ODPM 266: Go-libmemif + 2 examples.
[govpp.git] / vendor / github.com / google / gopacket / bytediff / bytediff_test.go
1 // Copyright 2012 Google, Inc. All rights reserved.
2 //
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
5 // tree.
6
7 package bytediff
8
9 import (
10         "reflect"
11         "testing"
12 )
13
14 func TestLCS(t *testing.T) {
15         for i, test := range []struct {
16                 a, b                   []byte
17                 indexA, indexB, length int
18         }{
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},
24         } {
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)
28                 }
29         }
30 }
31
32 func TestDiff(t *testing.T) {
33         for i, test := range []struct {
34                 a, b []byte
35                 d    Differences
36         }{
37                 {
38                         []byte{0, 1, 2, 3, 4},
39                         []byte{1, 1, 2, 2, 3, 4},
40                         Differences{
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}},
45                         },
46                 },
47         } {
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)
51                 }
52         }
53 }