def test_damerau_osa_match_ref_max_huge(self): max_distance = sys.maxsize comparer = DamerauOsa() for s1 in self.test_strings: for s2 in self.test_strings: self.assertEqual(get_damerau_osa(s1, s2, max_distance), comparer.distance(s1, s2, max_distance))
def test_damerau_osa_very_long_string_2(self): max_distance = 5 short_string = "string" very_long_string = "very_long_string" comparer = DamerauOsa() distance = comparer.distance(short_string, very_long_string, max_distance) self.assertEqual(-1, distance)
def test_damerau_osa_match_ref_max_3(self): max_distance = 3 comparer = DamerauOsa() for s1 in self.test_strings: for s2 in self.test_strings: print(s1, s2) self.assertEqual(get_damerau_osa(s1, s2, max_distance), comparer.distance(s1, s2, max_distance))
def test_damerau_osa_very_long_string_2(self): print(' - %s' % inspect.stack()[0][3]) max_distance = 5 short_string = "string" very_long_string = "very_long_string" comparer = DamerauOsa() distance = comparer.distance(short_string, very_long_string, max_distance) self.assertEqual(-1, distance)
def get_comparer(request): comparer_dict = { "damerau_osa": { "actual": DamerauOsa(), "expected": expected_damerau_osa }, "levenshtein": { "actual": Levenshtein(), "expected": expected_levenshtein }, "damerau_osa_fast": { "actual": DamerauOsaFast(), "expected": expected_damerau_osa, }, "levenshtein_fast": { "actual": LevenshteinFast(), "expected": expected_levenshtein, }, } yield comparer_dict[request.param]["actual"], comparer_dict[ request.param]["expected"]
def test_damerau_osa_null_distance(self): max_distance = 10 short_string = "string" long_string = "long_string" comparer = DamerauOsa() distance = comparer.distance(short_string, None, max_distance) self.assertEqual(len(short_string), distance) distance = comparer.distance(long_string, None, max_distance) self.assertEqual(-1, distance) distance = comparer.distance(None, short_string, max_distance) self.assertEqual(len(short_string), distance) distance = comparer.distance(None, long_string, max_distance) self.assertEqual(-1, distance) distance = comparer.distance(None, None, max_distance) self.assertEqual(0, distance)
def test_damerau_osa_negative_max_distance(self): max_distance_1 = 0 short_string = "string" long_string = "long_string" comparer = DamerauOsa() distance = comparer.distance(short_string, None, max_distance_1) self.assertEqual(-1, distance) distance = comparer.distance(long_string, None, max_distance_1) self.assertEqual(-1, distance) distance = comparer.distance(None, short_string, max_distance_1) self.assertEqual(-1, distance) distance = comparer.distance(None, long_string, max_distance_1) self.assertEqual(-1, distance) distance = comparer.distance(None, None, max_distance_1) self.assertEqual(0, distance) distance = comparer.distance(short_string, short_string, max_distance_1) self.assertEqual(0, distance) max_distance_2 = -1 distance = comparer.distance(short_string, None, max_distance_2) self.assertEqual(-1, distance) distance = comparer.distance(long_string, None, max_distance_2) self.assertEqual(-1, distance) distance = comparer.distance(None, short_string, max_distance_2) self.assertEqual(-1, distance) distance = comparer.distance(None, long_string, max_distance_2) self.assertEqual(-1, distance) distance = comparer.distance(None, None, max_distance_2) self.assertEqual(0, distance) distance = comparer.distance(short_string, short_string, max_distance_2) self.assertEqual(0, distance)