def check_diff_sequence_and_patch(a, b): d = diff_sequence_difflib(a, b) assert is_valid_diff(d) assert patch(a, d) == b d = diff_sequence_difflib(b, a) assert is_valid_diff(d) assert patch(b, d) == a
def check_diff_sequence_and_patch(a, b): d = diff_sequence(a, b) assert is_valid_diff(d) assert patch(a, d) == b d = diff_sequence(b, a) assert is_valid_diff(d) assert patch(b, d) == a
def check_diff_and_patch(a, b): "Check that patch(a, diff(a,b)) reproduces b." d = shallow_diff(a, b) assert is_valid_diff(d) assert patch(a, d) == b d = deep_diff(a, b) assert is_valid_diff(d) assert patch(a, d) == b
def test_diff_sequence_bruteforce(): examples = [ ([], []), ([1], [1]), ([1,2], [1,2]), ([2,1], [1,2]), ([1,2,3], [1,2]), ([2,1,3], [1,2]), ([1,2], [1,2,3]), ([2,1], [1,2,3]), ([1,2], [1,2,1,2]), ([1,2,1,2], [1,2]), ([1,2,3,4,1,2], [3,4,2,3]), (list("abcab"), list("ayb")), (list("xaxcxabc"), list("abcy")), ] for a, b in examples: G = bruteforce_compare_grid(a, b) assert all(bool(G[i,j]) == (a[i] == b[j]) for i in range(len(a)) for j in range(len(b))) R = bruteforce_llcs_grid(G) for i in range(len(a)): for j in range(len(b)): assert R[i+1,j+1] >= R[i,j] assert R[i+1,j] >= R[i,j] assert R[i,j+1] >= R[i,j] assert R[i+1,j+1] - R[i,j] <= 1 assert R[i+1,j] - R[i,j] <= 1 assert R[i,j+1] - R[i,j] <= 1 llcs = R[len(a), len(b)] A_indices, B_indices = bruteforce_lcs_indices(a, b, G, R) assert len(A_indices) == len(B_indices) assert len(A_indices) == llcs assert all(a[A_indices[r]] == b[B_indices[r]] for r in range(llcs)) d = diff_from_lcs(a, b, A_indices, B_indices) assert is_valid_diff(d) assert patch(a, d) == b # Test combined function (repeats the above pieces) assert patch(a, diff_sequence_bruteforce(a, b)) == b