mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-07-06 01:50:42 +02:00
Made unit tests for common/coords compiling again. Fixed NaivBigMin. Added bit based BigMin + unit test, which is still failing.
This commit is contained in:
@ -4,7 +4,11 @@
|
||||
|
||||
package common
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var data = []int16{
|
||||
-2045, -1850, -1811, -1629, -1104,
|
||||
@ -138,14 +142,58 @@ func TestTransforms(t *testing.T) {
|
||||
checkTransformer(
|
||||
"I2P(P2I(plain))",
|
||||
CoordToPlain,
|
||||
compose(TransformPlainToInterleaved, TransformInterleavedPlain),
|
||||
compose(TransformPlainToInterleaved, TransformInterleavedToPlain),
|
||||
c, t)
|
||||
})
|
||||
allData(func(c Coord) {
|
||||
checkTransformer(
|
||||
"P2I(I2P(interleaved))",
|
||||
CoordToInterleaved,
|
||||
compose(TransformInterleavedPlain, TransformPlainToInterleaved),
|
||||
compose(TransformInterleavedToPlain, TransformPlainToInterleaved),
|
||||
c, t)
|
||||
})
|
||||
}
|
||||
|
||||
func TestBigMin(t *testing.T) {
|
||||
const tries = 1
|
||||
errors, success := 0, 0
|
||||
for i := 0; i < tries; i++ {
|
||||
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
|
||||
x2 := x1 + w
|
||||
y2 := y1 + h
|
||||
z2 := z1 + d
|
||||
|
||||
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++ {
|
||||
c3 := InterleavedToCoord(zcode)
|
||||
if cub.Contains(c3) {
|
||||
continue
|
||||
}
|
||||
nbm := NaiveBigMin(zmin, zmax, zcode)
|
||||
cbm := BigMin(zmin, zmax, zcode)
|
||||
//fmt.Printf("cbm: %d\n", cbm)
|
||||
//fmt.Printf("nbm: %d\n", nbm)
|
||||
if nbm != cbm {
|
||||
errors++
|
||||
} else {
|
||||
success++
|
||||
}
|
||||
}
|
||||
}
|
||||
if errors > 0 {
|
||||
t.Errorf("BigMin: %d errors out of %d (%f)\n",
|
||||
errors, errors+success, float64(errors)/float64(errors+success))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user