1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:54:43 -07:00

make Len() == 0 for nil vector.Vector

(mimic behavior of slices)

R=r
DELTA=12  (12 added, 0 deleted, 0 changed)
OCL=28960
CL=28962
This commit is contained in:
Robert Griesemer 2009-05-15 21:59:08 -07:00
parent e8c1e2b93a
commit 8ee7688af6
2 changed files with 12 additions and 0 deletions

View File

@ -84,7 +84,11 @@ func New(len int) *Vector {
// Len returns the number of elements in the vector.
// Len is 0 if p == nil.
func (p *Vector) Len() int {
if p == nil {
return 0;
}
return len(p.a)
}

View File

@ -10,6 +10,14 @@ import "sort"
import "fmt"
func TestZeroLen(t *testing.T) {
var a *vector.Vector;
if a.Len() != 0 { t.Errorf("A) expected 0, got %d", a.Len()); }
a = vector.New(0);
if a.Len() != 0 { t.Errorf("B) expected 0, got %d", a.Len()); }
}
func TestInit(t *testing.T) {
var a vector.Vector;
if a.Init(0).Len() != 0 { t.Error("A") }