summaryrefslogtreecommitdiff
path: root/src/pkg/container/vector
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/container/vector')
-rw-r--r--src/pkg/container/vector/Makefile8
-rw-r--r--src/pkg/container/vector/intvector.go21
-rw-r--r--src/pkg/container/vector/intvector_test.go101
-rw-r--r--src/pkg/container/vector/numbers_test.go2
-rw-r--r--src/pkg/container/vector/stringvector.go21
-rw-r--r--src/pkg/container/vector/stringvector_test.go101
-rw-r--r--src/pkg/container/vector/vector.go21
-rw-r--r--src/pkg/container/vector/vector_test.go101
8 files changed, 91 insertions, 285 deletions
diff --git a/src/pkg/container/vector/Makefile b/src/pkg/container/vector/Makefile
index c456c6a6c..f6b50156f 100644
--- a/src/pkg/container/vector/Makefile
+++ b/src/pkg/container/vector/Makefile
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-include ../../../Make.$(GOARCH)
+include ../../../Make.inc
TARG=container/vector
GOFILES=\
@@ -42,8 +42,7 @@ generate: vector.go vector_test.go
| gofmt -r='make_vector -> make_vectorInt'\
| gofmt -r='TestInsertVector -> TestIntInsertVector'\
| gofmt -r='TestDo -> TestIntDo'\
- | gofmt -r='TestIter -> TestIntIter'\
- | gofmt -r='TestVectorData -> TestIntVectorData'\
+ | gofmt -r='TestVectorCopy -> TestIntVectorCopy'\
| gofmt -r='interface{} -> int'\
> intvector_test.go\
@@ -65,7 +64,6 @@ generate: vector.go vector_test.go
| gofmt -r='make_vector -> make_vectorStr'\
| gofmt -r='TestInsertVector -> TestStrInsertVector'\
| gofmt -r='TestDo -> TestStrDo'\
- | gofmt -r='TestIter -> TestStrIter'\
- | gofmt -r='TestVectorData -> TestStrVectorData'\
+ | gofmt -r='TestVectorCopy -> TestStrVectorCopy'\
| gofmt -r='interface{} -> string'\
> stringvector_test.go
diff --git a/src/pkg/container/vector/intvector.go b/src/pkg/container/vector/intvector.go
index 6aad358e3..5ad9e294b 100644
--- a/src/pkg/container/vector/intvector.go
+++ b/src/pkg/container/vector/intvector.go
@@ -104,8 +104,8 @@ func (p *IntVector) Set(i int, x int) { (*p)[i] = x }
func (p *IntVector) Last() int { return (*p)[len(*p)-1] }
-// Data returns all the elements as a slice.
-func (p *IntVector) Data() []int {
+// Copy makes a copy of the vector and returns it.
+func (p *IntVector) Copy() IntVector {
arr := make(IntVector, len(*p))
copy(arr, *p)
return arr
@@ -199,23 +199,6 @@ func (p *IntVector) Swap(i, j int) {
}
-// Iterate over all elements; driver for range
-func (p *IntVector) iterate(c chan<- int) {
- for _, v := range *p {
- c <- v
- }
- close(c)
-}
-
-
-// Channel iterator for range.
-func (p *IntVector) Iter() <-chan int {
- c := make(chan int)
- go p.iterate(c)
- return c
-}
-
-
// Do calls function f for each element of the vector, in order.
// The behavior of Do is undefined if f changes *p.
func (p *IntVector) Do(f func(elem int)) {
diff --git a/src/pkg/container/vector/intvector_test.go b/src/pkg/container/vector/intvector_test.go
index c80dd52cc..1e38a1982 100644
--- a/src/pkg/container/vector/intvector_test.go
+++ b/src/pkg/container/vector/intvector_test.go
@@ -127,59 +127,59 @@ func TestIntInsertDeleteClear(t *testing.T) {
for i := 0; i < n; i++ {
if a.Len() != i {
- t.Errorf("T%: A) wrong Len() %d (expected %d)", a, a.Len(), i)
+ t.Errorf("%T: A) wrong Len() %d (expected %d)", a, a.Len(), i)
}
if len(a) != i {
- t.Errorf("T%: A) wrong len() %d (expected %d)", a, len(a), i)
+ t.Errorf("%T: A) wrong len() %d (expected %d)", a, len(a), i)
}
a.Insert(0, int2IntValue(val(i)))
if elem2IntValue(a.Last()) != int2IntValue(val(0)) {
- t.Error("T%: B", a)
+ t.Errorf("%T: B", a)
}
}
for i := n - 1; i >= 0; i-- {
if elem2IntValue(a.Last()) != int2IntValue(val(0)) {
- t.Error("T%: C", a)
+ t.Errorf("%T: C", a)
}
if elem2IntValue(a.At(0)) != int2IntValue(val(i)) {
- t.Error("T%: D", a)
+ t.Errorf("%T: D", a)
}
if elem2IntValue(a[0]) != int2IntValue(val(i)) {
- t.Error("T%: D2", a)
+ t.Errorf("%T: D2", a)
}
a.Delete(0)
if a.Len() != i {
- t.Errorf("T%: E) wrong Len() %d (expected %d)", a, a.Len(), i)
+ t.Errorf("%T: E) wrong Len() %d (expected %d)", a, a.Len(), i)
}
if len(a) != i {
- t.Errorf("T%: E) wrong len() %d (expected %d)", a, len(a), i)
+ t.Errorf("%T: E) wrong len() %d (expected %d)", a, len(a), i)
}
}
if a.Len() != 0 {
- t.Errorf("T%: F) wrong Len() %d (expected 0)", a, a.Len())
+ t.Errorf("%T: F) wrong Len() %d (expected 0)", a, a.Len())
}
if len(a) != 0 {
- t.Errorf("T%: F) wrong len() %d (expected 0)", a, len(a))
+ t.Errorf("%T: F) wrong len() %d (expected 0)", a, len(a))
}
for i := 0; i < n; i++ {
a.Push(int2IntValue(val(i)))
if a.Len() != i+1 {
- t.Errorf("T%: G) wrong Len() %d (expected %d)", a, a.Len(), i+1)
+ t.Errorf("%T: G) wrong Len() %d (expected %d)", a, a.Len(), i+1)
}
if len(a) != i+1 {
- t.Errorf("T%: G) wrong len() %d (expected %d)", a, len(a), i+1)
+ t.Errorf("%T: G) wrong len() %d (expected %d)", a, len(a), i+1)
}
if elem2IntValue(a.Last()) != int2IntValue(val(i)) {
- t.Error("T%: H", a)
+ t.Errorf("%T: H", a)
}
}
a.Resize(0, 0)
if a.Len() != 0 {
- t.Errorf("T%: I wrong Len() %d (expected 0)", a, a.Len())
+ t.Errorf("%T: I wrong Len() %d (expected 0)", a, a.Len())
}
if len(a) != 0 {
- t.Errorf("T%: I wrong len() %d (expected 0)", a, len(a))
+ t.Errorf("%T: I wrong len() %d (expected 0)", a, len(a))
}
const m = 5
@@ -189,21 +189,21 @@ func TestIntInsertDeleteClear(t *testing.T) {
x := val(i)
a.Push(int2IntValue(x))
if elem2IntValue(a.Pop()) != int2IntValue(x) {
- t.Error("T%: J", a)
+ t.Errorf("%T: J", a)
}
if a.Len() != j+1 {
- t.Errorf("T%: K) wrong Len() %d (expected %d)", a, a.Len(), j+1)
+ t.Errorf("%T: K) wrong Len() %d (expected %d)", a, a.Len(), j+1)
}
if len(a) != j+1 {
- t.Errorf("T%: K) wrong len() %d (expected %d)", a, len(a), j+1)
+ t.Errorf("%T: K) wrong len() %d (expected %d)", a, len(a), j+1)
}
}
}
if a.Len() != m {
- t.Errorf("T%: L) wrong Len() %d (expected %d)", a, a.Len(), m)
+ t.Errorf("%T: L) wrong Len() %d (expected %d)", a, a.Len(), m)
}
if len(a) != m {
- t.Errorf("T%: L) wrong len() %d (expected %d)", a, len(a), m)
+ t.Errorf("%T: L) wrong len() %d (expected %d)", a, len(a), m)
}
}
@@ -211,14 +211,14 @@ func TestIntInsertDeleteClear(t *testing.T) {
func verify_sliceInt(t *testing.T, x *IntVector, elt, i, j int) {
for k := i; k < j; k++ {
if elem2IntValue(x.At(k)) != int2IntValue(elt) {
- t.Errorf("T%: M) wrong [%d] element %v (expected %v)", x, k, elem2IntValue(x.At(k)), int2IntValue(elt))
+ t.Errorf("%T: M) wrong [%d] element %v (expected %v)", x, k, elem2IntValue(x.At(k)), int2IntValue(elt))
}
}
s := x.Slice(i, j)
for k, n := 0, j-i; k < n; k++ {
if elem2IntValue(s.At(k)) != int2IntValue(elt) {
- t.Errorf("T%: N) wrong [%d] element %v (expected %v)", x, k, elem2IntValue(x.At(k)), int2IntValue(elt))
+ t.Errorf("%T: N) wrong [%d] element %v (expected %v)", x, k, elem2IntValue(x.At(k)), int2IntValue(elt))
}
}
}
@@ -227,10 +227,10 @@ func verify_sliceInt(t *testing.T, x *IntVector, elt, i, j int) {
func verify_patternInt(t *testing.T, x *IntVector, a, b, c int) {
n := a + b + c
if x.Len() != n {
- t.Errorf("T%: O) wrong Len() %d (expected %d)", x, x.Len(), n)
+ t.Errorf("%T: O) wrong Len() %d (expected %d)", x, x.Len(), n)
}
if len(*x) != n {
- t.Errorf("T%: O) wrong len() %d (expected %d)", x, len(*x), n)
+ t.Errorf("%T: O) wrong len() %d (expected %d)", x, len(*x), n)
}
verify_sliceInt(t, x, 0, 0, a)
verify_sliceInt(t, x, 1, a, a+b)
@@ -326,61 +326,14 @@ func TestIntDo(t *testing.T) {
}
-func TestIntIter(t *testing.T) {
- const Len = 100
- x := new(IntVector).Resize(Len, 0)
- for i := 0; i < Len; i++ {
- x.Set(i, int2IntValue(i*i))
- }
- i := 0
- for v := range x.Iter() {
- if elem2IntValue(v) != int2IntValue(i*i) {
- t.Error(tname(x), "Iter expected", i*i, "got", elem2IntValue(v))
- }
- i++
- }
- if i != Len {
- t.Error(tname(x), "Iter stopped at", i, "not", Len)
- }
- y := new(IntVector).Resize(Len, 0)
- for i := 0; i < Len; i++ {
- (*y)[i] = int2IntValue(i * i)
- }
- i = 0
- for v := range y.Iter() {
- if elem2IntValue(v) != int2IntValue(i*i) {
- t.Error(tname(y), "y, Iter expected", i*i, "got", elem2IntValue(v))
- }
- i++
- }
- if i != Len {
- t.Error(tname(y), "y, Iter stopped at", i, "not", Len)
- }
- var z IntVector
- z.Resize(Len, 0)
- for i := 0; i < Len; i++ {
- z[i] = int2IntValue(i * i)
- }
- i = 0
- for v := range z.Iter() {
- if elem2IntValue(v) != int2IntValue(i*i) {
- t.Error(tname(z), "z, Iter expected", i*i, "got", elem2IntValue(v))
- }
- i++
- }
- if i != Len {
- t.Error(tname(z), "z, Iter stopped at", i, "not", Len)
- }
-}
-
-func TestIntVectorData(t *testing.T) {
- // verify Data() returns a slice of a copy, not a slice of the original vector
+func TestIntVectorCopy(t *testing.T) {
+ // verify Copy() returns a copy, not simply a slice of the original vector
const Len = 10
var src IntVector
for i := 0; i < Len; i++ {
src.Push(int2IntValue(i * i))
}
- dest := src.Data()
+ dest := src.Copy()
for i := 0; i < Len; i++ {
src[i] = int2IntValue(-1)
v := elem2IntValue(dest[i])
diff --git a/src/pkg/container/vector/numbers_test.go b/src/pkg/container/vector/numbers_test.go
index a44242f67..93335ca60 100644
--- a/src/pkg/container/vector/numbers_test.go
+++ b/src/pkg/container/vector/numbers_test.go
@@ -20,7 +20,7 @@ func s(n uint64) string {
lens := len(str)
a := make([]string, (lens+2)/3)
start := lens
- for i, _ := range a {
+ for i := range a {
start -= 3
if start < 0 {
start = 0
diff --git a/src/pkg/container/vector/stringvector.go b/src/pkg/container/vector/stringvector.go
index ddc030f81..852685f5a 100644
--- a/src/pkg/container/vector/stringvector.go
+++ b/src/pkg/container/vector/stringvector.go
@@ -104,8 +104,8 @@ func (p *StringVector) Set(i int, x string) { (*p)[i] = x }
func (p *StringVector) Last() string { return (*p)[len(*p)-1] }
-// Data returns all the elements as a slice.
-func (p *StringVector) Data() []string {
+// Copy makes a copy of the vector and returns it.
+func (p *StringVector) Copy() StringVector {
arr := make(StringVector, len(*p))
copy(arr, *p)
return arr
@@ -199,23 +199,6 @@ func (p *StringVector) Swap(i, j int) {
}
-// Iterate over all elements; driver for range
-func (p *StringVector) iterate(c chan<- string) {
- for _, v := range *p {
- c <- v
- }
- close(c)
-}
-
-
-// Channel iterator for range.
-func (p *StringVector) Iter() <-chan string {
- c := make(chan string)
- go p.iterate(c)
- return c
-}
-
-
// Do calls function f for each element of the vector, in order.
// The behavior of Do is undefined if f changes *p.
func (p *StringVector) Do(f func(elem string)) {
diff --git a/src/pkg/container/vector/stringvector_test.go b/src/pkg/container/vector/stringvector_test.go
index 859dac2fd..776ae26de 100644
--- a/src/pkg/container/vector/stringvector_test.go
+++ b/src/pkg/container/vector/stringvector_test.go
@@ -127,59 +127,59 @@ func TestStrInsertDeleteClear(t *testing.T) {
for i := 0; i < n; i++ {
if a.Len() != i {
- t.Errorf("T%: A) wrong Len() %d (expected %d)", a, a.Len(), i)
+ t.Errorf("%T: A) wrong Len() %d (expected %d)", a, a.Len(), i)
}
if len(a) != i {
- t.Errorf("T%: A) wrong len() %d (expected %d)", a, len(a), i)
+ t.Errorf("%T: A) wrong len() %d (expected %d)", a, len(a), i)
}
a.Insert(0, int2StrValue(val(i)))
if elem2StrValue(a.Last()) != int2StrValue(val(0)) {
- t.Error("T%: B", a)
+ t.Errorf("%T: B", a)
}
}
for i := n - 1; i >= 0; i-- {
if elem2StrValue(a.Last()) != int2StrValue(val(0)) {
- t.Error("T%: C", a)
+ t.Errorf("%T: C", a)
}
if elem2StrValue(a.At(0)) != int2StrValue(val(i)) {
- t.Error("T%: D", a)
+ t.Errorf("%T: D", a)
}
if elem2StrValue(a[0]) != int2StrValue(val(i)) {
- t.Error("T%: D2", a)
+ t.Errorf("%T: D2", a)
}
a.Delete(0)
if a.Len() != i {
- t.Errorf("T%: E) wrong Len() %d (expected %d)", a, a.Len(), i)
+ t.Errorf("%T: E) wrong Len() %d (expected %d)", a, a.Len(), i)
}
if len(a) != i {
- t.Errorf("T%: E) wrong len() %d (expected %d)", a, len(a), i)
+ t.Errorf("%T: E) wrong len() %d (expected %d)", a, len(a), i)
}
}
if a.Len() != 0 {
- t.Errorf("T%: F) wrong Len() %d (expected 0)", a, a.Len())
+ t.Errorf("%T: F) wrong Len() %d (expected 0)", a, a.Len())
}
if len(a) != 0 {
- t.Errorf("T%: F) wrong len() %d (expected 0)", a, len(a))
+ t.Errorf("%T: F) wrong len() %d (expected 0)", a, len(a))
}
for i := 0; i < n; i++ {
a.Push(int2StrValue(val(i)))
if a.Len() != i+1 {
- t.Errorf("T%: G) wrong Len() %d (expected %d)", a, a.Len(), i+1)
+ t.Errorf("%T: G) wrong Len() %d (expected %d)", a, a.Len(), i+1)
}
if len(a) != i+1 {
- t.Errorf("T%: G) wrong len() %d (expected %d)", a, len(a), i+1)
+ t.Errorf("%T: G) wrong len() %d (expected %d)", a, len(a), i+1)
}
if elem2StrValue(a.Last()) != int2StrValue(val(i)) {
- t.Error("T%: H", a)
+ t.Errorf("%T: H", a)
}
}
a.Resize(0, 0)
if a.Len() != 0 {
- t.Errorf("T%: I wrong Len() %d (expected 0)", a, a.Len())
+ t.Errorf("%T: I wrong Len() %d (expected 0)", a, a.Len())
}
if len(a) != 0 {
- t.Errorf("T%: I wrong len() %d (expected 0)", a, len(a))
+ t.Errorf("%T: I wrong len() %d (expected 0)", a, len(a))
}
const m = 5
@@ -189,21 +189,21 @@ func TestStrInsertDeleteClear(t *testing.T) {
x := val(i)
a.Push(int2StrValue(x))
if elem2StrValue(a.Pop()) != int2StrValue(x) {
- t.Error("T%: J", a)
+ t.Errorf("%T: J", a)
}
if a.Len() != j+1 {
- t.Errorf("T%: K) wrong Len() %d (expected %d)", a, a.Len(), j+1)
+ t.Errorf("%T: K) wrong Len() %d (expected %d)", a, a.Len(), j+1)
}
if len(a) != j+1 {
- t.Errorf("T%: K) wrong len() %d (expected %d)", a, len(a), j+1)
+ t.Errorf("%T: K) wrong len() %d (expected %d)", a, len(a), j+1)
}
}
}
if a.Len() != m {
- t.Errorf("T%: L) wrong Len() %d (expected %d)", a, a.Len(), m)
+ t.Errorf("%T: L) wrong Len() %d (expected %d)", a, a.Len(), m)
}
if len(a) != m {
- t.Errorf("T%: L) wrong len() %d (expected %d)", a, len(a), m)
+ t.Errorf("%T: L) wrong len() %d (expected %d)", a, len(a), m)
}
}
@@ -211,14 +211,14 @@ func TestStrInsertDeleteClear(t *testing.T) {
func verify_sliceStr(t *testing.T, x *StringVector, elt, i, j int) {
for k := i; k < j; k++ {
if elem2StrValue(x.At(k)) != int2StrValue(elt) {
- t.Errorf("T%: M) wrong [%d] element %v (expected %v)", x, k, elem2StrValue(x.At(k)), int2StrValue(elt))
+ t.Errorf("%T: M) wrong [%d] element %v (expected %v)", x, k, elem2StrValue(x.At(k)), int2StrValue(elt))
}
}
s := x.Slice(i, j)
for k, n := 0, j-i; k < n; k++ {
if elem2StrValue(s.At(k)) != int2StrValue(elt) {
- t.Errorf("T%: N) wrong [%d] element %v (expected %v)", x, k, elem2StrValue(x.At(k)), int2StrValue(elt))
+ t.Errorf("%T: N) wrong [%d] element %v (expected %v)", x, k, elem2StrValue(x.At(k)), int2StrValue(elt))
}
}
}
@@ -227,10 +227,10 @@ func verify_sliceStr(t *testing.T, x *StringVector, elt, i, j int) {
func verify_patternStr(t *testing.T, x *StringVector, a, b, c int) {
n := a + b + c
if x.Len() != n {
- t.Errorf("T%: O) wrong Len() %d (expected %d)", x, x.Len(), n)
+ t.Errorf("%T: O) wrong Len() %d (expected %d)", x, x.Len(), n)
}
if len(*x) != n {
- t.Errorf("T%: O) wrong len() %d (expected %d)", x, len(*x), n)
+ t.Errorf("%T: O) wrong len() %d (expected %d)", x, len(*x), n)
}
verify_sliceStr(t, x, 0, 0, a)
verify_sliceStr(t, x, 1, a, a+b)
@@ -326,61 +326,14 @@ func TestStrDo(t *testing.T) {
}
-func TestStrIter(t *testing.T) {
- const Len = 100
- x := new(StringVector).Resize(Len, 0)
- for i := 0; i < Len; i++ {
- x.Set(i, int2StrValue(i*i))
- }
- i := 0
- for v := range x.Iter() {
- if elem2StrValue(v) != int2StrValue(i*i) {
- t.Error(tname(x), "Iter expected", i*i, "got", elem2StrValue(v))
- }
- i++
- }
- if i != Len {
- t.Error(tname(x), "Iter stopped at", i, "not", Len)
- }
- y := new(StringVector).Resize(Len, 0)
- for i := 0; i < Len; i++ {
- (*y)[i] = int2StrValue(i * i)
- }
- i = 0
- for v := range y.Iter() {
- if elem2StrValue(v) != int2StrValue(i*i) {
- t.Error(tname(y), "y, Iter expected", i*i, "got", elem2StrValue(v))
- }
- i++
- }
- if i != Len {
- t.Error(tname(y), "y, Iter stopped at", i, "not", Len)
- }
- var z StringVector
- z.Resize(Len, 0)
- for i := 0; i < Len; i++ {
- z[i] = int2StrValue(i * i)
- }
- i = 0
- for v := range z.Iter() {
- if elem2StrValue(v) != int2StrValue(i*i) {
- t.Error(tname(z), "z, Iter expected", i*i, "got", elem2StrValue(v))
- }
- i++
- }
- if i != Len {
- t.Error(tname(z), "z, Iter stopped at", i, "not", Len)
- }
-}
-
-func TestStrVectorData(t *testing.T) {
- // verify Data() returns a slice of a copy, not a slice of the original vector
+func TestStrVectorCopy(t *testing.T) {
+ // verify Copy() returns a copy, not simply a slice of the original vector
const Len = 10
var src StringVector
for i := 0; i < Len; i++ {
src.Push(int2StrValue(i * i))
}
- dest := src.Data()
+ dest := src.Copy()
for i := 0; i < Len; i++ {
src[i] = int2StrValue(-1)
v := elem2StrValue(dest[i])
diff --git a/src/pkg/container/vector/vector.go b/src/pkg/container/vector/vector.go
index 986321b14..f43e4d23c 100644
--- a/src/pkg/container/vector/vector.go
+++ b/src/pkg/container/vector/vector.go
@@ -104,8 +104,8 @@ func (p *Vector) Set(i int, x interface{}) { (*p)[i] = x }
func (p *Vector) Last() interface{} { return (*p)[len(*p)-1] }
-// Data returns all the elements as a slice.
-func (p *Vector) Data() []interface{} {
+// Copy makes a copy of the vector and returns it.
+func (p *Vector) Copy() Vector {
arr := make(Vector, len(*p))
copy(arr, *p)
return arr
@@ -199,23 +199,6 @@ func (p *Vector) Swap(i, j int) {
}
-// Iterate over all elements; driver for range
-func (p *Vector) iterate(c chan<- interface{}) {
- for _, v := range *p {
- c <- v
- }
- close(c)
-}
-
-
-// Channel iterator for range.
-func (p *Vector) Iter() <-chan interface{} {
- c := make(chan interface{})
- go p.iterate(c)
- return c
-}
-
-
// Do calls function f for each element of the vector, in order.
// The behavior of Do is undefined if f changes *p.
func (p *Vector) Do(f func(elem interface{})) {
diff --git a/src/pkg/container/vector/vector_test.go b/src/pkg/container/vector/vector_test.go
index 158b34479..a9c4ceb55 100644
--- a/src/pkg/container/vector/vector_test.go
+++ b/src/pkg/container/vector/vector_test.go
@@ -127,59 +127,59 @@ func TestInsertDeleteClear(t *testing.T) {
for i := 0; i < n; i++ {
if a.Len() != i {
- t.Errorf("T%: A) wrong Len() %d (expected %d)", a, a.Len(), i)
+ t.Errorf("%T: A) wrong Len() %d (expected %d)", a, a.Len(), i)
}
if len(a) != i {
- t.Errorf("T%: A) wrong len() %d (expected %d)", a, len(a), i)
+ t.Errorf("%T: A) wrong len() %d (expected %d)", a, len(a), i)
}
a.Insert(0, int2Value(val(i)))
if elem2Value(a.Last()) != int2Value(val(0)) {
- t.Error("T%: B", a)
+ t.Errorf("%T: B", a)
}
}
for i := n - 1; i >= 0; i-- {
if elem2Value(a.Last()) != int2Value(val(0)) {
- t.Error("T%: C", a)
+ t.Errorf("%T: C", a)
}
if elem2Value(a.At(0)) != int2Value(val(i)) {
- t.Error("T%: D", a)
+ t.Errorf("%T: D", a)
}
if elem2Value(a[0]) != int2Value(val(i)) {
- t.Error("T%: D2", a)
+ t.Errorf("%T: D2", a)
}
a.Delete(0)
if a.Len() != i {
- t.Errorf("T%: E) wrong Len() %d (expected %d)", a, a.Len(), i)
+ t.Errorf("%T: E) wrong Len() %d (expected %d)", a, a.Len(), i)
}
if len(a) != i {
- t.Errorf("T%: E) wrong len() %d (expected %d)", a, len(a), i)
+ t.Errorf("%T: E) wrong len() %d (expected %d)", a, len(a), i)
}
}
if a.Len() != 0 {
- t.Errorf("T%: F) wrong Len() %d (expected 0)", a, a.Len())
+ t.Errorf("%T: F) wrong Len() %d (expected 0)", a, a.Len())
}
if len(a) != 0 {
- t.Errorf("T%: F) wrong len() %d (expected 0)", a, len(a))
+ t.Errorf("%T: F) wrong len() %d (expected 0)", a, len(a))
}
for i := 0; i < n; i++ {
a.Push(int2Value(val(i)))
if a.Len() != i+1 {
- t.Errorf("T%: G) wrong Len() %d (expected %d)", a, a.Len(), i+1)
+ t.Errorf("%T: G) wrong Len() %d (expected %d)", a, a.Len(), i+1)
}
if len(a) != i+1 {
- t.Errorf("T%: G) wrong len() %d (expected %d)", a, len(a), i+1)
+ t.Errorf("%T: G) wrong len() %d (expected %d)", a, len(a), i+1)
}
if elem2Value(a.Last()) != int2Value(val(i)) {
- t.Error("T%: H", a)
+ t.Errorf("%T: H", a)
}
}
a.Resize(0, 0)
if a.Len() != 0 {
- t.Errorf("T%: I wrong Len() %d (expected 0)", a, a.Len())
+ t.Errorf("%T: I wrong Len() %d (expected 0)", a, a.Len())
}
if len(a) != 0 {
- t.Errorf("T%: I wrong len() %d (expected 0)", a, len(a))
+ t.Errorf("%T: I wrong len() %d (expected 0)", a, len(a))
}
const m = 5
@@ -189,21 +189,21 @@ func TestInsertDeleteClear(t *testing.T) {
x := val(i)
a.Push(int2Value(x))
if elem2Value(a.Pop()) != int2Value(x) {
- t.Error("T%: J", a)
+ t.Errorf("%T: J", a)
}
if a.Len() != j+1 {
- t.Errorf("T%: K) wrong Len() %d (expected %d)", a, a.Len(), j+1)
+ t.Errorf("%T: K) wrong Len() %d (expected %d)", a, a.Len(), j+1)
}
if len(a) != j+1 {
- t.Errorf("T%: K) wrong len() %d (expected %d)", a, len(a), j+1)
+ t.Errorf("%T: K) wrong len() %d (expected %d)", a, len(a), j+1)
}
}
}
if a.Len() != m {
- t.Errorf("T%: L) wrong Len() %d (expected %d)", a, a.Len(), m)
+ t.Errorf("%T: L) wrong Len() %d (expected %d)", a, a.Len(), m)
}
if len(a) != m {
- t.Errorf("T%: L) wrong len() %d (expected %d)", a, len(a), m)
+ t.Errorf("%T: L) wrong len() %d (expected %d)", a, len(a), m)
}
}
@@ -211,14 +211,14 @@ func TestInsertDeleteClear(t *testing.T) {
func verify_slice(t *testing.T, x *Vector, elt, i, j int) {
for k := i; k < j; k++ {
if elem2Value(x.At(k)) != int2Value(elt) {
- t.Errorf("T%: M) wrong [%d] element %v (expected %v)", x, k, elem2Value(x.At(k)), int2Value(elt))
+ t.Errorf("%T: M) wrong [%d] element %v (expected %v)", x, k, elem2Value(x.At(k)), int2Value(elt))
}
}
s := x.Slice(i, j)
for k, n := 0, j-i; k < n; k++ {
if elem2Value(s.At(k)) != int2Value(elt) {
- t.Errorf("T%: N) wrong [%d] element %v (expected %v)", x, k, elem2Value(x.At(k)), int2Value(elt))
+ t.Errorf("%T: N) wrong [%d] element %v (expected %v)", x, k, elem2Value(x.At(k)), int2Value(elt))
}
}
}
@@ -227,10 +227,10 @@ func verify_slice(t *testing.T, x *Vector, elt, i, j int) {
func verify_pattern(t *testing.T, x *Vector, a, b, c int) {
n := a + b + c
if x.Len() != n {
- t.Errorf("T%: O) wrong Len() %d (expected %d)", x, x.Len(), n)
+ t.Errorf("%T: O) wrong Len() %d (expected %d)", x, x.Len(), n)
}
if len(*x) != n {
- t.Errorf("T%: O) wrong len() %d (expected %d)", x, len(*x), n)
+ t.Errorf("%T: O) wrong len() %d (expected %d)", x, len(*x), n)
}
verify_slice(t, x, 0, 0, a)
verify_slice(t, x, 1, a, a+b)
@@ -326,61 +326,14 @@ func TestDo(t *testing.T) {
}
-func TestIter(t *testing.T) {
- const Len = 100
- x := new(Vector).Resize(Len, 0)
- for i := 0; i < Len; i++ {
- x.Set(i, int2Value(i*i))
- }
- i := 0
- for v := range x.Iter() {
- if elem2Value(v) != int2Value(i*i) {
- t.Error(tname(x), "Iter expected", i*i, "got", elem2Value(v))
- }
- i++
- }
- if i != Len {
- t.Error(tname(x), "Iter stopped at", i, "not", Len)
- }
- y := new(Vector).Resize(Len, 0)
- for i := 0; i < Len; i++ {
- (*y)[i] = int2Value(i * i)
- }
- i = 0
- for v := range y.Iter() {
- if elem2Value(v) != int2Value(i*i) {
- t.Error(tname(y), "y, Iter expected", i*i, "got", elem2Value(v))
- }
- i++
- }
- if i != Len {
- t.Error(tname(y), "y, Iter stopped at", i, "not", Len)
- }
- var z Vector
- z.Resize(Len, 0)
- for i := 0; i < Len; i++ {
- z[i] = int2Value(i * i)
- }
- i = 0
- for v := range z.Iter() {
- if elem2Value(v) != int2Value(i*i) {
- t.Error(tname(z), "z, Iter expected", i*i, "got", elem2Value(v))
- }
- i++
- }
- if i != Len {
- t.Error(tname(z), "z, Iter stopped at", i, "not", Len)
- }
-}
-
-func TestVectorData(t *testing.T) {
- // verify Data() returns a slice of a copy, not a slice of the original vector
+func TestVectorCopy(t *testing.T) {
+ // verify Copy() returns a copy, not simply a slice of the original vector
const Len = 10
var src Vector
for i := 0; i < Len; i++ {
src.Push(int2Value(i * i))
}
- dest := src.Data()
+ dest := src.Copy()
for i := 0; i < Len; i++ {
src[i] = int2Value(-1)
v := elem2Value(dest[i])