package common import "testing" //var data = []int16{-2} var data = []int16{ -2045, -1850, -1811, -1629, -1104, -967, -725, -646, -329, -212, -150, 88, 524, 527, 549, 1783, 1817, 1826, 2028, 2032} func allData(f func(int16, int16, int16)) { for _, z := range data { for _, y := range data { for _, x := range data { f(x, y, z) } } } } func checkJoinSplit( desc string, join KeyJoiner, split KeySplitter, x1, y1, z1 int16, t *testing.T) { k1 := join(x1, y1, z1) x2, y2, z2 := split(k1) if x1 != x2 || y1 != y2 || z1 != z2 { t.Errorf("%s: Expected (%d, %d, %d) got (%d, %d, %d) %b\n", desc, x1, y1, z1, x2, y2, z2, k1) } } func TestJoinSplit(t *testing.T) { allData(func(x, y, z int16) { checkJoinSplit( "P2XYZ(XYZ2P(xyz))", XYZToPlain, PlainToXYZ, x, y, z, t) }) allData(func(x, y, z int16) { checkJoinSplit( "I2XYZ(XYZ2I(xyz))", XYZToInterleaved, InterleavedToXYZ, x, y, z, t) }) } func checkTransformer( desc string, joiner KeyJoiner, transform KeyTransformer, x, y, z int16, t *testing.T) { k1 := joiner(x, y, z) k2 := transform(k1) if k2 != k1 { t.Errorf("%s: Expected %v got %v for (%d, %d, %d)\n", desc, k1, k2, x, y, z) } } func compose(transforms ...KeyTransformer) KeyTransformer { return func(x int64) int64 { for _, transform := range transforms { x = transform(x) } return x } } func TestTransforms(t *testing.T) { // Mainly to check the test itself. allData(func(x, y, z int16) { checkTransformer( "plain", XYZToPlain, compose(), x, y, z, t) }) allData(func(x, y, z int16) { checkTransformer( "I2P(P2I(plain))", XYZToPlain, compose(TransformPlainToInterleaved, TransformInterleavedPlain), x, y, z, t) }) allData(func(x, y, z int16) { checkTransformer( "P2I(I2P(interleaved))", XYZToInterleaved, compose(TransformInterleavedPlain, TransformPlainToInterleaved), x, y, z, t) }) }