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!
12 func TestIntZeroLen(t *testing.T) {
15 t.Errorf("%T: B1) expected 0, got %d", a, a.Len())
18 t.Errorf("%T: B2) expected 0, got %d", a, len(*a))
22 t.Errorf("%T: B3) expected 0, got %d", b, b.Len())
25 t.Errorf("%T: B4) expected 0, got %d", b, len(b))
29 func TestIntResize(t *testing.T) {
31 checkSize(t, &a, 0, 0)
32 checkSize(t, a.Resize(0, 5), 0, 5)
33 checkSize(t, a.Resize(1, 0), 1, 5)
34 checkSize(t, a.Resize(10, 0), 10, 10)
35 checkSize(t, a.Resize(5, 0), 5, 10)
36 checkSize(t, a.Resize(3, 8), 3, 10)
37 checkSize(t, a.Resize(0, 100), 0, 100)
38 checkSize(t, a.Resize(11, 100), 11, 100)
41 func TestIntResize2(t *testing.T) {
43 checkSize(t, &a, 0, 0)
44 a.Push(int2IntValue(1))
45 a.Push(int2IntValue(2))
46 a.Push(int2IntValue(3))
47 a.Push(int2IntValue(4))
48 checkSize(t, &a, 4, 4)
49 checkSize(t, a.Resize(10, 0), 10, 10)
50 for i := 4; i < a.Len(); i++ {
51 if a.At(i) != intzero {
52 t.Errorf("%T: expected a.At(%d) == %v; found %v!", a, i, intzero, a.At(i))
55 for i := 4; i < len(a); i++ {
57 t.Errorf("%T: expected a[%d] == %v; found %v", a, i, intzero, a[i])
62 func checkIntZero(t *testing.T, a *IntVector, i int) {
63 for j := 0; j < i; j++ {
64 if a.At(j) == intzero {
65 t.Errorf("%T: 1 expected a.At(%d) == %d; found %v", a, j, j, a.At(j))
67 if (*a)[j] == intzero {
68 t.Errorf("%T: 2 expected (*a)[%d] == %d; found %v", a, j, j, (*a)[j])
71 for ; i < a.Len(); i++ {
72 if a.At(i) != intzero {
73 t.Errorf("%T: 3 expected a.At(%d) == %v; found %v", a, i, intzero, a.At(i))
75 if (*a)[i] != intzero {
76 t.Errorf("%T: 4 expected (*a)[%d] == %v; found %v", a, i, intzero, (*a)[i])
81 func TestIntTrailingElements(t *testing.T) {
83 for i := 0; i < 10; i++ {
84 a.Push(int2IntValue(i + 1))
86 checkIntZero(t, &a, 10)
87 checkSize(t, &a, 10, 16)
88 checkSize(t, a.Resize(5, 0), 5, 16)
89 checkSize(t, a.Resize(10, 0), 10, 16)
90 checkIntZero(t, &a, 5)
93 func TestIntAccess(t *testing.T) {
97 for i := 0; i < n; i++ {
98 a.Set(i, int2IntValue(val(i)))
100 for i := 0; i < n; i++ {
101 if elem2IntValue(a.At(i)) != int2IntValue(val(i)) {
107 for i := 0; i < n; i++ {
108 b[i] = int2IntValue(val(i))
110 for i := 0; i < n; i++ {
111 if elem2IntValue(b[i]) != int2IntValue(val(i)) {
117 func TestIntInsertDeleteClear(t *testing.T) {
121 for i := 0; i < n; i++ {
123 t.Errorf("%T: A) wrong Len() %d (expected %d)", a, a.Len(), i)
126 t.Errorf("%T: A) wrong len() %d (expected %d)", a, len(a), i)
128 a.Insert(0, int2IntValue(val(i)))
129 if elem2IntValue(a.Last()) != int2IntValue(val(0)) {
133 for i := n - 1; i >= 0; i-- {
134 if elem2IntValue(a.Last()) != int2IntValue(val(0)) {
137 if elem2IntValue(a.At(0)) != int2IntValue(val(i)) {
140 if elem2IntValue(a[0]) != int2IntValue(val(i)) {
141 t.Errorf("%T: D2", a)
145 t.Errorf("%T: E) wrong Len() %d (expected %d)", a, a.Len(), i)
148 t.Errorf("%T: E) wrong len() %d (expected %d)", a, len(a), i)
153 t.Errorf("%T: F) wrong Len() %d (expected 0)", a, a.Len())
156 t.Errorf("%T: F) wrong len() %d (expected 0)", a, len(a))
158 for i := 0; i < n; i++ {
159 a.Push(int2IntValue(val(i)))
161 t.Errorf("%T: G) wrong Len() %d (expected %d)", a, a.Len(), i+1)
164 t.Errorf("%T: G) wrong len() %d (expected %d)", a, len(a), i+1)
166 if elem2IntValue(a.Last()) != int2IntValue(val(i)) {
172 t.Errorf("%T: I wrong Len() %d (expected 0)", a, a.Len())
175 t.Errorf("%T: I wrong len() %d (expected 0)", a, len(a))
179 for j := 0; j < m; j++ {
180 a.Push(int2IntValue(j))
181 for i := 0; i < n; i++ {
183 a.Push(int2IntValue(x))
184 if elem2IntValue(a.Pop()) != int2IntValue(x) {
188 t.Errorf("%T: K) wrong Len() %d (expected %d)", a, a.Len(), j+1)
191 t.Errorf("%T: K) wrong len() %d (expected %d)", a, len(a), j+1)
196 t.Errorf("%T: L) wrong Len() %d (expected %d)", a, a.Len(), m)
199 t.Errorf("%T: L) wrong len() %d (expected %d)", a, len(a), m)
203 func verify_sliceInt(t *testing.T, x *IntVector, elt, i, j int) {
204 for k := i; k < j; k++ {
205 if elem2IntValue(x.At(k)) != int2IntValue(elt) {
206 t.Errorf("%T: M) wrong [%d] element %v (expected %v)", x, k, elem2IntValue(x.At(k)), int2IntValue(elt))
211 for k, n := 0, j-i; k < n; k++ {
212 if elem2IntValue(s.At(k)) != int2IntValue(elt) {
213 t.Errorf("%T: N) wrong [%d] element %v (expected %v)", x, k, elem2IntValue(x.At(k)), int2IntValue(elt))
218 func verify_patternInt(t *testing.T, x *IntVector, a, b, c int) {
221 t.Errorf("%T: O) wrong Len() %d (expected %d)", x, x.Len(), n)
224 t.Errorf("%T: O) wrong len() %d (expected %d)", x, len(*x), n)
226 verify_sliceInt(t, x, 0, 0, a)
227 verify_sliceInt(t, x, 1, a, a+b)
228 verify_sliceInt(t, x, 0, a+b, n)
231 func make_vectorInt(elt, len int) *IntVector {
232 x := new(IntVector).Resize(len, 0)
233 for i := 0; i < len; i++ {
234 x.Set(i, int2IntValue(elt))
239 func TestIntInsertVector(t *testing.T) {
241 a := make_vectorInt(0, 0)
242 b := make_vectorInt(1, 10)
244 verify_patternInt(t, a, 0, 10, 0)
246 a = make_vectorInt(0, 10)
247 b = make_vectorInt(1, 0)
249 verify_patternInt(t, a, 5, 0, 5)
251 a = make_vectorInt(0, 10)
252 b = make_vectorInt(1, 3)
254 verify_patternInt(t, a, 3, 3, 7)
256 a = make_vectorInt(0, 10)
257 b = make_vectorInt(1, 1000)
259 verify_patternInt(t, a, 8, 1000, 2)
262 func TestIntDo(t *testing.T) {
265 a := new(IntVector).Resize(n, 0)
266 for i := 0; i < n; i++ {
267 a.Set(i, int2IntValue(salt*i))
271 i := intf2IntValue(e)
272 if i != int2IntValue(count*salt) {
273 t.Error(tname(a), "value at", count, "should be", count*salt, "not", i)
278 t.Error(tname(a), "should visit", n, "values; did visit", count)
281 b := new(IntVector).Resize(n, 0)
282 for i := 0; i < n; i++ {
283 (*b)[i] = int2IntValue(salt * i)
287 i := intf2IntValue(e)
288 if i != int2IntValue(count*salt) {
289 t.Error(tname(b), "b) value at", count, "should be", count*salt, "not", i)
294 t.Error(tname(b), "b) should visit", n, "values; did visit", count)
299 for i := 0; i < n; i++ {
300 c[i] = int2IntValue(salt * i)
304 i := intf2IntValue(e)
305 if i != int2IntValue(count*salt) {
306 t.Error(tname(c), "c) value at", count, "should be", count*salt, "not", i)
311 t.Error(tname(c), "c) should visit", n, "values; did visit", count)
316 func TestIntVectorCopy(t *testing.T) {
317 // verify Copy() returns a copy, not simply a slice of the original vector
320 for i := 0; i < Len; i++ {
321 src.Push(int2IntValue(i * i))
324 for i := 0; i < Len; i++ {
325 src[i] = int2IntValue(-1)
326 v := elem2IntValue(dest[i])
327 if v != int2IntValue(i*i) {
328 t.Error(tname(src), "expected", i*i, "got", v)