From 45ec5ccd3e5b1e545b3854ae132cc28ccbce58d2 Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sun, 7 Sep 2014 10:12:39 +0200 Subject: [PATCH] Simplified unit test for BigMin. --- common/coords_test.go | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/common/coords_test.go b/common/coords_test.go index 36e866e..b6f9b81 100644 --- a/common/coords_test.go +++ b/common/coords_test.go @@ -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) - - 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 - } + 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++ { + zn := CoordToInterleaved(c) + 1 + if zn > zmin && zn < zmax && !cub.Contains(InterleavedToCoord(zn)) { + fn(zn) } } } - }() - return outs + } } func TestBigMin(t *testing.T) { @@ -214,7 +204,7 @@ func TestBigMin(t *testing.T) { } errors, success := 0, 0 - for zcode := range outsiders(zmin, zmax) { + outsiders(zmin, zmax, func(zcode int64) { nbm := NaiveBigMin(zmin, zmax, zcode) cbm := BigMin(zmin, zmax, zcode) //fmt.Printf("nbm: %b\n", nbm) @@ -224,7 +214,7 @@ func TestBigMin(t *testing.T) { } else { success++ } - } + }) if errors > 0 { cub := Cuboid{P1: c1, P2: c2} t.Errorf("BigMin: %s (%d %d) %d errors out of %d (%f)\n",