| from benchmark.scoring import score_exact_match, score_token_f1, score_numeric, score_list |
|
|
| def test_exact_match(): |
| assert score_exact_match("Project Aster Access Code is CODE-12", "CODE-12") == 1.0 |
| assert score_exact_match("code-12", "CODE-12") == 1.0 |
| assert score_exact_match("CODE-99", "CODE-12") == 0.0 |
|
|
| def test_token_f1(): |
| p, r, f1 = score_token_f1("the red car", "red car") |
| assert p == 2/3 |
| assert r == 1.0 |
| assert f1 == (2 * (2/3) * 1) / ((2/3) + 1) |
|
|
| def test_numeric_tolerance(): |
| |
| assert score_numeric("105.2", 105.2, mode="exact") == 1.0 |
| assert score_numeric("105", 105.2, mode="exact") == 0.0 |
| |
| |
| assert score_numeric("105.0", 105.2, mode="absolute_tolerance", tolerance=0.3) == 1.0 |
| assert score_numeric("104.5", 105.2, mode="absolute_tolerance", tolerance=0.3) == 0.0 |
| |
| |
| assert score_numeric("100", 102, mode="relative_tolerance", tolerance=0.03) == 1.0 |
|
|
| def test_list_matching(): |
| |
| p, r, f1 = score_list("apple, banana, cherry", ["apple", "cherry"]) |
| assert p == 2/3 |
| assert r == 1.0 |
|
|