2020-07-04 19:25:53 -04:00
|
|
|
package d2vector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2020-07-09 08:30:55 -04:00
|
|
|
func validate(t *testing.T, original, got, want, unchanged Vector) {
|
|
|
|
if !got.EqualsApprox(want) {
|
2020-07-04 19:25:53 -04:00
|
|
|
t.Errorf("want %s: got %s", want, got)
|
|
|
|
}
|
|
|
|
|
2020-07-09 08:30:55 -04:00
|
|
|
if !original.EqualsApprox(unchanged) {
|
2020-07-04 19:25:53 -04:00
|
|
|
t.Errorf("Position value %s was incorrectly changed to %s when calling this method", unchanged, original)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTile(t *testing.T) {
|
|
|
|
p := NewPosition(1.6, 1.6)
|
|
|
|
got := p.Tile()
|
2020-07-09 08:30:55 -04:00
|
|
|
want := NewVector(1, 1)
|
|
|
|
unchanged := NewVector(1.6, 1.6)
|
2020-07-04 19:25:53 -04:00
|
|
|
|
2020-07-09 08:30:55 -04:00
|
|
|
validate(t, p.Vector, *got, want, unchanged)
|
2020-07-04 19:25:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTileOffset(t *testing.T) {
|
|
|
|
p := NewPosition(1.6, 1.6)
|
|
|
|
got := p.TileOffset()
|
2020-07-09 08:30:55 -04:00
|
|
|
want := NewVector(0.6, 0.6)
|
|
|
|
unchanged := NewVector(1.6, 1.6)
|
2020-07-04 19:25:53 -04:00
|
|
|
|
2020-07-09 08:30:55 -04:00
|
|
|
validate(t, p.Vector, *got, want, unchanged)
|
2020-07-04 19:25:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSubWorld(t *testing.T) {
|
|
|
|
p := NewPosition(1, 1)
|
|
|
|
got := p.SubWorld()
|
2020-07-09 08:30:55 -04:00
|
|
|
want := NewVector(5, 5)
|
|
|
|
unchanged := NewVector(1, 1)
|
2020-07-04 19:25:53 -04:00
|
|
|
|
2020-07-09 08:30:55 -04:00
|
|
|
validate(t, p.Vector, *got, want, unchanged)
|
2020-07-04 19:25:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSubTile(t *testing.T) {
|
|
|
|
p := NewPosition(1, 1)
|
|
|
|
got := p.SubTile()
|
2020-07-09 08:30:55 -04:00
|
|
|
want := NewVector(5, 5)
|
|
|
|
unchanged := NewVector(1, 1)
|
2020-07-04 19:25:53 -04:00
|
|
|
|
2020-07-09 08:30:55 -04:00
|
|
|
validate(t, p.Vector, *got, want, unchanged)
|
2020-07-04 19:25:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSubTileOffset(t *testing.T) {
|
|
|
|
p := NewPosition(1.1, 1.1)
|
|
|
|
got := p.SubTileOffset()
|
2020-07-09 08:30:55 -04:00
|
|
|
want := NewVector(0.5, 0.5)
|
|
|
|
unchanged := NewVector(1.1, 1.1)
|
2020-07-04 19:25:53 -04:00
|
|
|
|
2020-07-09 08:30:55 -04:00
|
|
|
validate(t, p.Vector, *got, want, unchanged)
|
2020-07-04 19:25:53 -04:00
|
|
|
}
|