Fixed tests for new architecture

main
Bryson Zimmerman 11 months ago
parent ed103c30fe
commit 84109d48ed

@ -13,46 +13,41 @@ class MazeFinderTest {
MazeFinder.primsAlgorithm()
}
//Top row must have at least one south connection and no north connections
@Test
fun topRowOutOfBoundsCheck() {
var southExists = false
World.tiles.value.forEach {
col ->
if(col[0].isSouth())
for(x in 0..<World.sizeX) {
assert(!World.get(Tile(x, 0)).isNorth())
if(World.get(Tile(x, 0)).isSouth())
southExists = true
}
assert(southExists)
}
//Bottom row cannot have any south connections
@Test
fun bottomRowOutOfBoundsCheck() {
var southNotExists = true
World.tiles.value.forEach {
col ->
if(col[9].isSouth())
southNotExists = false
for(x in 0..<World.sizeX) {
assert(!World.get(Tile(x, World.sizeY-1)).isSouth())
}
assert(southNotExists)
}
@Test
fun allTilesVisited() {
World.tiles.value.forEach {
col ->
col.forEach {
tile ->
assert(tile.visited())
for(x in 0..<World.sizeX) {
for(y in 0..<World.sizeY) {
assert(World.get(Tile(x, y)).visited())
}
}
}
@Test
fun allTilesHaveConnections() {
World.tiles.value.forEachIndexed {
x,
col ->
col.forEachIndexed { y,
tileprop ->
for(x in 0..<World.sizeX) {
for(y in 0..<World.sizeY) {
val tileprop = World.get(Tile(x, y))
if(!tileprop.visited())
println("Empty Connections at: " + Tile(x, y).toString())
assert(tileprop.visited())

@ -1,18 +1,24 @@
import technology.zim.ArrayBackedPathfinder
import technology.zim.data.Tile
import technology.zim.data.TileHeap
import kotlin.math.abs
import kotlin.test.Test
import kotlin.test.BeforeTest
//TODO: update to use Tile adjustment to heap
class TileHeapTest {
companion object {
var gVals = HashMap<Tile, Int>()
var heap = TileHeap(Tile(20, 20), gVals)
var heap = TileHeap(Tile(20, 20), this::fValue)
private fun fValue(prospect: Tile, end: Tile): Int {
return hValue(prospect, end).plus(gVals.get(prospect) ?: 0)
}
private fun hValue(prospect: Tile, end:Tile): Int {
return abs(prospect.x() - end.x()) + abs(prospect.y() - end.y())
}
}
@BeforeTest
fun setUp() {
heap = TileHeap(Tile(20, 20), gVals)
heap = TileHeap(Tile(20, 20), Companion::fValue)
arrayOf(Tile(0, 0), Tile(1, 1), Tile(5, 5), Tile(4, 4), Tile(19, 19), Tile(2, 2)).forEach { item ->
heap.insert(item)
}

Loading…
Cancel
Save