def test_compute_snakes_multilevel(): a = [("a0", "b0", "c0"), ("q", "y", "z"), ("a1", "b1", "c1"), ("a2", "b2", "c2"), ("a3", "b3", "c3")] b = [("a0", "b0", "c"), ("a", "b", "c"), ("a2", "b2", "c2"), ("x", "y", "z"), ("x", "y", "z"), ("a3", "b", "c")] def _cmp_n(n): def _cmp(x, y): return x[:n] == y[:n] return _cmp compares = [_cmp_n(1), _cmp_n(2), operator.__eq__] snakes = compute_snakes_multilevel(a, b, compares) assert snakes == [(0, 0, 1), (3, 2, 1), (4, 5, 1)] # Test case to show how first level provides a coarse # identification and snakes from second level are merged # with the first ones A = ["aa", "ab", "ba", "bb"] B = ["aa", "ax", "ba", "bx"] compares = [lambda a, b: a == b, lambda a, b: a[0] == b[0]] snakes = compute_snakes_multilevel(A, B, compares[:1]) assert snakes == [(0, 0, 1), (2, 2, 1)] snakes = compute_snakes_multilevel(A, B, compares) assert snakes == [(0, 0, 4)]
def test_compute_snakes_multilevel(): a = [ ("a0", "b0", "c0"), ("q", "y", "z"), ("a1", "b1", "c1"), ("a2", "b2", "c2"), ("a3", "b3", "c3"), ] b = [ ("a0", "b0", "c"), ("a", "b", "c"), ("a2", "b2", "c2"), ("x", "y", "z"), ("x", "y", "z"), ("a3", "b", "c"), ] def _cmp_n(n): def _cmp(x, y): return x[:n] == y[:n] return _cmp compares = [_cmp_n(1), _cmp_n(2), operator.__eq__] snakes = compute_snakes_multilevel(a, b, compares) assert snakes == [(0, 0, 1), (3, 2, 1), (4, 5, 1)] # Test case to show how first level provides a coarse # identification and snakes from second level are merged # with the first ones A = ["aa", "ab", "ba", "bb"] B = ["aa", "ax", "ba", "bx"] compares = [ lambda a, b: a == b, lambda a, b: a[0] == b[0], ] snakes = compute_snakes_multilevel(A, B, compares[:1]) assert snakes == [(0, 0, 1), (2, 2, 1)] snakes = compute_snakes_multilevel(A, B, compares) assert snakes == [(0, 0, 4)]