11package sc.plugin2020
22
3+ import io.kotlintest.matchers.types.shouldNotBeSameInstanceAs
34import io.kotlintest.shouldBe
45import io.kotlintest.specs.StringSpec
56import sc.framework.plugins.Player
@@ -8,16 +9,25 @@ import sc.shared.PlayerColor
89class CloneTest : StringSpec ({
910 " clone Player" {
1011 val player = Player (PlayerColor .RED , "aPlayer")
11- player.clone() shouldBe player
12+ val clone = player.clone()
13+ clone shouldBe player
14+ clone shouldNotBeSameInstanceAs player
1215 }
1316 " clone Board" {
1417 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
1625 }
1726 " clone GameState" {
1827 val state = GameState (blue = Player (PlayerColor .BLUE , "aBluePlayer"), turn = 5)
1928 val clone = state.clone()
2029 clone shouldBe state
30+ clone shouldNotBeSameInstanceAs state
2131 clone.getDeployedPieces(PlayerColor .RED ) shouldBe state.getDeployedPieces(PlayerColor .RED )
2232 }
2333})
0 commit comments