diff options
Diffstat (limited to 'core/src/commonTest/kotlin/coffee/liz')
| -rw-r--r-- | core/src/commonTest/kotlin/coffee/liz/rookery/AlgSetsTest.kt | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/core/src/commonTest/kotlin/coffee/liz/rookery/AlgSetsTest.kt b/core/src/commonTest/kotlin/coffee/liz/rookery/AlgSetsTest.kt new file mode 100644 index 0000000..eadef06 --- /dev/null +++ b/core/src/commonTest/kotlin/coffee/liz/rookery/AlgSetsTest.kt @@ -0,0 +1,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()) + } +} |
