@@ -10,70 +10,54 @@ import (
1010
1111type testcase struct {
1212 name string
13- data * Ints
13+ a , b [] int
1414 res []Change
1515}
1616
1717var tests = []testcase {
1818 {"shift" ,
19- & Ints {
20- {1 , 2 , 3 },
21- {0 , 1 , 2 , 3 },
22- },
19+ []int {1 , 2 , 3 },
20+ []int {0 , 1 , 2 , 3 },
2321 []Change {{0 , 0 , 0 , 1 }},
2422 },
2523 {"push" ,
26- & Ints {
27- {1 , 2 , 3 },
28- {1 , 2 , 3 , 4 },
29- },
24+ []int {1 , 2 , 3 },
25+ []int {1 , 2 , 3 , 4 },
3026 []Change {{3 , 3 , 0 , 1 }},
3127 },
3228 {"unshift" ,
33- & Ints {
34- {0 , 1 , 2 , 3 },
35- {1 , 2 , 3 },
36- },
29+ []int {0 , 1 , 2 , 3 },
30+ []int {1 , 2 , 3 },
3731 []Change {{0 , 0 , 1 , 0 }},
3832 },
3933 {"pop" ,
40- & Ints {
41- {1 , 2 , 3 , 4 },
42- {1 , 2 , 3 },
43- },
34+ []int {1 , 2 , 3 , 4 },
35+ []int {1 , 2 , 3 },
4436 []Change {{3 , 3 , 1 , 0 }},
4537 },
4638 {"all changed" ,
47- & Ints {
48- {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 },
49- {10 , 11 , 12 , 13 , 14 },
50- },
39+ []int {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 },
40+ []int {10 , 11 , 12 , 13 , 14 },
5141 []Change {
5242 {0 , 0 , 10 , 5 },
5343 },
5444 },
5545 {"all same" ,
56- & Ints {
57- {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 },
58- {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 },
59- },
46+ []int {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 },
47+ []int {0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 },
6048 []Change {},
6149 },
6250 {"wrap" ,
63- & Ints {
64- {1 },
65- {0 , 1 , 2 , 3 },
66- },
51+ []int {1 },
52+ []int {0 , 1 , 2 , 3 },
6753 []Change {
6854 {0 , 0 , 0 , 1 },
6955 {1 , 2 , 0 , 2 },
7056 },
7157 },
7258 {"snake" ,
73- & Ints {
74- {0 , 1 , 2 , 3 , 4 , 5 },
75- {1 , 2 , 3 , 4 , 5 , 6 },
76- },
59+ []int {0 , 1 , 2 , 3 , 4 , 5 },
60+ []int {1 , 2 , 3 , 4 , 5 , 6 },
7761 []Change {
7862 {0 , 0 , 1 , 0 },
7963 {6 , 5 , 0 , 1 },
@@ -83,10 +67,8 @@ var tests = []testcase{
8367 // first two traces differ from fig.1
8468 // it still is a lcs and ses path
8569 {"paper fig. 1" ,
86- & Ints {
87- {1 , 2 , 3 , 1 , 2 , 2 , 1 },
88- {3 , 2 , 1 , 2 , 1 , 3 },
89- },
70+ []int {1 , 2 , 3 , 1 , 2 , 2 , 1 },
71+ []int {3 , 2 , 1 , 2 , 1 , 3 },
9072 []Change {
9173 {0 , 0 , 1 , 1 },
9274 {2 , 2 , 1 , 0 },
@@ -98,7 +80,7 @@ var tests = []testcase{
9880
9981func TestDiffAB (t * testing.T ) {
10082 for _ , test := range tests {
101- res := test .data . Diff ( )
83+ res := Ints ( test .a , test . b )
10284 if len (res ) != len (test .res ) {
10385 t .Error (test .name , "expected length" , len (test .res ), "for" , res )
10486 continue
@@ -120,7 +102,7 @@ func TestDiffBA(t *testing.T) {
120102 {7 , 5 , 0 , 1 },
121103 }
122104 for _ , test := range tests {
123- res := Diff ( & Ints { test .data [ 1 ] , test .data [ 0 ]} )
105+ res := Ints ( test .b , test .a )
124106 if len (res ) != len (test .res ) {
125107 t .Error (test .name , "expected length" , len (test .res ), "for" , res )
126108 continue
@@ -137,14 +119,17 @@ func TestDiffBA(t *testing.T) {
137119
138120func BenchmarkDiff (b * testing.B ) {
139121 t := tests [len (tests )- 1 ]
122+ d := & ints {t .a , t .b }
123+ n , m := len (d .a ), len (d .b )
140124 for i := 0 ; i < b .N ; i ++ {
141- t . data . Diff ()
125+ Diff (n , m , d )
142126 }
143127}
144128
145129func BenchmarkDiffRunes (b * testing.B ) {
146- data := & Runes {[]rune ("1231221" ), []rune ("321213" )}
130+ d := & runes {[]rune ("1231221" ), []rune ("321213" )}
131+ n , m := len (d .a ), len (d .b )
147132 for i := 0 ; i < b .N ; i ++ {
148- Diff (data )
133+ Diff (n , m , d )
149134 }
150135}
0 commit comments