|
| 1 | +from __future__ import absolute_import |
| 2 | +from __future__ import division |
| 3 | +from __future__ import print_function |
| 4 | +from __future__ import unicode_literals |
| 5 | + |
| 6 | + |
| 7 | +from fuzzy_matcher import process |
| 8 | + |
| 9 | + |
| 10 | +def test_partial_distance(): |
| 11 | + query = "orange" |
| 12 | + candidates = ['orangoutan', 'orange tango', 'olive martini', 'orangemartinin', 'martininorange'] |
| 13 | + partial_distances = [process.partial_distance(query, val) for val in candidates] |
| 14 | + assert partial_distances == [1, 0, 5, 0, 0] |
| 15 | + |
| 16 | + |
| 17 | +def test_ratio(): |
| 18 | + |
| 19 | + query = "orange" |
| 20 | + val = ['blue', 'orange', 'brown', 'ornage', 'range', 'angel', 'gang', 'ang'] |
| 21 | + fuzzy = process.extract(query, val, limit=3, scorer='ratio') |
| 22 | + assert fuzzy == [('orange', 100), ('range', 83), ('ornage', 66)] |
| 23 | + |
| 24 | + |
| 25 | +def test_partial_ratio(): |
| 26 | + query = "orange" |
| 27 | + val = ['blue tango', 'orange tango', 'brown tango'] |
| 28 | + fuzzy = process.extract(query, val, limit=3, scorer='partial_ratio') |
| 29 | + assert fuzzy == [('orange tango', 100), ('blue tango', 50), ('brown tango', 50)] |
| 30 | + |
0 commit comments