Add tests
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package ch.dissem.yaep.domain
|
||||
|
||||
@Suppress("JavaDefaultMethodsNotOverriddenByDelegation")
|
||||
class GameRow<C : ItemClass<C>>(
|
||||
val category: ItemClassCompanion<C>,
|
||||
val options: List<Item<C>>,
|
||||
@@ -22,12 +21,8 @@ class GameRow<C : ItemClass<C>>(
|
||||
fun indexOf(element: C): Int = indexOfFirst { it.selection?.itemType == element }
|
||||
|
||||
fun cleanupOptions() {
|
||||
if (isSolved && all {
|
||||
it.solution != null
|
||||
&& it.options.size == 1
|
||||
&& it.options.single() == it.selection
|
||||
}
|
||||
) return
|
||||
if (isSolved && all { it.options.size == 1 && it.options.single() == it.selection })
|
||||
return
|
||||
do {
|
||||
var changed = false
|
||||
val selections = filter { it.selection != null }.let { cellsWithSelection ->
|
||||
@@ -58,11 +53,7 @@ class GameRow<C : ItemClass<C>>(
|
||||
}
|
||||
}
|
||||
} while (changed)
|
||||
isSolved = all {
|
||||
it.solution != null
|
||||
&& it.options.size == 1
|
||||
&& it.options.single() == it.selection
|
||||
}
|
||||
isSolved = all { it.options.size == 1 && it.options.single() == it.selection }
|
||||
}
|
||||
|
||||
fun snapshot() {
|
||||
@@ -72,11 +63,7 @@ class GameRow<C : ItemClass<C>>(
|
||||
fun undo(): Boolean {
|
||||
val didChange = cells.map { it.undo() }.reduce { a, b -> a || b }
|
||||
if (didChange) {
|
||||
isSolved = all {
|
||||
it.solution != null
|
||||
&& it.options.size == 1
|
||||
&& it.options.single() == it.selection
|
||||
}
|
||||
isSolved = all { it.options.size == 1 && it.options.single() == it.selection }
|
||||
}
|
||||
return didChange
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user