Add OrderClue tests
This commit is contained in:
@@ -6,10 +6,9 @@ class Game(
|
|||||||
) {
|
) {
|
||||||
val horizontalClues = clues.filterIsInstance<HorizontalClue>()
|
val horizontalClues = clues.filterIsInstance<HorizontalClue>()
|
||||||
val verticalClues = clues.filterIsInstance<SameColumnClue<ItemClass<*>, ItemClass<*>>>()
|
val verticalClues = clues.filterIsInstance<SameColumnClue<ItemClass<*>, ItemClass<*>>>()
|
||||||
val positionalClues = clues.filterIsInstance<PositionClue<ItemClass<*>>>()
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
for (position in positionalClues) {
|
for (position in clues.filterIsInstance<PositionClue<ItemClass<*>>>()) {
|
||||||
val row = grid[position.item.itemType.companion]
|
val row = grid[position.item.itemType.companion]
|
||||||
row.forEachIndexed { index, gameCell ->
|
row.forEachIndexed { index, gameCell ->
|
||||||
if (index == position.index) {
|
if (index == position.index) {
|
||||||
@@ -34,4 +33,8 @@ class Game(
|
|||||||
|
|
||||||
fun areRulesViolated(): Boolean = clues
|
fun areRulesViolated(): Boolean = clues
|
||||||
.any { it.isRuleViolated(grid) }
|
.any { it.isRuleViolated(grid) }
|
||||||
}
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return grid.toString() + "\n\n" + clues.joinToString("\n* ", prefix = "* ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ class Grid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return rows.map { row -> row.map { it.selection?.symbol ?: " " }.joinToString("") }
|
return rows.joinToString("\n") { row ->
|
||||||
.joinToString("\n")
|
row.joinToString("") { it.selection?.symbol ?: " " }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user