1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // CAUTION: If this file is not vector_test.go, it was generated
6 // automatically from vector_test.go - DO NOT EDIT in that case!
13 func TestStrZeroLen(t *testing.T) {
14 a := new(StringVector)
16 t.Errorf("%T: B1) expected 0, got %d", a, a.Len())
19 t.Errorf("%T: B2) expected 0, got %d", a, len(*a))
23 t.Errorf("%T: B3) expected 0, got %d", b, b.Len())
26 t.Errorf("%T: B4) expected 0, got %d", b, len(b))
31 func TestStrResize(t *testing.T) {
33 checkSize(t, &a, 0, 0)
34 checkSize(t, a.Resize(0, 5), 0, 5)
35 checkSize(t, a.Resize(1, 0), 1, 5)
36 checkSize(t, a.Resize(10, 0), 10, 10)
37 checkSize(t, a.Resize(5, 0), 5, 10)
38 checkSize(t, a.Resize(3, 8), 3, 10)
39 checkSize(t, a.Resize(0, 100), 0, 100)
40 checkSize(t, a.Resize(11, 100), 11, 100)
44 func TestStrResize2(t *testing.T) {
46 checkSize(t, &a, 0, 0)
47 a.Push(int2StrValue(1))
48 a.Push(int2StrValue(2))
49 a.Push(int2StrValue(3))
50 a.Push(int2StrValue(4))
51 checkSize(t, &a, 4, 4)
52 checkSize(t, a.Resize(10, 0), 10, 10)
53 for i := 4; i < a.Len(); i++ {
54 if a.At(i) != strzero {
55 t.Errorf("%T: expected a.At(%d) == %v; found %v!", a, i, strzero, a.At(i))
58 for i := 4; i < len(a); i++ {
60 t.Errorf("%T: expected a[%d] == %v; found %v", a, i, strzero, a[i])
66 func checkStrZero(t *testing.T, a *StringVector, i int) {
67 for j := 0; j < i; j++ {
68 if a.At(j) == strzero {
69 t.Errorf("%T: 1 expected a.At(%d) == %d; found %v", a, j, j, a.At(j))
71 if (*a)[j] == strzero {
72 t.Errorf("%T: 2 expected (*a)[%d] == %d; found %v", a, j, j, (*a)[j])
75 for ; i < a.Len(); i++ {
76 if a.At(i) != strzero {
77 t.Errorf("%T: 3 expected a.At(%d) == %v; found %v", a, i, strzero, a.At(i))
79 if (*a)[i] != strzero {
80 t.Errorf("%T: 4 expected (*a)[%d] == %v; found %v", a, i, strzero, (*a)[i])
86 func TestStrTrailingElements(t *testing.T) {
88 for i := 0; i < 10; i++ {
89 a.Push(int2StrValue(i + 1))
91 checkStrZero(t, &a, 10)
92 checkSize(t, &a, 10, 16)
93 checkSize(t, a.Resize(5, 0), 5, 16)
94 checkSize(t, a.Resize(10, 0), 10, 16)
95 checkStrZero(t, &a, 5)
99 func TestStrAccess(t *testing.T) {
103 for i := 0; i < n; i++ {
104 a.Set(i, int2StrValue(val(i)))
106 for i := 0; i < n; i++ {
107 if elem2StrValue(a.At(i)) != int2StrValue(val(i)) {
113 for i := 0; i < n; i++ {
114 b[i] = int2StrValue(val(i))
116 for i := 0; i < n; i++ {
117 if elem2StrValue(b[i]) != int2StrValue(val(i)) {
124 func TestStrInsertDeleteClear(t *testing.T) {
128 for i := 0; i < n; i++ {
130 t.Errorf("T%: A) wrong Len() %d (expected %d)", a, a.Len(), i)
133 t.Errorf("T%: A) wrong len() %d (expected %d)", a, len(a), i)
135 a.Insert(0, int2StrValue(val(i)))
136 if elem2StrValue(a.Last()) != int2StrValue(val(0)) {
140 for i := n - 1; i >= 0; i-- {
141 if elem2StrValue(a.Last()) != int2StrValue(val(0)) {
144 if elem2StrValue(a.At(0)) != int2StrValue(val(i)) {
147 if elem2StrValue(a[0]) != int2StrValue(val(i)) {
152 t.Errorf("T%: E) wrong Len() %d (expected %d)", a, a.Len(), i)
155 t.Errorf("T%: E) wrong len() %d (expected %d)", a, len(a), i)
160 t.Errorf("T%: F) wrong Len() %d (expected 0)", a, a.Len())
163 t.Errorf("T%: F) wrong len() %d (expected 0)", a, len(a))
165 for i := 0; i < n; i++ {
166 a.Push(int2StrValue(val(i)))
168 t.Errorf("T%: G) wrong Len() %d (expected %d)", a, a.Len(), i+1)
171 t.Errorf("T%: G) wrong len() %d (expected %d)", a, len(a), i+1)
173 if elem2StrValue(a.Last()) != int2StrValue(val(i)) {
179 t.Errorf("T%: I wrong Len() %d (expected 0)", a, a.Len())
182 t.Errorf("T%: I wrong len() %d (expected 0)", a, len(a))
186 for j := 0; j < m; j++ {
187 a.Push(int2StrValue(j))
188 for i := 0; i < n; i++ {
190 a.Push(int2StrValue(x))
191 if elem2StrValue(a.Pop()) != int2StrValue(x) {
195 t.Errorf("T%: K) wrong Len() %d (expected %d)", a, a.Len(), j+1)
198 t.Errorf("T%: K) wrong len() %d (expected %d)", a, len(a), j+1)
203 t.Errorf("T%: L) wrong Len() %d (expected %d)", a, a.Len(), m)
206 t.Errorf("T%: L) wrong len() %d (expected %d)", a, len(a), m)
211 func verify_sliceStr(t *testing.T, x *StringVector, elt, i, j int) {
212 for k := i; k < j; k++ {
213 if elem2StrValue(x.At(k)) != int2StrValue(elt) {
214 t.Errorf("T%: M) wrong [%d] element %v (expected %v)", x, k, elem2StrValue(x.At(k)), int2StrValue(elt))
219 for k, n := 0, j-i; k < n; k++ {
220 if elem2StrValue(s.At(k)) != int2StrValue(elt) {
221 t.Errorf("T%: N) wrong [%d] element %v (expected %v)", x, k, elem2StrValue(x.At(k)), int2StrValue(elt))
227 func verify_patternStr(t *testing.T, x *StringVector, a, b, c int) {
230 t.Errorf("T%: O) wrong Len() %d (expected %d)", x, x.Len(), n)
233 t.Errorf("T%: O) wrong len() %d (expected %d)", x, len(*x), n)
235 verify_sliceStr(t, x, 0, 0, a)
236 verify_sliceStr(t, x, 1, a, a+b)
237 verify_sliceStr(t, x, 0, a+b, n)
241 func make_vectorStr(elt, len int) *StringVector {
242 x := new(StringVector).Resize(len, 0)
243 for i := 0; i < len; i++ {
244 x.Set(i, int2StrValue(elt))
250 func TestStrInsertVector(t *testing.T) {
252 a := make_vectorStr(0, 0)
253 b := make_vectorStr(1, 10)
255 verify_patternStr(t, a, 0, 10, 0)
257 a = make_vectorStr(0, 10)
258 b = make_vectorStr(1, 0)
260 verify_patternStr(t, a, 5, 0, 5)
262 a = make_vectorStr(0, 10)
263 b = make_vectorStr(1, 3)
265 verify_patternStr(t, a, 3, 3, 7)
267 a = make_vectorStr(0, 10)
268 b = make_vectorStr(1, 1000)
270 verify_patternStr(t, a, 8, 1000, 2)
274 func TestStrDo(t *testing.T) {
277 a := new(StringVector).Resize(n, 0)
278 for i := 0; i < n; i++ {
279 a.Set(i, int2StrValue(salt*i))
282 a.Do(func(e string) {
283 i := intf2StrValue(e)
284 if i != int2StrValue(count*salt) {
285 t.Error(tname(a), "value at", count, "should be", count*salt, "not", i)
290 t.Error(tname(a), "should visit", n, "values; did visit", count)
293 b := new(StringVector).Resize(n, 0)
294 for i := 0; i < n; i++ {
295 (*b)[i] = int2StrValue(salt * i)
298 b.Do(func(e string) {
299 i := intf2StrValue(e)
300 if i != int2StrValue(count*salt) {
301 t.Error(tname(b), "b) value at", count, "should be", count*salt, "not", i)
306 t.Error(tname(b), "b) should visit", n, "values; did visit", count)
311 for i := 0; i < n; i++ {
312 c[i] = int2StrValue(salt * i)
315 c.Do(func(e string) {
316 i := intf2StrValue(e)
317 if i != int2StrValue(count*salt) {
318 t.Error(tname(c), "c) value at", count, "should be", count*salt, "not", i)
323 t.Error(tname(c), "c) should visit", n, "values; did visit", count)
329 func TestStrVectorCopy(t *testing.T) {
330 // verify Copy() returns a copy, not simply a slice of the original vector
333 for i := 0; i < Len; i++ {
334 src.Push(int2StrValue(i * i))
337 for i := 0; i < Len; i++ {
338 src[i] = int2StrValue(-1)
339 v := elem2StrValue(dest[i])
340 if v != int2StrValue(i*i) {
341 t.Error(tname(src), "expected", i*i, "got", v)