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 TestIntZeroLen(t *testing.T) {
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 TestIntResize(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 TestIntResize2(t *testing.T) {
46 checkSize(t, &a, 0, 0)
47 a.Push(int2IntValue(1))
48 a.Push(int2IntValue(2))
49 a.Push(int2IntValue(3))
50 a.Push(int2IntValue(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) != intzero {
55 t.Errorf("%T: expected a.At(%d) == %v; found %v!", a, i, intzero, a.At(i))
58 for i := 4; i < len(a); i++ {
60 t.Errorf("%T: expected a[%d] == %v; found %v", a, i, intzero, a[i])
66 func checkIntZero(t *testing.T, a *IntVector, i int) {
67 for j := 0; j < i; j++ {
68 if a.At(j) == intzero {
69 t.Errorf("%T: 1 expected a.At(%d) == %d; found %v", a, j, j, a.At(j))
71 if (*a)[j] == intzero {
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) != intzero {
77 t.Errorf("%T: 3 expected a.At(%d) == %v; found %v", a, i, intzero, a.At(i))
79 if (*a)[i] != intzero {
80 t.Errorf("%T: 4 expected (*a)[%d] == %v; found %v", a, i, intzero, (*a)[i])
86 func TestIntTrailingElements(t *testing.T) {
88 for i := 0; i < 10; i++ {
89 a.Push(int2IntValue(i + 1))
91 checkIntZero(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 checkIntZero(t, &a, 5)
99 func TestIntAccess(t *testing.T) {
103 for i := 0; i < n; i++ {
104 a.Set(i, int2IntValue(val(i)))
106 for i := 0; i < n; i++ {
107 if elem2IntValue(a.At(i)) != int2IntValue(val(i)) {
113 for i := 0; i < n; i++ {
114 b[i] = int2IntValue(val(i))
116 for i := 0; i < n; i++ {
117 if elem2IntValue(b[i]) != int2IntValue(val(i)) {
124 func TestIntInsertDeleteClear(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, int2IntValue(val(i)))
136 if elem2IntValue(a.Last()) != int2IntValue(val(0)) {
140 for i := n - 1; i >= 0; i-- {
141 if elem2IntValue(a.Last()) != int2IntValue(val(0)) {
144 if elem2IntValue(a.At(0)) != int2IntValue(val(i)) {
147 if elem2IntValue(a[0]) != int2IntValue(val(i)) {
148 t.Errorf("%T: D2", a)
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(int2IntValue(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 elem2IntValue(a.Last()) != int2IntValue(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(int2IntValue(j))
188 for i := 0; i < n; i++ {
190 a.Push(int2IntValue(x))
191 if elem2IntValue(a.Pop()) != int2IntValue(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_sliceInt(t *testing.T, x *IntVector, elt, i, j int) {
212 for k := i; k < j; k++ {
213 if elem2IntValue(x.At(k)) != int2IntValue(elt) {
214 t.Errorf("%T: M) wrong [%d] element %v (expected %v)", x, k, elem2IntValue(x.At(k)), int2IntValue(elt))
219 for k, n := 0, j-i; k < n; k++ {
220 if elem2IntValue(s.At(k)) != int2IntValue(elt) {
221 t.Errorf("%T: N) wrong [%d] element %v (expected %v)", x, k, elem2IntValue(x.At(k)), int2IntValue(elt))
227 func verify_patternInt(t *testing.T, x *IntVector, 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_sliceInt(t, x, 0, 0, a)
236 verify_sliceInt(t, x, 1, a, a+b)
237 verify_sliceInt(t, x, 0, a+b, n)
241 func make_vectorInt(elt, len int) *IntVector {
242 x := new(IntVector).Resize(len, 0)
243 for i := 0; i < len; i++ {
244 x.Set(i, int2IntValue(elt))
250 func TestIntInsertVector(t *testing.T) {
252 a := make_vectorInt(0, 0)
253 b := make_vectorInt(1, 10)
255 verify_patternInt(t, a, 0, 10, 0)
257 a = make_vectorInt(0, 10)
258 b = make_vectorInt(1, 0)
260 verify_patternInt(t, a, 5, 0, 5)
262 a = make_vectorInt(0, 10)
263 b = make_vectorInt(1, 3)
265 verify_patternInt(t, a, 3, 3, 7)
267 a = make_vectorInt(0, 10)
268 b = make_vectorInt(1, 1000)
270 verify_patternInt(t, a, 8, 1000, 2)
274 func TestIntDo(t *testing.T) {
277 a := new(IntVector).Resize(n, 0)
278 for i := 0; i < n; i++ {
279 a.Set(i, int2IntValue(salt*i))
283 i := intf2IntValue(e)
284 if i != int2IntValue(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(IntVector).Resize(n, 0)
294 for i := 0; i < n; i++ {
295 (*b)[i] = int2IntValue(salt * i)
299 i := intf2IntValue(e)
300 if i != int2IntValue(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] = int2IntValue(salt * i)
316 i := intf2IntValue(e)
317 if i != int2IntValue(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 TestIntVectorCopy(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(int2IntValue(i * i))
337 for i := 0; i < Len; i++ {
338 src[i] = int2IntValue(-1)
339 v := elem2IntValue(dest[i])
340 if v != int2IntValue(i*i) {
341 t.Error(tname(src), "expected", i*i, "got", v)