示例#1
0
    def test_hamming(self):
        def f1(): fHammingDistance()("Pattern 1", "Pattern")
        def f2(): fHammingDistance()("Pattern", "Pattern 2")
        def f3(): fHammingDistance()(None, "Pattern 2")
        def f4(): fHammingDistance()(None, None)
        def f5(): fHammingDistance()("pattern", None)

        self.assertRaises(AssertionError, f1)
        self.assertRaises(AssertionError, f2)
        self.assertRaises(AssertionError, f3)
        self.assertRaises(AssertionError, f4)
        self.assertRaises(AssertionError, f5)
        
        self.assertEqual(fHammingDistance()("Pattern 1", "Pattern 2"), 1)
        self.assertEqual(fHammingDistance()("Pattern", "Pattern"), 0)
        self.assertEqual(fHammingDistance()("", ""), 0)

        em =  [ [  1, 0, 0, 0, 0, 0, 0 ],
                [  0, 1, 0, 0, 0, 0, 0 ],
                [  0, 0, 2, 0, 0, 0, 0 ],
                [  0, 0, 0, 3, 0, 0, 0 ],
                [  0, 0, 0, 0, 4, 0, 0 ],
                [  0, 0, 0, 0, 0, 4, 0 ],
                [  0, 0, 0, 0, 0, 0, 4 ] ]

        m = fHammingDistance().fill_matrix("abcdefg", "cbdrtfg", DistanceMatrix())
        for row in range(len(em)):
            for col in range(len(em[row])):
                self.assertEqual(em[row][col], m.get(row, col))
示例#2
0
    def test_hamming(self):
        def f1():
            fHammingDistance()("Pattern 1", "Pattern")

        def f2():
            fHammingDistance()("Pattern", "Pattern 2")

        def f3():
            fHammingDistance()(None, "Pattern 2")

        def f4():
            fHammingDistance()(None, None)

        def f5():
            fHammingDistance()("pattern", None)

        self.assertRaises(AssertionError, f1)
        self.assertRaises(AssertionError, f2)
        self.assertRaises(AssertionError, f3)
        self.assertRaises(AssertionError, f4)
        self.assertRaises(AssertionError, f5)

        self.assertEqual(fHammingDistance()("Pattern 1", "Pattern 2"), 1)
        self.assertEqual(fHammingDistance()("Pattern", "Pattern"), 0)
        self.assertEqual(fHammingDistance()("", ""), 0)

        em = [[1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0],
              [0, 0, 2, 0, 0, 0, 0], [0, 0, 0, 3, 0, 0, 0],
              [0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 0, 4, 0],
              [0, 0, 0, 0, 0, 0, 4]]

        m = fHammingDistance().fill_matrix("abcdefg", "cbdrtfg",
                                           DistanceMatrix())
        for row in range(len(em)):
            for col in range(len(em[row])):
                self.assertEqual(em[row][col], m.get(row, col))
示例#3
0
 def f5():
     fHammingDistance()("pattern", None)
示例#4
0
 def f4():
     fHammingDistance()(None, None)
示例#5
0
 def f3():
     fHammingDistance()(None, "Pattern 2")
示例#6
0
 def f2():
     fHammingDistance()("Pattern", "Pattern 2")
示例#7
0
 def f1():
     fHammingDistance()("Pattern 1", "Pattern")
示例#8
0
        def f5(): fHammingDistance()("pattern", None)

        self.assertRaises(AssertionError, f1)
示例#9
0
 def f4(): fHammingDistance()(None, None)
 def f5(): fHammingDistance()("pattern", None)
示例#10
0
 def f3(): fHammingDistance()(None, "Pattern 2")
 def f4(): fHammingDistance()(None, None)
示例#11
0
 def f2(): fHammingDistance()("Pattern", "Pattern 2")
 def f3(): fHammingDistance()(None, "Pattern 2")
示例#12
0
 def f1(): fHammingDistance()("Pattern 1", "Pattern")
 def f2(): fHammingDistance()("Pattern", "Pattern 2")