1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package coffee.liz.rookery
import coffee.liz.rookery.algs.AlgCase
import coffee.liz.rookery.algs.AlgSets
import coffee.liz.rookery.puzzle.NxnCube
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class AlgSetsTest {
private fun f2lSolved(c: NxnCube) = (1..5).all { f -> f == 3 || (3 until 9).all { c.stickers[f * 9 + it] == f } } && (0 until 9).all { c.stickers[3 * 9 + it] == 3 }
private fun topOriented(c: NxnCube) = (0 until 9).all { c.stickers[it] == 0 }
@Test fun setsAreComplete() {
assertEquals(21, AlgSets.cases("pll").size)
assertEquals(57, AlgSets.cases("oll").size)
}
@Test fun everyAlgorithmSolvesItsOwnCase() {
for (set in AlgSets.names) for (case in AlgSets.cases(set)) for (alg in case.algs) {
val state = case.state(alg)
assertTrue(f2lSolved(state), "${case.id}: '$alg' disturbs the first two layers")
if (set == "pll") assertTrue(topOriented(state), "${case.id}: '$alg' is not a pure permutation")
if (set == "oll") assertTrue(!topOriented(state), "${case.id}: '$alg' does nothing to orientation")
// doing the algorithm on its own setup returns a solved cube (possibly held differently)
val done = NxnCube(3).apply(case.setup(alg)).apply(AlgCase.clean(alg))
assertTrue((0 until 6).all { f -> (0 until 9).all { done.stickers[f * 9 + it] == done.stickers[f * 9 + 4] } }, "${case.id}: setup then '$alg' is not solved")
}
}
@Test fun planPutsFrontAtTheBottom() {
val p = AlgSets.plan(NxnCube(3))
assertEquals(listOf(-1, 5, 5, 5, -1), p[0].toList())
assertEquals(listOf(4, 0, 0, 0, 1), p[2].toList())
assertEquals(listOf(-1, 2, 2, 2, -1), p[4].toList())
}
}
|