-
Notifications
You must be signed in to change notification settings - Fork 0
/
coordinate_test.go
30 lines (26 loc) · 1.21 KB
/
coordinate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPositioned_Distance(t *testing.T) {
t.Run("Zero relative", func(t *testing.T) {
zero := Coordinate{}
assert.Equal(t, SquareFloat(0.00), Distance(&zero, &zero))
assert.Equal(t, SquareFloat(3.00), Distance(&zero, &Coordinate{X: -1.0, Y: -1.0, Z: -1.0}))
assert.Equal(t, SquareFloat(13.25), Distance(&zero, &Coordinate{X: 2.0, Y: -3.0, Z: 0.5}))
})
t.Run("Non-zero relative", func(t *testing.T) {
lhs := Coordinate{X: -3.0, Y: 4.2, Z: 5.5}
assert.Equal(t, SquareFloat(0.00), Distance(&lhs, &lhs))
assert.Equal(t, SquareFloat(1.00), Distance(&lhs, &Coordinate{X: -2.0, Y: 4.2, Z: 5.5}))
assert.Equal(t, SquareFloat(2.00), Distance(&lhs, &Coordinate{X: -2.0, Y: 5.2, Z: 5.5}))
assert.Equal(t, SquareFloat(3.00), Distance(&lhs, &Coordinate{X: -2.0, Y: 5.2, Z: 4.5}))
assert.Equal(t, SquareFloat(56.89), Distance(&lhs, &Coordinate{X: -0.0}))
})
}
func TestCoordinate_SectorKey(t *testing.T) {
assert.Equal(t, SectorKey{}, Coordinate{}.SectorKey())
assert.Equal(t, SectorKey{X: -1}, Coordinate{X: -1, Y: 1, Z: 2}.SectorKey())
assert.Equal(t, SectorKey{X: 1, Y: -2}, Coordinate{X: 1 << 5, Y: -2 << 5, Z: (1 << 5) - 1}.SectorKey())
}