# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========

from mirage.utils.score import format_score, score_from_distance


def test_score_from_distance_zero_is_full_similarity():
    assert score_from_distance(0.0) == "1.00"


def test_score_from_distance_clamps_negative_similarity():
    assert score_from_distance(2.5) == "0.00"


def test_score_from_distance_fraction():
    assert score_from_distance(0.25) == "0.75"


def test_score_from_distance_non_numeric():
    assert score_from_distance(None) == "0.00"
    assert score_from_distance("0.1") == "0.00"
    assert score_from_distance(True) == "0.00"


def test_format_score_numeric():
    assert format_score(0.913) == "0.91"
    assert format_score(1) == "1.00"


def test_format_score_non_numeric():
    assert format_score(None) is None
    assert format_score("0.5") is None
    assert format_score(False) is None
