Commit 8ee7688a authored by Robert Griesemer's avatar Robert Griesemer

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
parent e8c1e2b9
......@@ -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)
}
......
......@@ -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") }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment