mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-17 15:48:17 +01:00
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:
parent
abaef4936c
commit
6e958e4ff6
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user