Simplified unit test for BigMin.

This commit is contained in:
Sascha L. Teichmann 2014-09-07 10:12:39 +02:00
parent a8c2a4c55d
commit 45ec5ccd3e

View File

@ -162,32 +162,22 @@ func TestCoordInterleaving(t *testing.T) {
}) })
} }
func outsiders(zmin, zmax int64) chan int64 { func outsiders(zmin, zmax int64, fn func(int64)) {
outs := make(chan int64) c1 := InterleavedToCoord(zmin)
c2 := InterleavedToCoord(zmax)
go func() { cub := Cuboid{P1: c1, P2: c2}
defer close(outs) var c Coord
c1 := InterleavedToCoord(zmin) for c.X = c1.X; c.X <= c2.X; c.X++ {
c2 := InterleavedToCoord(zmax) for c.Y = c1.Y; c.Y <= c2.Y; c.Y++ {
cub := Cuboid{P1: c1, P2: c2} for c.Z = c1.Z; c.Z <= c2.Z; c.Z++ {
var c Coord zn := CoordToInterleaved(c) + 1
for c.X = c1.X; c.X <= c2.X; c.X++ { if zn > zmin && zn < zmax && !cub.Contains(InterleavedToCoord(zn)) {
for c.Y = c1.Y; c.Y <= c2.Y; c.Y++ { fn(zn)
for c.Z = c1.Z; c.Z <= c2.Z; c.Z++ {
code := CoordToInterleaved(c) + 1
if code < zmin || code > zmax {
continue
}
c3 := InterleavedToCoord(code)
if !cub.Contains(c3) {
outs <- code
}
} }
} }
} }
}() }
return outs
} }
func TestBigMin(t *testing.T) { func TestBigMin(t *testing.T) {
@ -214,7 +204,7 @@ func TestBigMin(t *testing.T) {
} }
errors, success := 0, 0 errors, success := 0, 0
for zcode := range outsiders(zmin, zmax) { outsiders(zmin, zmax, func(zcode int64) {
nbm := NaiveBigMin(zmin, zmax, zcode) nbm := NaiveBigMin(zmin, zmax, zcode)
cbm := BigMin(zmin, zmax, zcode) cbm := BigMin(zmin, zmax, zcode)
//fmt.Printf("nbm: %b\n", nbm) //fmt.Printf("nbm: %b\n", nbm)
@ -224,7 +214,7 @@ func TestBigMin(t *testing.T) {
} else { } else {
success++ success++
} }
} })
if errors > 0 { if errors > 0 {
cub := Cuboid{P1: c1, P2: c2} cub := Cuboid{P1: c1, P2: c2}
t.Errorf("BigMin: %s (%d %d) %d errors out of %d (%f)\n", t.Errorf("BigMin: %s (%d %d) %d errors out of %d (%f)\n",