|
| 1 | +import pytest |
| 2 | +from decimal import Decimal |
| 3 | +from sota_extractor2.models.linking.bm25_naive import convert_metric |
| 4 | + |
| 5 | +raw_values = ["0.21", "0.21%", "21", "21%"] |
| 6 | +ranges = ["0-1", "1-100", "abs", ""] |
| 7 | + |
| 8 | +values = { |
| 9 | + # 0.21 0.21% 21 21% |
| 10 | + "0-1": [ "0.21", "0.0021", "0.21", "0.21"], |
| 11 | + "1-100": [ "21", "0.21", "21", "21"], |
| 12 | + "abs": [ "0.21", "0.0021", "21", "0.21"], |
| 13 | + "": [ "0.21", "0.21", "21", "21"] |
| 14 | +} |
| 15 | + |
| 16 | +comp_values = { |
| 17 | + # 0.21 0.21% 21 21% |
| 18 | + "0-1": [ "0.79", "0.9979", "0.79", "0.79"], |
| 19 | + "1-100": [ "79", "99.79", "79", "79"], |
| 20 | + "": [ "0.79", "99.79", "79", "79"] |
| 21 | +} |
| 22 | + |
| 23 | +cases = [(raw_value, rng, complementary, Decimal(answer)) |
| 24 | + for complementary, vals in zip([False, True], [values, comp_values]) |
| 25 | + for rng in vals |
| 26 | + for raw_value, answer in zip(raw_values, vals[rng]) |
| 27 | +] |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.parametrize("raw_value,rng,complementary,expected", cases) |
| 31 | +def test_ranges(raw_value, rng, complementary, expected): |
| 32 | + value = convert_metric(raw_value, rng, complementary) |
| 33 | + assert value == expected, (f"{'complement of ' if complementary else ''}" |
| 34 | + f"raw value {raw_value}, assuming {rng if rng else 'empty'} range " |
| 35 | + f"should be extracted as {expected}, not {value}") |
0 commit comments