@@ -3,8 +3,8 @@ package sc.plugin2022
3
3
import io.kotest.assertions.throwables.shouldThrow
4
4
import io.kotest.core.spec.style.FunSpec
5
5
import 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.*
8
8
import io.kotest.matchers.maps.shouldBeEmpty
9
9
import io.kotest.matchers.maps.shouldHaveSize
10
10
import io.kotest.matchers.shouldBe
@@ -46,10 +46,11 @@ class BoardTest: FunSpec({
46
46
context("Board performs Moves ") {
47
47
context("refuses invalid moves") {
48
48
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 ()))
50
51
board.entries.forAll {
51
52
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)))
53
54
}.mistake shouldBe MoveMistake .INVALID_MOVEMENT
54
55
}
55
56
}
@@ -61,22 +62,18 @@ class BoardTest: FunSpec({
61
62
}
62
63
}
63
64
context("amber") {
64
- val coords = Coordinates (0, 6)
65
65
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")
68
67
board.movePiece(Move (0 y 6, 0 y 7)) shouldBe 0
69
68
board shouldHaveSize 1
70
69
}
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 ")
74
72
board.movePiece(Move (0 y 6, 0 y 7)) shouldBe 1
75
73
board.shouldBeEmpty()
76
74
}
77
75
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 ")
80
77
board.movePiece(Move (0 y 6, 2 y 7)) shouldBe 0
81
78
board shouldHaveSize 1
82
79
}
@@ -96,6 +93,30 @@ class BoardTest: FunSpec({
96
93
}
97
94
}
98
95
}
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
+ }
99
120
})
100
121
101
122
infix fun String.at (pos : Coordinates ) = Pair (pos, Piece .fromString(this ))
0 commit comments