From 6e958e4ff611dd7ade1049f9c66dc39e5f8bf3a7 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 7 Sep 2014 00:18:28 +0200 Subject: [PATCH] Be more clever in testing BigMin. This shows that the interleaving code has shift all values to be positive, so it's broken atm. :-/ --- common/coords_test.go | 50 ++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/common/coords_test.go b/common/coords_test.go index 556d279..e34f640 100644 --- a/common/coords_test.go +++ b/common/coords_test.go @@ -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) { - const tries = 1 - errors, success := 0, 0 + const tries = 10 for i := 0; i < tries; i++ { x1 := 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)} 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) zmax := CoordToInterleaved(c2) - for zcode := zmin + 1; zcode < zmax; zcode++ { - if cub.Contains(InterleavedToCoord(zcode)) { - continue - } + errors, success := 0, 0 + for zcode := range outsiders(zmin, zmax) { nbm := NaiveBigMin(zmin, zmax, zcode) cbm := BigMin(zmin, zmax, zcode) //fmt.Printf("nbm: %b\n", nbm) @@ -189,9 +212,12 @@ func TestBigMin(t *testing.T) { success++ } } - } - if errors > 0 { - t.Errorf("BigMin: %d errors out of %d (%f)\n", - errors, errors+success, float64(errors)/float64(errors+success)) + if errors > 0 { + cub := Cuboid{P1: c1, P2: c2} + t.Errorf("BigMin: %s %d errors out of %d (%f)\n", + cub, + errors, errors+success, + float64(errors)/float64(errors+success)) + } } }