pmap/pvec_test.go

52 lines
783 B
Go

package pmap
import (
"testing"
)
func TestPvec(t *testing.T) {
for n := 4; n < 1024*1024; {
list := make([]Value, n)
for i := range list {
list[i] = len(list) - i
}
p := list2pvec(list)
got := pvec2list(p)
if !eq(list, got) {
t.Error("mismatch with n =", n)
if n < 128 {
t.Error(" want =", list)
t.Error(" got =", got)
}
break
}
if n < 1024 {
n++
} else {
n += n / 8
}
}
}
func eq(a, b []Value) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
func TestFloor(t *testing.T) {
if got := floor(8); got != 4 {
t.Errorf("floor(%v) = %v, want %v", 8, got, 4)
}
if got := floor(9); got != 8 {
t.Errorf("floor(%v) = %v, want %v", 9, got, 8)
}
}