| gofmt -r='make_vector -> make_vectorInt'\
| gofmt -r='TestInsertVector -> TestIntInsertVector'\
| gofmt -r='TestDo -> TestIntDo'\
- | gofmt -r='TestVectorData -> TestIntVectorData'\
+ | gofmt -r='TestVectorCopy -> TestIntVectorCopy'\
| gofmt -r='interface{} -> int'\
> intvector_test.go\
| gofmt -r='make_vector -> make_vectorStr'\
| gofmt -r='TestInsertVector -> TestStrInsertVector'\
| gofmt -r='TestDo -> TestStrDo'\
- | gofmt -r='TestVectorData -> TestStrVectorData'\
+ | gofmt -r='TestVectorCopy -> TestStrVectorCopy'\
| gofmt -r='interface{} -> string'\
> stringvector_test.go
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
}
-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])
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
}
-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])
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
}
-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])
// Data returns a slice containing the elements of iter.
func Data(iter Iterable) []interface{} {
- vec := new(vector.Vector)
+ var v vector.Vector
for e := range iter.Iter() {
- vec.Push(e)
+ v.Push(e)
}
- return vec.Data()
+ return v
}
// filteredIterable is a struct that implements Iterable with each element
for x := range GroupBy(elevenToTwenty, intkey{}).Iter() {
out.Push(x.(Group).Key)
}
- assertArraysAreEqual(t, out.Data(), elevenToTwenty)
+ assertArraysAreEqual(t, out, elevenToTwenty)
}
func TestUnique(t *testing.T) {