Fixed tests for new architecture

main
Bryson Zimmerman 11 months ago
parent ed103c30fe
commit 84109d48ed

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

@ -1,18 +1,24 @@
import technology.zim.ArrayBackedPathfinder
import technology.zim.data.Tile import technology.zim.data.Tile
import technology.zim.data.TileHeap import technology.zim.data.TileHeap
import kotlin.math.abs
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.BeforeTest import kotlin.test.BeforeTest
//TODO: update to use Tile adjustment to heap
class TileHeapTest { class TileHeapTest {
companion object { companion object {
var gVals = HashMap<Tile, Int>() 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 @BeforeTest
fun setUp() { 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 -> arrayOf(Tile(0, 0), Tile(1, 1), Tile(5, 5), Tile(4, 4), Tile(19, 19), Tile(2, 2)).forEach { item ->
heap.insert(item) heap.insert(item)
} }

Loading…
Cancel
Save