1
1
package sc.plugin2020
2
2
3
+ import io.kotlintest.matchers.types.shouldNotBeSameInstanceAs
3
4
import io.kotlintest.shouldBe
4
5
import io.kotlintest.specs.StringSpec
5
6
import sc.framework.plugins.Player
@@ -8,16 +9,25 @@ import sc.shared.PlayerColor
8
9
class CloneTest : StringSpec ({
9
10
" clone Player" {
10
11
val player = Player (PlayerColor .RED , "aPlayer")
11
- player.clone() shouldBe player
12
+ val clone = player.clone()
13
+ clone shouldBe player
14
+ clone shouldNotBeSameInstanceAs player
12
15
}
13
16
" clone Board" {
14
17
val board = Board ()
15
- board.clone() shouldBe board
18
+ board.getField(0, 0, 0).pieces.add(Piece (PlayerColor .RED , PieceType .BEETLE ))
19
+ val clone = board.clone()
20
+ clone shouldBe board
21
+ clone shouldNotBeSameInstanceAs board
22
+ clone.getField(0, 0, 0) shouldNotBeSameInstanceAs board.getField(0, 0, 0)
23
+ // note that the individual pieces are immutable and don't need to be cloned, only the stack which holds them
24
+ clone.getField(0, 0, 0).pieces shouldNotBeSameInstanceAs board.getField(0, 0, 0).pieces
16
25
}
17
26
" clone GameState" {
18
27
val state = GameState (blue = Player (PlayerColor .BLUE , "aBluePlayer"), turn = 5)
19
28
val clone = state.clone()
20
29
clone shouldBe state
30
+ clone shouldNotBeSameInstanceAs state
21
31
clone.getDeployedPieces(PlayerColor .RED ) shouldBe state.getDeployedPieces(PlayerColor .RED )
22
32
}
23
33
})
0 commit comments