Ejemplo n.º 1
0
    def test_compute_edit_distance(self):
        s1v1 = "ip address 129.170.9.157 255.255.255.255"
        s1v2 = "ip address 129.170.9.195 255.255.255.255"

        # process these as a sequence of unicode bytes
        edit_distance = EditDistance()
        X = s1v1.encode()
        Y = s1v2.encode()
        m = len(X)
        n = len(Y)
        self.assertEqual(m, 40)
        self.assertEqual(n, 40)
        edit_distance.compute_edit_distance(X, Y)
        self.assertEqual(edit_distance.c[m, n], 2)

        # process these as a sequence of chars
        edit_distance = EditDistance()
        X = s1v1
        Y = s1v2
        m = len(X)
        n = len(Y)
        self.assertEqual(m, 40)
        self.assertEqual(n, 40)
        edit_distance.compute_edit_distance(X, Y)
        self.assertEqual(edit_distance.c[m, n], 2)

        # process these as a sequence of words
        edit_distance = EditDistance()
        X = s1v1.split()
        Y = s1v2.split()
        m = len(X)
        n = len(Y)
        self.assertEqual(m, 4)
        self.assertEqual(n, 4)
        edit_distance.compute_edit_distance(X, Y)
        self.assertEqual(edit_distance.c[m, n], 1)
Ejemplo n.º 2
0
    def test_edit_distance(self):
        s1v1 = "ip address 129.170.9.157 255.255.255.255"
        s1v2 = "ip address 129.170.9.195 255.255.255.255"

        edit_distance = EditDistance()

        # test byte
        dist = edit_distance.edit_distance(s1v1, s1v2, "builtin:byte")
        self.assertEqual(dist, 2)

        dist = edit_distance.edit_distance(s1v1, s1v2, "builtin:character")
        self.assertEqual(dist, 2)

        dist = edit_distance.edit_distance(s1v1, s1v2, "builtin:word")
        self.assertEqual(dist, 1)

        dist = edit_distance.edit_distance(None, s1v2, "builtin:word")
        self.assertEqual(dist, 4)

        dist = edit_distance.edit_distance(s1v1, None, "builtin:byte")
        self.assertEqual(dist, 40)