@@ -49,6 +49,75 @@ def record_dawg(self):
49
49
50
50
51
51
52
+ @pytest .mark .parametrize (("word" , "prediction" ), SUITE )
53
+ def test_dawg_prediction (self , word , prediction ):
54
+ d = dawg_python .DAWG ().load (data_path ("small" , "prediction.dawg" ))
55
+ assert d .similar_keys (word , self .REPLACES ) == prediction
56
+
57
+ @pytest .mark .parametrize (("word" , "prediction" ), SUITE )
58
+ def test_record_dawg_prediction (self , word , prediction ):
59
+ d = self .record_dawg ()
60
+ assert d .similar_keys (word , self .REPLACES ) == prediction
61
+
62
+ @pytest .mark .parametrize (("word" , "prediction" ), SUITE_ITEMS )
63
+ def test_record_dawg_items (self , word , prediction ):
64
+ d = self .record_dawg ()
65
+ assert d .similar_items (word , self .REPLACES ) == prediction
66
+
67
+ @pytest .mark .parametrize (("word" , "prediction" ), SUITE_VALUES )
68
+ def test_record_dawg_items_values (self , word , prediction ):
69
+ d = self .record_dawg ()
70
+ assert d .similar_item_values (word , self .REPLACES ) == prediction
71
+
72
+ class TestMultiValuedPrediction (object ):
73
+
74
+ REPLACES = dawg_python .DAWG .compile_replaces ({'е' : ['ё' , 'ѣ' ], 'и' : 'і' })
75
+
76
+ DATA = "хлѣб ёлка ель лѣс лѣсное всё всѣ бѣлёная изобрѣтён лев лёв лѣв вѣнскій" .split (" " )
77
+ SUITE = [
78
+ ('осел' , []),
79
+ ('ель' , ['ель' ]),
80
+ ('ёль' , []),
81
+ ('хлеб' , ['хлѣб' ]),
82
+ ('елка' , ['ёлка' ]),
83
+ ('лесное' , ['лѣсное' ]),
84
+ ('лесноё' , []),
85
+ ('лёсное' , []),
86
+ ('изобретен' , ['изобрѣтён' ]),
87
+ ('беленая' , ['бѣлёная' ]),
88
+ ('белёная' , ['бѣлёная' ]),
89
+ ('бѣленая' , ['бѣлёная' ]),
90
+ ('бѣлёная' , ['бѣлёная' ]),
91
+ ('белѣная' , []),
92
+ ('бѣлѣная' , []),
93
+ ('все' , ['всё' , 'всѣ' ]),
94
+ ('лев' , ['лев' , 'лёв' , 'лѣв' ]),
95
+ ('венский' , ['вѣнскій' ]),
96
+ ]
97
+
98
+ SUITE_ITEMS = [
99
+ (
100
+ it [0 ], # key
101
+ [
102
+ (w , [(len (w ),)]) # item, value pair
103
+ for w in it [1 ]
104
+ ]
105
+ )
106
+ for it in SUITE
107
+ ]
108
+
109
+ SUITE_VALUES = [
110
+ (
111
+ it [0 ], # key
112
+ [[(len (w ),)] for w in it [1 ]]
113
+ )
114
+ for it in SUITE
115
+ ]
116
+
117
+ def record_dawg (self ):
118
+ path = data_path ("small" , "prediction-record.dawg" )
119
+ return dawg_python .RecordDAWG (str ("=H" )).load (path )
120
+
52
121
@pytest .mark .parametrize (("word" , "prediction" ), SUITE )
53
122
def test_dawg_prediction (self , word , prediction ):
54
123
d = dawg_python .DAWG ().load (data_path ("small" , "prediction.dawg" ))
0 commit comments