1 // Copyright 2012 Google, Inc. All rights reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
14 func TestLCS(t *testing.T) {
15 for i, test := range []struct {
17 indexA, indexB, length int
19 {[]byte{1, 2, 3}, []byte{1, 2, 3}, 0, 0, 3},
20 {[]byte{0, 1, 2, 3}, []byte{1, 2, 3, 4}, 1, 0, 3},
21 {[]byte{0, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3}, []byte{1, 2, 3, 4}, 4, 0, 4},
22 {[]byte{1, 2, 2, 3, 4}, []byte{1, 2, 3, 4}, 2, 1, 3},
23 {[]byte{0, 1, 2, 3, 4}, []byte{1, 1, 2, 2, 3, 4}, 2, 3, 3},
25 ia, ib, l := longestCommonSubstring(test.a, test.b)
26 if ia != test.indexA || ib != test.indexB || l != test.length {
27 t.Errorf("%d: want (%d %d %d) got (%d %d %d)", i, test.indexA, test.indexB, test.length, ia, ib, l)
32 func TestDiff(t *testing.T) {
33 for i, test := range []struct {
38 []byte{0, 1, 2, 3, 4},
39 []byte{1, 1, 2, 2, 3, 4},
41 Difference{true, []byte{0}, []byte{}},
42 Difference{false, []byte{1}, []byte{1}},
43 Difference{true, []byte{}, []byte{1, 2}},
44 Difference{false, []byte{2, 3, 4}, []byte{2, 3, 4}},
48 diffs := Diff(test.a, test.b)
49 if !reflect.DeepEqual(diffs, test.d) {
50 t.Errorf("%d want %v got %v", i, test.d, diffs)