1
- import dotenv
2
-
3
- dotenv .load_dotenv ()
4
-
5
1
from langevals_langevals .exact_match import (
6
2
ExactMatchEvaluator ,
7
3
ExactMatchEntry ,
8
4
ExactMatchSettings ,
9
5
)
10
6
11
7
12
- def test_langeval_exact_match_evaluator_exact ():
8
+ def test_langeval_exact_match_evaluator ():
13
9
entry = ExactMatchEntry (
14
10
input = "What is the capital of France?" ,
15
11
output = "What is the capital of France?" ,
@@ -19,17 +15,112 @@ def test_langeval_exact_match_evaluator_exact():
19
15
evaluator = ExactMatchEvaluator (settings = settings )
20
16
result = evaluator .evaluate (entry )
21
17
22
- assert result == True
18
+ assert result . passed == True
23
19
24
20
25
- def test_langeval_exact_match_evaluator_different ():
21
+ def test_langeval_exact_match_evaluator_defaults ():
26
22
entry = ExactMatchEntry (
27
23
input = "What is the capital of France?" ,
28
- output = "The capital of France is London. " ,
24
+ output = "What is the capital of the Netherlands? " ,
29
25
)
30
26
settings = ExactMatchSettings ()
31
27
32
28
evaluator = ExactMatchEvaluator (settings = settings )
33
29
result = evaluator .evaluate (entry )
34
30
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