Ejemplo n.º 1
0
    def test_levenshtein_match_ref_max_1(self):
        max_distance = 1

        comparer = Levenshtein()
        for s1 in self.test_strings:
            for s2 in self.test_strings:
                self.assertEqual(get_levenshtein(s1, s2, max_distance),
                                 comparer.distance(s1, s2, max_distance))
Ejemplo n.º 2
0
    def test_levenshtein_very_long_string_2(self):
        max_distance = 5
        short_string = "string"
        very_long_string = "very_long_string"

        comparer = Levenshtein()
        distance = comparer.distance(short_string, very_long_string,
                                     max_distance)
        self.assertEqual(-1, distance)
Ejemplo n.º 3
0
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"]
Ejemplo n.º 4
0
    def test_levenshtein_null_distance(self):
        max_distance = 10
        short_string = "string"
        long_string = "long_string"

        comparer = Levenshtein()
        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)
Ejemplo n.º 5
0
    def test_levenshtein_negative_max_distance(self):
        max_distance_1 = 0
        short_string = "string"
        long_string = "long_string"

        comparer = Levenshtein()
        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)