Add OrderClue tests

This commit is contained in:
Christian Basler
2024-07-03 16:39:54 +02:00
parent 5b97b789a5
commit 9a38d85e84
3 changed files with 42 additions and 6 deletions

View File

@@ -6,10 +6,9 @@ class Game(
) {
val horizontalClues = clues.filterIsInstance<HorizontalClue>()
val verticalClues = clues.filterIsInstance<SameColumnClue<ItemClass<*>, ItemClass<*>>>()
val positionalClues = clues.filterIsInstance<PositionClue<ItemClass<*>>>()
init {
for (position in positionalClues) {
for (position in clues.filterIsInstance<PositionClue<ItemClass<*>>>()) {
val row = grid[position.item.itemType.companion]
row.forEachIndexed { index, gameCell ->
if (index == position.index) {
@@ -34,4 +33,8 @@ class Game(
fun areRulesViolated(): Boolean = clues
.any { it.isRuleViolated(grid) }
override fun toString(): String {
return grid.toString() + "\n\n" + clues.joinToString("\n* ", prefix = "* ")
}
}

View File

@@ -19,8 +19,9 @@ class Grid(
}
override fun toString(): String {
return rows.map { row -> row.map { it.selection?.symbol ?: " " }.joinToString("") }
.joinToString("\n")
return rows.joinToString("\n") { row ->
row.joinToString("") { it.selection?.symbol ?: " " }
}
}
}

View File

@@ -25,4 +25,36 @@ class OrderClueTest : ClueTest() {
}
}
@Test
fun `ensure items in wrong order are valid`() {
val grid = createGrid()
for (ia in 0 until size) {
for (ib in 0 until size) {
for (ic in 0 until size) {
for (ja in 0 until size - 1) {
for (jb in ja until size) {
val a = grid[ia][ja]
val b = grid[ib][jb]
expect(OrderClue(b.solution, a.solution).isRuleViolated(grid))
.toEqual(true)
}
}
}
}
}
}
@Test
fun `ensure items in the same column are not valid`() {
val grid = createGrid()
for (rowA in grid.rows) {
for (rowB in grid.rows) {
for (i in 0 until size) {
expect(OrderClue(rowA[i].solution, rowB[i].solution).isRuleViolated(grid))
.toEqual(true)
}
}
}
}
}