Add tests
This commit is contained in:
@@ -1,36 +1,94 @@
|
||||
package domain
|
||||
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.feature
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.size
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toBeLessThan
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
|
||||
import ch.tutteli.atrium.api.fluent.en_GB.toHaveSize
|
||||
import ch.tutteli.atrium.api.verbs.expect
|
||||
import domain.Item
|
||||
import kotlin.test.Test
|
||||
|
||||
class NeighbourClueTest {
|
||||
class NeighbourClueTest : ClueTest() {
|
||||
|
||||
@Test
|
||||
fun `ensure actual neighbours are valid`() {
|
||||
val size = 5
|
||||
val grid = ItemClass.randomClasses(size)
|
||||
.map {
|
||||
it.randomItems(size).map { item -> Item(item) }
|
||||
}
|
||||
.map { row ->
|
||||
GameRow(
|
||||
category = row.first().itemType.companion,
|
||||
options = row,
|
||||
cells = row.map {
|
||||
GameCell(
|
||||
selection = it,
|
||||
solution = it,
|
||||
options = mutableListOf()
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
val grid = createGrid()
|
||||
for (ia in 0 until size) {
|
||||
for (ib in 0 until size) {
|
||||
for (j in 1 until size) {
|
||||
val a = grid[ia][j - 1]
|
||||
val b = grid[ib][j]
|
||||
|
||||
NeighbourClue(Item(Animals.ANT), Item(Profession.ASTRONAUT))
|
||||
expect(NeighbourClue(a.solution, b.solution).isRuleViolated(grid))
|
||||
.toEqual(false)
|
||||
expect(NeighbourClue(b.solution, a.solution).isRuleViolated(grid))
|
||||
.toEqual(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure non-neighbours are invalid`() {
|
||||
val grid = createGrid()
|
||||
for (ia in 0 until size) {
|
||||
for (ib in 0 until size) {
|
||||
for (ja in 0 until size) {
|
||||
for (jb in 0 until size) {
|
||||
if (ja == jb + 1 || ja == jb - 1) {
|
||||
continue
|
||||
}
|
||||
val a = grid[ia][ja]
|
||||
val b = grid[ib][jb]
|
||||
|
||||
expect(NeighbourClue(a.solution, b.solution).isRuleViolated(grid))
|
||||
.toEqual(true)
|
||||
expect(NeighbourClue(b.solution, a.solution).isRuleViolated(grid))
|
||||
.toEqual(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure grid with one neighbour not set is considered valid`() {
|
||||
val grid = createGrid()
|
||||
for (ia in 0 until size) {
|
||||
for (ib in 0 until size) {
|
||||
for (j in 1 until size) {
|
||||
val a = grid[ia][j - 1]
|
||||
val b = grid[ib][j]
|
||||
|
||||
a.selection = null
|
||||
b.selection = b.solution
|
||||
|
||||
expect(NeighbourClue(a.solution, b.solution).isRuleViolated(grid))
|
||||
.toEqual(false)
|
||||
expect(NeighbourClue(b.solution, a.solution).isRuleViolated(grid))
|
||||
.toEqual(false)
|
||||
|
||||
a.selection = a.solution
|
||||
b.selection = null
|
||||
|
||||
expect(NeighbourClue(a.solution, b.solution).isRuleViolated(grid))
|
||||
.toEqual(false)
|
||||
expect(NeighbourClue(b.solution, a.solution).isRuleViolated(grid))
|
||||
.toEqual(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure grid with a and c more than one cell between is not considered valid`() {
|
||||
val grid = createGrid { null }
|
||||
val a = grid[2][1]
|
||||
val b = grid[0][2]
|
||||
|
||||
a.selection = a.solution
|
||||
grid[0][3].selection = b.solution
|
||||
|
||||
expect(NeighbourClue(a.solution, b.solution).isRuleViolated(grid))
|
||||
.toEqual(true)
|
||||
expect(NeighbourClue(b.solution, a.solution).isRuleViolated(grid))
|
||||
.toEqual(true)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user