OLD | NEW |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package suffixarray | 5 package suffixarray |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "container/vector" | 9 "container/vector" |
10 "regexp" | 10 "regexp" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 if len(res) != len(exp) { | 134 if len(res) != len(exp) { |
135 t.Errorf("test %q, lookup %q (n = %d): expected %d results; got
%d", tc.name, s, n, len(exp), len(res)) | 135 t.Errorf("test %q, lookup %q (n = %d): expected %d results; got
%d", tc.name, s, n, len(exp), len(res)) |
136 } | 136 } |
137 | 137 |
138 // if n >= 0 the number of results is limited --- unless n >= all result
s, | 138 // if n >= 0 the number of results is limited --- unless n >= all result
s, |
139 // we may obtain different positions from the Index and from find (becau
se | 139 // we may obtain different positions from the Index and from find (becau
se |
140 // Index may not find the results in the same order as find) => in gener
al | 140 // Index may not find the results in the same order as find) => in gener
al |
141 // we cannot simply check that the res and exp lists are equal | 141 // we cannot simply check that the res and exp lists are equal |
142 | 142 |
143 // check that each result is in fact a correct match and there are no du
plicates | 143 // check that each result is in fact a correct match and there are no du
plicates |
144 » sort.SortInts(res) | 144 » sort.Ints(res) |
145 for i, r := range res { | 145 for i, r := range res { |
146 if r < 0 || len(tc.source) <= r { | 146 if r < 0 || len(tc.source) <= r { |
147 t.Errorf("test %q, lookup %q, result %d (n = %d): index
%d out of range [0, %d[", tc.name, s, i, n, r, len(tc.source)) | 147 t.Errorf("test %q, lookup %q, result %d (n = %d): index
%d out of range [0, %d[", tc.name, s, i, n, r, len(tc.source)) |
148 } else if !strings.HasPrefix(tc.source[r:], s) { | 148 } else if !strings.HasPrefix(tc.source[r:], s) { |
149 t.Errorf("test %q, lookup %q, result %d (n = %d): index
%d not a match", tc.name, s, i, n, r) | 149 t.Errorf("test %q, lookup %q, result %d (n = %d): index
%d not a match", tc.name, s, i, n, r) |
150 } | 150 } |
151 if i > 0 && res[i-1] == r { | 151 if i > 0 && res[i-1] == r { |
152 t.Errorf("test %q, lookup %q, result %d (n = %d): found
duplicate index %d", tc.name, s, i, n, r) | 152 t.Errorf("test %q, lookup %q, result %d (n = %d): found
duplicate index %d", tc.name, s, i, n, r) |
153 } | 153 } |
154 } | 154 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 for _, tc := range testCases { | 231 for _, tc := range testCases { |
232 x := New([]byte(tc.source)) | 232 x := New([]byte(tc.source)) |
233 testConstruction(t, &tc, x) | 233 testConstruction(t, &tc, x) |
234 testLookups(t, &tc, x, 0) | 234 testLookups(t, &tc, x, 0) |
235 testLookups(t, &tc, x, 1) | 235 testLookups(t, &tc, x, 1) |
236 testLookups(t, &tc, x, 10) | 236 testLookups(t, &tc, x, 10) |
237 testLookups(t, &tc, x, 2e9) | 237 testLookups(t, &tc, x, 2e9) |
238 testLookups(t, &tc, x, -1) | 238 testLookups(t, &tc, x, -1) |
239 } | 239 } |
240 } | 240 } |
OLD | NEW |