tins2021/tiles_test.go
Sander Schobers 13b6a50a45 Added bitmap font.
Added monsters.
Added animations.
Added rendering of geometries.
2021-08-09 01:25:51 +02:00

90 lines
2.5 KiB
Go

package tins2021
import (
"testing"
"github.com/stretchr/testify/assert"
"opslag.de/schobers/geom"
)
func TestTilesNotTraversableWhenNoTile(t *testing.T) {
tiles := Tiles{}
pos := geom.ZeroPt
tiles[pos] = &Tile{}
for _, dir := range AllDirections {
_, ok := tiles.CanMove(pos, dir)
assert.False(t, ok)
}
}
func TestTilesIsTraversableInDirection(t *testing.T) {
tiles := Tiles{}
center := geom.Pt(1, 1)
tiles[center] = &Tile{}
for _, dir := range AllDirections {
tiles[AdjacentPosition(center, dir)] = &Tile{}
}
tiles[geom.Pt(1, 2)] = &Tile{}
for _, dir := range AllDirections {
pos, ok := tiles.CanMove(center, dir)
assert.True(t, ok)
assert.Equal(t, AdjacentPosition(center, dir), pos)
}
}
func TestTilesNotTraversableWhenGoingUpFromInversedTile(t *testing.T) {
tiles := Tiles{}
center := geom.Pt(1, 1)
tiles[center] = &Tile{Inversed: true}
leftUp := AdjacentPosition(center, DirectionUpLeft)
rightUp := AdjacentPosition(center, DirectionUpRight)
tiles[leftUp] = &Tile{}
tiles[rightUp] = &Tile{}
_, ok := tiles.CanMove(center, DirectionUpLeft)
assert.False(t, ok)
_, ok = tiles.CanMove(center, DirectionUpLeft)
assert.False(t, ok)
}
func TestTilesNotTraversableWhenGoingDownToInversedTile(t *testing.T) {
tiles := Tiles{}
center := geom.Pt(1, 1)
tiles[center] = &Tile{}
leftDown := AdjacentPosition(center, DirectionDownLeft)
rightDown := AdjacentPosition(center, DirectionDownRight)
tiles[leftDown] = &Tile{Inversed: true}
tiles[rightDown] = &Tile{Inversed: true}
_, ok := tiles.CanMove(center, DirectionDownLeft)
assert.False(t, ok)
_, ok = tiles.CanMove(center, DirectionDownLeft)
assert.False(t, ok)
}
func TestTilesTraversableWhenGoingDownFromInversedTile(t *testing.T) {
tiles := Tiles{}
center := geom.Pt(1, 1)
tiles[center] = &Tile{Inversed: true}
leftDown := AdjacentPosition(center, DirectionDownLeft)
rightDown := AdjacentPosition(center, DirectionDownRight)
tiles[leftDown] = &Tile{}
tiles[rightDown] = &Tile{}
_, ok := tiles.CanMove(center, DirectionDownLeft)
assert.True(t, ok)
_, ok = tiles.CanMove(center, DirectionDownLeft)
assert.True(t, ok)
}
func TestTilesTraversableWhenGoingUpToInversedTile(t *testing.T) {
tiles := Tiles{}
center := geom.Pt(1, 1)
tiles[center] = &Tile{}
leftUp := AdjacentPosition(center, DirectionUpLeft)
rightUp := AdjacentPosition(center, DirectionUpRight)
tiles[leftUp] = &Tile{Inversed: true}
tiles[rightUp] = &Tile{Inversed: true}
_, ok := tiles.CanMove(center, DirectionUpLeft)
assert.True(t, ok)
_, ok = tiles.CanMove(center, DirectionUpLeft)
assert.True(t, ok)
}