def test_sequence_matcher(self): """Test the sequence matcher.""" a = ['a', 'b'] b = ['a', 'b', 'd', 'c'] sm = SequenceMatcher(a=a, b=b) opcodes = [['equal', 0, 1, 0, 1], ['equal', 1, 2, 1, 2], ['insert', 1, 1, 2, 3], ['insert', 1, 1, 3, 4]] self.assertTrue(sm.distance() == 2) self.assertTrue(sm.ratio() == 2 / 3) self.assertTrue(sm.quick_ratio() == 2 / 3) self.assertTrue(sm.real_quick_ratio() == 2 / 3) self.assertTrue(sm.distance() == 2) # This doesn't return anything, saves the value in the sm cache. self.assertTrue(not sm._compute_distance_fast()) self.assertTrue(sm.get_opcodes() == opcodes) self.assertTrue(list(sm.get_matching_blocks()) == [[0, 0, 1], [1, 1, 1]])
def test_sequence_matcher(self): """Test the sequence matcher.""" a = ['a', 'b'] b = ['a', 'b', 'd', 'c'] sm = SequenceMatcher(a=a, b=b) opcodes = [['equal', 0, 1, 0, 1], ['equal', 1, 2, 1, 2], ['insert', 1, 1, 2, 3], ['insert', 1, 1, 3, 4]] self.assertTrue(sm.distance() == 2) self.assertTrue(sm.ratio() == 2 / 3) self.assertTrue(sm.quick_ratio() == 2 / 3) self.assertTrue(sm.real_quick_ratio() == 2 / 3) self.assertTrue(sm.distance() == 2) # This doesn't return anything, saves the value in the sm cache. self.assertTrue(not sm._compute_distance_fast()) self.assertTrue(sm.get_opcodes() == opcodes) self.assertTrue( list(sm.get_matching_blocks()) == [[0, 0, 1], [1, 1, 1]])
def test_sequence_matcher(self): """Test the sequence matcher.""" a = ["a", "b"] b = ["a", "b", "d", "c"] sm = SequenceMatcher(a=a, b=b) opcodes = [ ["equal", 0, 1, 0, 1], ["equal", 1, 2, 1, 2], ["insert", 2, 2, 2, 3], ["insert", 2, 2, 3, 4], ] self.assertEqual(sm.distance(), 2) self.assertEqual(sm.ratio(), 2 / 3) self.assertEqual(sm.quick_ratio(), 2 / 3) self.assertEqual(sm.real_quick_ratio(), 2 / 3) self.assertEqual(sm.distance(), 2) # This doesn't return anything, saves the value in the sm cache. self.assertTrue(not sm._compute_distance_fast()) self.assertEqual(sm.get_opcodes(), opcodes) self.assertEqual(list(sm.get_matching_blocks()), [[0, 0, 1], [1, 1, 1]])