@@ -3,8 +3,8 @@ package sc.plugin2022
33import io.kotest.assertions.throwables.shouldThrow
44import io.kotest.core.spec.style.FunSpec
55import io.kotest.inspectors.forAll
6- import io.kotest.matchers.collections.shouldBeOneOf
7- import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
6+ import io.kotest.matchers.booleans.shouldBeFalse
7+ import io.kotest.matchers.collections.*
88import io.kotest.matchers.maps.shouldBeEmpty
99import io.kotest.matchers.maps.shouldHaveSize
1010import io.kotest.matchers.shouldBe
@@ -46,10 +46,11 @@ class BoardTest: FunSpec({
4646 context("Board performs Moves ") {
4747 context("refuses invalid moves") {
4848 test("can't move backwards or off the fields") {
49- val board = Board (arrayOf(Seestern , Herzmuschel ).flatMap { it.teamPieces() }.mapIndexed { index, piece -> Coordinates (index, 4) to piece }.toMap(HashMap ()))
49+ val board = Board (arrayOf(Seestern , Herzmuschel ).flatMap { it.teamPieces() }
50+ .mapIndexed { index, piece -> Coordinates (index, 4) to piece }.toMap(HashMap ()))
5051 board.entries.forAll {
5152 shouldThrow<InvalidMoveException > {
52- board.movePiece(Move (it.key, it.key.copy(y = if(it.value.team == Team .ONE ) 3 else 5)))
53+ board.movePiece(Move (it.key, it.key.copy(y = if (it.value.team == Team .ONE ) 3 else 5)))
5354 }.mistake shouldBe MoveMistake .INVALID_MOVEMENT
5455 }
5556 }
@@ -61,22 +62,18 @@ class BoardTest: FunSpec({
6162 }
6263 }
6364 context("amber") {
64- val coords = Coordinates (0, 6)
6565 test("not for other team") {
66- val moewe = Piece (Moewe , Team .TWO )
67- val board = Board (mutableMapOf(coords to moewe))
66+ val board = makeBoard(0 y 6 to "m")
6867 board.movePiece(Move (0 y 6, 0 y 7)) shouldBe 0
6968 board shouldHaveSize 1
7069 }
71- test("from position") {
72- val moewe = Piece (Moewe , Team .ONE )
73- val board = Board (mutableMapOf(coords to moewe))
70+ test("from position") {
71+ val board = makeBoard(0 y 6 to "M ")
7472 board.movePiece(Move (0 y 6, 0 y 7)) shouldBe 1
7573 board.shouldBeEmpty()
7674 }
7775 test("not from Robbe in position") {
78- val robbe = Piece (Robbe , Team .ONE )
79- val board = Board (mutableMapOf(coords to robbe))
76+ val board = makeBoard(0 y 6 to "R ")
8077 board.movePiece(Move (0 y 6, 2 y 7)) shouldBe 0
8178 board shouldHaveSize 1
8279 }
@@ -96,6 +93,30 @@ class BoardTest: FunSpec({
9693 }
9794 }
9895 }
96+ context("Board calculates diffs") {
97+ val board = makeBoard(0 y 0 to "r", 2 y 0 to "r")
98+ test("empty for itself") {
99+ board.diff(board).shouldBeEmpty()
100+ board.diff(board.clone()).shouldBeEmpty()
101+ board.clone().diff(board).shouldBeEmpty()
102+ }
103+ test("one moved and one unmoved piece") {
104+ val move = Move (0 y 0, 2 y 1)
105+ val newBoard = board.clone()
106+ newBoard.movePiece(move)
107+ board.diff(newBoard) shouldContainExactly listOf(move)
108+ }
109+ test("both pieces moved") {
110+ val newBoard = makeBoard(2 y 1 to "r", 1 y 2 to "r")
111+ board.diff(newBoard) shouldHaveSize 2
112+ }
113+ test("one piece vanished") {
114+ val newBoard = makeBoard(2 y 0 to "r")
115+ val move = board.diff(newBoard).single()
116+ move.start shouldBe (0 y 0)
117+ move.destination.isValid.shouldBeFalse()
118+ }
119+ }
99120})
100121
101122infix fun String.at (pos : Coordinates ) = Pair (pos, Piece .fromString(this ))
0 commit comments