From f75e1015af6084693c4c760c28c6beb119aee73f Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Sat, 6 Sep 2014 20:38:49 +0200 Subject: [PATCH] Some code cleanup in unit test for bit version of BigMin. Test is still failing. --- common/coords.go | 27 ++++++++++++++------------- common/coords_test.go | 16 +++++++--------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/common/coords.go b/common/coords.go index 881c217..b714d07 100644 --- a/common/coords.go +++ b/common/coords.go @@ -250,33 +250,34 @@ func NaiveBigMin(minz, maxz, zcode int64) int64 { } const ( - bits = 12 - msb = uint(3*bits - 1) - _000_ = 0 - _001_ = 1 - _010_ = 2 - _011_ = 2 | 1 - _100_ = 4 - _101_ = 4 | 1 - mask = int64(0x924924924924924) - full = int64(0xfffffffffffffff) + bits = 12 + msb = uint8(3*bits - 1) + mask = int64(0x924924924924924) + full = int64(0xfffffffffffffff) ) -func setbits(p uint, v int64) int64 { +func setbits(p uint8, v int64) int64 { m := (mask >> (msb - p)) & (^(full << p) & full) return (v | m) & ^(1 << p) & full } -func unsetbits(p uint, v int64) int64 { +func unsetbits(p uint8, v int64) int64 { m := ^(mask >> (msb - p)) & full return (v & m) | (int64(1) << p) } func BigMin(minz, maxz, zcode int64) int64 { + const ( + _001_ = 1 + _010_ = 2 + _011_ = 2 | 1 + _100_ = 4 + _101_ = 4 | 1 + ) bigmin := maxz pos := msb for m := int64(1) << msb; m != 0; m >>= 1 { - var v uint16 + var v uint8 if zcode&m != 0 { v = _100_ } diff --git a/common/coords_test.go b/common/coords_test.go index 4d3c7d4..556d279 100644 --- a/common/coords_test.go +++ b/common/coords_test.go @@ -5,7 +5,6 @@ package common import ( - "fmt" "math/rand" "testing" ) @@ -161,9 +160,9 @@ func TestBigMin(t *testing.T) { x1 := rand.Intn(4000) - 2000 y1 := rand.Intn(4000) - 2000 z1 := rand.Intn(4000) - 2000 - w := rand.Intn(20) + 1 - h := rand.Intn(20) + 1 - d := rand.Intn(20) + 1 + w := rand.Intn(18) + 1 + h := rand.Intn(18) + 1 + d := rand.Intn(18) + 1 x2 := x1 + w y2 := y1 + h z2 := z1 + d @@ -171,20 +170,19 @@ 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) + //fmt.Printf("Cuboid: %s\n", cub) zmin := CoordToInterleaved(c1) zmax := CoordToInterleaved(c2) for zcode := zmin + 1; zcode < zmax; zcode++ { - c3 := InterleavedToCoord(zcode) - if cub.Contains(c3) { + if cub.Contains(InterleavedToCoord(zcode)) { continue } nbm := NaiveBigMin(zmin, zmax, zcode) cbm := BigMin(zmin, zmax, zcode) - //fmt.Printf("cbm: %d\n", cbm) - //fmt.Printf("nbm: %d\n", nbm) + //fmt.Printf("nbm: %b\n", nbm) + //fmt.Printf("cbm: %b\n", cbm) if nbm != cbm { errors++ } else {