Skip to content

Commit b9abe29

Browse files
committed
added tests for exact match
1 parent e3ecbc6 commit b9abe29

File tree

1 file changed

+100
-9
lines changed

1 file changed

+100
-9
lines changed
Lines changed: 100 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import dotenv
2-
3-
dotenv.load_dotenv()
4-
51
from langevals_langevals.exact_match import (
62
ExactMatchEvaluator,
73
ExactMatchEntry,
84
ExactMatchSettings,
95
)
106

117

12-
def test_langeval_exact_match_evaluator_exact():
8+
def test_langeval_exact_match_evaluator():
139
entry = ExactMatchEntry(
1410
input="What is the capital of France?",
1511
output="What is the capital of France?",
@@ -19,17 +15,112 @@ def test_langeval_exact_match_evaluator_exact():
1915
evaluator = ExactMatchEvaluator(settings=settings)
2016
result = evaluator.evaluate(entry)
2117

22-
assert result == True
18+
assert result.passed == True
2319

2420

25-
def test_langeval_exact_match_evaluator_different():
21+
def test_langeval_exact_match_evaluator_defaults():
2622
entry = ExactMatchEntry(
2723
input="What is the capital of France?",
28-
output="The capital of France is London.",
24+
output="What is the capital of the Netherlands?",
2925
)
3026
settings = ExactMatchSettings()
3127

3228
evaluator = ExactMatchEvaluator(settings=settings)
3329
result = evaluator.evaluate(entry)
3430

35-
assert result == False
31+
assert result.passed == False
32+
33+
34+
def test_langeval_exact_match_case_sensitive_true():
35+
entry = ExactMatchEntry(
36+
input="Hello World",
37+
output="hello world",
38+
)
39+
settings = ExactMatchSettings(case_sensitive=True)
40+
41+
evaluator = ExactMatchEvaluator(settings=settings)
42+
result = evaluator.evaluate(entry)
43+
44+
assert result.passed == False
45+
46+
47+
def test_langeval_exact_match_case_sensitive_false():
48+
entry = ExactMatchEntry(
49+
input="Hello World",
50+
output="hello world",
51+
)
52+
settings = ExactMatchSettings(case_sensitive=False)
53+
54+
evaluator = ExactMatchEvaluator(settings=settings)
55+
result = evaluator.evaluate(entry)
56+
57+
assert result.passed == True
58+
59+
60+
def test_langeval_exact_match_trim_whitespace_true():
61+
entry = ExactMatchEntry(
62+
input=" Hello World ",
63+
output="Hello World",
64+
)
65+
settings = ExactMatchSettings(trim_whitespace=True)
66+
67+
evaluator = ExactMatchEvaluator(settings=settings)
68+
result = evaluator.evaluate(entry)
69+
70+
assert result.passed == True
71+
72+
73+
def test_langeval_exact_match_trim_whitespace_false():
74+
entry = ExactMatchEntry(
75+
input=" Hello World ",
76+
output="Hello World",
77+
)
78+
settings = ExactMatchSettings(trim_whitespace=False)
79+
80+
evaluator = ExactMatchEvaluator(settings=settings)
81+
result = evaluator.evaluate(entry)
82+
83+
assert result.passed == False
84+
85+
86+
def test_langeval_exact_match_remove_punctuation_true():
87+
entry = ExactMatchEntry(
88+
input="Hello, World!",
89+
output="Hello World",
90+
)
91+
settings = ExactMatchSettings(remove_punctuation=True)
92+
93+
evaluator = ExactMatchEvaluator(settings=settings)
94+
result = evaluator.evaluate(entry)
95+
96+
assert result.passed == True
97+
98+
99+
def test_langeval_exact_match_remove_punctuation_false():
100+
entry = ExactMatchEntry(
101+
input="Hello, World!",
102+
output="Hello World",
103+
)
104+
settings = ExactMatchSettings(remove_punctuation=False)
105+
106+
evaluator = ExactMatchEvaluator(settings=settings)
107+
result = evaluator.evaluate(entry)
108+
109+
assert result.passed == False
110+
111+
112+
def test_langeval_exact_match_combined_settings():
113+
entry = ExactMatchEntry(
114+
input=" Hello, World! ",
115+
output="hello world",
116+
)
117+
settings = ExactMatchSettings(
118+
case_sensitive=False,
119+
trim_whitespace=True,
120+
remove_punctuation=True
121+
)
122+
123+
evaluator = ExactMatchEvaluator(settings=settings)
124+
result = evaluator.evaluate(entry)
125+
126+
assert result.passed == True

0 commit comments

Comments
 (0)