Be more clever in testing BigMin. This shows that the interleaving code has shift all values to be positive, so it's broken atm. :-/

This commit is contained in:
Sascha L. Teichmann 2014-09-07 00:18:28 +02:00
parent abaef4936c
commit 6e958e4ff6

View File

@ -153,9 +153,36 @@ func TestTransforms(t *testing.T) {
}) })
} }
func outsiders(zmin, zmax int64) chan int64 {
outs := make(chan int64)
go func() {
defer close(outs)
c1 := InterleavedToCoord(zmin)
c2 := InterleavedToCoord(zmax)
cub := Cuboid{P1: c1, P2: c2}
var c Coord
for c.X = c1.X; c.X <= c2.X; c.X++ {
for c.Y = c1.Y; c.Y <= c2.Y; c.Y++ {
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) {
const tries = 1 const tries = 10
errors, success := 0, 0
for i := 0; i < tries; i++ { for i := 0; i < tries; i++ {
x1 := rand.Intn(4000) - 2000 x1 := rand.Intn(4000) - 2000
y1 := rand.Intn(4000) - 2000 y1 := rand.Intn(4000) - 2000
@ -169,16 +196,12 @@ func TestBigMin(t *testing.T) {
c1 := Coord{X: int16(x1), Y: int16(y1), Z: int16(z1)} c1 := Coord{X: int16(x1), Y: int16(y1), Z: int16(z1)}
c2 := Coord{X: int16(x2), Y: int16(y2), Z: int16(z2)} c2 := Coord{X: int16(x2), Y: int16(y2), Z: int16(z2)}
cub := Cuboid{P1: c1, P2: c2}
//fmt.Printf("Cuboid: %s\n", cub)
zmin := CoordToInterleaved(c1) zmin := CoordToInterleaved(c1)
zmax := CoordToInterleaved(c2) zmax := CoordToInterleaved(c2)
for zcode := zmin + 1; zcode < zmax; zcode++ { errors, success := 0, 0
if cub.Contains(InterleavedToCoord(zcode)) { for zcode := range outsiders(zmin, zmax) {
continue
}
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)
@ -189,9 +212,12 @@ func TestBigMin(t *testing.T) {
success++ success++
} }
} }
}
if errors > 0 { if errors > 0 {
t.Errorf("BigMin: %d errors out of %d (%f)\n", cub := Cuboid{P1: c1, P2: c2}
errors, errors+success, float64(errors)/float64(errors+success)) t.Errorf("BigMin: %s %d errors out of %d (%f)\n",
cub,
errors, errors+success,
float64(errors)/float64(errors+success))
}
} }
} }