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))
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))
def f5(): fHammingDistance()("pattern", None)
def f4(): fHammingDistance()(None, None)
def f3(): fHammingDistance()(None, "Pattern 2")
def f2(): fHammingDistance()("Pattern", "Pattern 2")
def f1(): fHammingDistance()("Pattern 1", "Pattern")
def f5(): fHammingDistance()("pattern", None) self.assertRaises(AssertionError, f1)
def f4(): fHammingDistance()(None, None) def f5(): fHammingDistance()("pattern", None)
def f3(): fHammingDistance()(None, "Pattern 2") def f4(): fHammingDistance()(None, None)
def f2(): fHammingDistance()("Pattern", "Pattern 2") def f3(): fHammingDistance()(None, "Pattern 2")
def f1(): fHammingDistance()("Pattern 1", "Pattern") def f2(): fHammingDistance()("Pattern", "Pattern 2")