diff --git a/domain/src/main/kotlin/ch/dissem/yaep/domain/Game.kt b/domain/src/main/kotlin/ch/dissem/yaep/domain/Game.kt index 7ef6422..89adbcc 100644 --- a/domain/src/main/kotlin/ch/dissem/yaep/domain/Game.kt +++ b/domain/src/main/kotlin/ch/dissem/yaep/domain/Game.kt @@ -6,10 +6,9 @@ class Game( ) { val horizontalClues = clues.filterIsInstance() val verticalClues = clues.filterIsInstance, ItemClass<*>>>() - val positionalClues = clues.filterIsInstance>>() init { - for (position in positionalClues) { + for (position in clues.filterIsInstance>>()) { 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) } -} \ No newline at end of file + + override fun toString(): String { + return grid.toString() + "\n\n" + clues.joinToString("\n* ", prefix = "* ") + } +} diff --git a/domain/src/main/kotlin/ch/dissem/yaep/domain/Grid.kt b/domain/src/main/kotlin/ch/dissem/yaep/domain/Grid.kt index 1349a5c..895b6a8 100644 --- a/domain/src/main/kotlin/ch/dissem/yaep/domain/Grid.kt +++ b/domain/src/main/kotlin/ch/dissem/yaep/domain/Grid.kt @@ -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 ?: " " } + } } } diff --git a/domain/src/test/kotlin/ch/dissem/yaep/domain/OrderClueTest.kt b/domain/src/test/kotlin/ch/dissem/yaep/domain/OrderClueTest.kt index e94a775..d2b8df8 100644 --- a/domain/src/test/kotlin/ch/dissem/yaep/domain/OrderClueTest.kt +++ b/domain/src/test/kotlin/ch/dissem/yaep/domain/OrderClueTest.kt @@ -25,4 +25,36 @@ class OrderClueTest : ClueTest() { } } -} \ No newline at end of file + @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) + } + } + } + } +}