func (p *PList) Equiv(o interface{}) bool { if p == o { return true } if os, ok := o.(iseq.Seqable); ok { return sequtil.SeqEquiv(p.Seq(), os.Seq()) } return false }
// Equiv returns true if this Cons is eqivalent to the given object, treated as an iseq.Seqable. func (c *Cons) Equiv(o interface{}) bool { if c == o { return true } if os, ok := o.(iseq.Seqable); ok { return sequtil.SeqEquiv(c, os.Seq()) } // TODO: handle built-in 'sequable' things such as arrays, slices, strings return false }
func TestPVectorAssocN(t *testing.T) { v3o := NewPVectorFromItems("abc", 4, 5) v3 := NewPVectorFromItems("abc", 4, 5) v3a := v3.AssocN(1, "def") if !sequtil.SeqEquiv(v3o.Seq(), v3.Seq()) { t.Error("PVector.AssocN: appears to have mutated original") } if v3a.Count() != v3.Count() { t.Errorf("PVector.AssocN: count should be %v, got %v", v3.Count(), v3a.Count()) } v3t := NewPVectorFromItems("abc", "def", 5) if !sequtil.SeqEquiv(v3a.Seq(), v3t.Seq()) { t.Errorf("PVector.AssocN: wrong items") } v4a := v3.AssocN(3, "pqr") if !sequtil.SeqEquiv(v3o.Seq(), v3.Seq()) { t.Error("PVector.AssocN: appears to have mutated original") } if v4a.Count() != v3.Count()+1 { t.Errorf("PVector.AssocN: appending count should be %v, got %v", v3.Count()+1, v3a.Count()) } v4t := NewPVectorFromItems("abc", 4, 5, "pqr") if !sequtil.SeqEquiv(v4a.Seq(), v4t.Seq()) { t.Errorf("PVector.AssocN: wrong items on append") } v1a := NewPVectorFromItems().AssocN(0, "abc") if c := v1a.Count(); c != 1 { t.Errorf("PVector.AssocN: appending to empty should have one element, found %v", c) } if e := v1a.Nth(0); e != "abc" { t.Errorf("PVector.AssocN: appending to empty, first (only) element should be abc, got %v", e) } }
func TestPVectorConses(t *testing.T) { v3 := NewPVectorFromItems("abc", 4, 5) s4 := v3.Seq().ConsS(12) if s4.Count() != 4 { t.Error("SCons of PVector.Seq has wrong count") } if s4.First() != 12 { t.Error("SCons of PVector.Seq has wrong first item") } if !sequtil.SeqEquiv(s4.Next(), v3.Seq()) { t.Error("SCons of PVector.Seq has wrong next seq") } }
func TestPVectorCons(t *testing.T) { v3 := NewPVectorFromItems("abc", 4, 5) v4 := v3.ConsV(12) c4 := v3.Cons(12) if c4.Count() != 4 { t.Error("Cons of PVector has wrong count") } vc4, vok := c4.(*PVector) if !vok { t.Errorf("Cons of PVector should be a PVector, got %T", vc4) } for i := 0; i < c4.Count(); i++ { if vc4.Nth(i) != v4.Nth(i) { t.Errorf("Cons of PVector has wrong item at %v", i) } } if !sequtil.SeqEquiv(c4.Seq(), v4.Seq()) { t.Error("Something wrong with Seq()ing on PVector") } }