-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
...-core/src/test/kotlin/org/piepmeyer/gauguin/difficulty/human/LinesPossiblesSumDualTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.piepmeyer.gauguin.difficulty.human | ||
|
||
import io.kotest.assertions.assertSoftly | ||
import io.kotest.assertions.withClue | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.collections.shouldContainExactly | ||
import io.kotest.matchers.shouldBe | ||
import org.piepmeyer.gauguin.creation.GridBuilder | ||
import org.piepmeyer.gauguin.creation.cage.GridCageType | ||
import org.piepmeyer.gauguin.difficulty.human.strategy.LinesSingleCagePossiblesSumDual | ||
import org.piepmeyer.gauguin.grid.GridCageAction | ||
|
||
class LinesPossiblesSumDualTest : | ||
FunSpec({ | ||
|
||
test("4x4 grid") { | ||
val grid = | ||
GridBuilder(4, 4) | ||
.addSingleCage(3, 3) | ||
.addSingleCage(2, 14) | ||
.addCage( | ||
24, | ||
GridCageAction.ACTION_MULTIPLY, | ||
GridCageType.L_HORIZONTAL_SHORT_RIGHT_BOTTOM, | ||
0, | ||
).addCage( | ||
1, | ||
GridCageAction.ACTION_SUBTRACT, | ||
GridCageType.DOUBLE_VERTICAL, | ||
4, | ||
).addCage( | ||
9, | ||
GridCageAction.ACTION_ADD, | ||
GridCageType.ANGLE_RIGHT_TOP, | ||
5, | ||
).addCage( | ||
8, | ||
GridCageAction.ACTION_MULTIPLY, | ||
GridCageType.TRIPLE_VERTICAL, | ||
7, | ||
).addCage( | ||
3, | ||
GridCageAction.ACTION_DIVIDE, | ||
GridCageType.DOUBLE_HORIZONTAL, | ||
12, | ||
).createGrid() | ||
|
||
grid.cells[0].possibles = setOf(2, 4) | ||
grid.cells[1].possibles = setOf(2, 4) | ||
grid.cells[2].userValue = 1 | ||
grid.cells[3].userValue = 3 | ||
grid.cells[4].possibles = setOf(1, 2, 4) | ||
grid.cells[5].possibles = setOf(2, 4) | ||
grid.cells[6].userValue = 3 | ||
grid.cells[7].possibles = setOf(1, 2) | ||
grid.cells[8].possibles = setOf(1, 2, 3) | ||
grid.cells[9].possibles = setOf(1, 3) | ||
grid.cells[10].userValue = 4 | ||
grid.cells[11].possibles = setOf(1, 2) | ||
grid.cells[12].possibles = setOf(1, 3) | ||
grid.cells[13].possibles = setOf(1, 3) | ||
grid.cells[14].userValue = 2 | ||
grid.cells[15].userValue = 4 | ||
|
||
val solver = LinesSingleCagePossiblesSumDual() | ||
|
||
println(grid) | ||
|
||
// solver should find two possibles and delete one of them for each run | ||
solver.fillCells(grid, PossiblesCache(grid)) shouldBe true | ||
|
||
println(grid) | ||
|
||
assertSoftly { | ||
withClue("cell 4") { | ||
grid.cells[4].possibles shouldContainExactly setOf(2, 4) | ||
} | ||
} | ||
} | ||
}) |
163 changes: 163 additions & 0 deletions
163
.../org/piepmeyer/gauguin/difficulty/human/strategy/RemoveImpossibleCombinationInLineTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package org.piepmeyer.gauguin.difficulty.human.strategy | ||
|
||
import io.kotest.assertions.assertSoftly | ||
import io.kotest.assertions.withClue | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.collections.shouldContainExactly | ||
import io.kotest.matchers.shouldBe | ||
import org.piepmeyer.gauguin.creation.GridBuilder | ||
import org.piepmeyer.gauguin.creation.cage.GridCageType | ||
import org.piepmeyer.gauguin.grid.GridCageAction | ||
|
||
class RemoveImpossibleCombinationInLineTest : | ||
FunSpec({ | ||
|
||
test("4x4 grid") { | ||
val grid = | ||
GridBuilder(4, 4) | ||
.addSingleCage(1, 3) | ||
.addSingleCage(4, 10) | ||
.addCage( | ||
24, | ||
GridCageAction.ACTION_MULTIPLY, | ||
GridCageType.TRIPLE_HORIZONTAL, | ||
0, | ||
).addCage( | ||
24, | ||
GridCageAction.ACTION_MULTIPLY, | ||
GridCageType.L_VERTICAL_SHORT_RIGHT_TOP, | ||
4, | ||
).addCage( | ||
8, | ||
GridCageAction.ACTION_ADD, | ||
GridCageType.ANGLE_LEFT_BOTTOM, | ||
6, | ||
).addCage( | ||
2, | ||
GridCageAction.ACTION_DIVIDE, | ||
GridCageType.DOUBLE_VERTICAL, | ||
9, | ||
).addCage( | ||
1, | ||
GridCageAction.ACTION_SUBTRACT, | ||
GridCageType.DOUBLE_HORIZONTAL, | ||
14, | ||
).createGrid() | ||
|
||
grid.cells[0].possibles = setOf(3, 4) | ||
grid.cells[1].possibles = setOf(3, 4) | ||
grid.cells[2].userValue = 2 | ||
grid.cells[3].userValue = 1 | ||
grid.cells[4].possibles = setOf(1, 2, 3, 4) | ||
grid.cells[5].possibles = setOf(3, 4) | ||
grid.cells[6].possibles = setOf(1, 3) | ||
grid.cells[7].possibles = setOf(2, 4) | ||
grid.cells[8].possibles = setOf(1, 2) | ||
grid.cells[9].possibles = setOf(1, 2) | ||
grid.cells[10].userValue = 4 | ||
grid.cells[11].userValue = 3 | ||
grid.cells[12].possibles = setOf(1, 2, 3, 4) | ||
grid.cells[13].possibles = setOf(1, 2) | ||
grid.cells[14].possibles = setOf(1, 3) | ||
grid.cells[15].possibles = setOf(2, 4) | ||
|
||
val solver = RemoveImpossibleCombinationInLineBecauseOfSingleCell() | ||
|
||
println(grid) | ||
|
||
// solver should find two possibles and delete one of them for each run | ||
solver.fillCellsWithNewCache(grid) shouldBe true | ||
|
||
println(grid) | ||
|
||
assertSoftly { | ||
withClue("cell 14") { | ||
grid.cells[14].possibles shouldContainExactly setOf(3) | ||
} | ||
} | ||
} | ||
|
||
test("4x4 grid impossible combinations") { | ||
val grid = | ||
GridBuilder(4, 4) | ||
.addSingleCage(2, 3) | ||
.addSingleCage(1, 13) | ||
.addCage( | ||
3, | ||
GridCageAction.ACTION_DIVIDE, | ||
GridCageType.DOUBLE_VERTICAL, | ||
0, | ||
).addCage( | ||
9, | ||
GridCageAction.ACTION_ADD, | ||
GridCageType.ANGLE_LEFT_BOTTOM, | ||
1, | ||
).addCage( | ||
6, | ||
GridCageAction.ACTION_MULTIPLY, | ||
GridCageType.DOUBLE_VERTICAL, | ||
5, | ||
).addCage( | ||
8, | ||
GridCageAction.ACTION_ADD, | ||
GridCageType.TRIPLE_VERTICAL, | ||
7, | ||
).addCage( | ||
2, | ||
GridCageAction.ACTION_DIVIDE, | ||
GridCageType.DOUBLE_VERTICAL, | ||
8, | ||
).addCage( | ||
1, | ||
GridCageAction.ACTION_SUBTRACT, | ||
GridCageType.DOUBLE_VERTICAL, | ||
10, | ||
).createGrid() | ||
|
||
grid.cells[0].possibles = setOf(1, 3) | ||
grid.cells[1].userValue = 4 | ||
grid.cells[2].possibles = setOf(1, 3) | ||
grid.cells[3].userValue = 2 | ||
grid.cells[4].possibles = setOf(1, 3) | ||
grid.cells[5].possibles = setOf(2, 3) | ||
grid.cells[6].possibles = setOf(2, 4) | ||
grid.cells[7].possibles = setOf(1, 3, 4) | ||
grid.cells[8].possibles = setOf(2, 4) | ||
grid.cells[9].possibles = setOf(2, 3) | ||
grid.cells[10].possibles = setOf(1, 2, 3, 4) | ||
grid.cells[11].possibles = setOf(1, 3, 4) | ||
grid.cells[12].possibles = setOf(2, 4) | ||
grid.cells[13].userValue = 1 | ||
grid.cells[14].possibles = setOf(2, 3, 4) | ||
grid.cells[15].possibles = setOf(3, 4) | ||
|
||
val solver = RemoveImpossibleCombinationInLineBecauseOfPossiblesOfOtherCage() | ||
|
||
println(grid) | ||
|
||
// solver should find all five possibles in column three | ||
solver.fillCellsWithNewCache(grid) shouldBe true | ||
solver.fillCellsWithNewCache(grid) shouldBe true | ||
// solver.fillCellsWithNewCache(grid) shouldBe true | ||
// solver.fillCellsWithNewCache(grid) shouldBe true | ||
// solver.fillCellsWithNewCache(grid) shouldBe true | ||
// solver.fillCellsWithNewCache(grid) shouldBe false | ||
|
||
println(grid) | ||
|
||
assertSoftly { | ||
withClue("cell 2") { | ||
grid.cells[2].possibles shouldContainExactly setOf(1) | ||
} | ||
withClue("cell 6") { | ||
grid.cells[6].possibles shouldContainExactly setOf(4) | ||
} | ||
withClue("cell 10") { | ||
grid.cells[10].possibles shouldContainExactly setOf(2, 3) | ||
} | ||
withClue("cell 14") { | ||
grid.cells[14].possibles shouldContainExactly setOf(2, 3) | ||
} | ||
} | ||
} | ||
}) |