From c5484d8043be6b47f50d91e253121d11c6af7897 Mon Sep 17 00:00:00 2001 From: Alessandro Mazzoli Date: Wed, 20 Sep 2023 12:48:24 +0200 Subject: [PATCH] chore: refactored test structure --- src/test/scala/scatan/model/TurnTest.scala | 42 +++++++++++++--------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/test/scala/scatan/model/TurnTest.scala b/src/test/scala/scatan/model/TurnTest.scala index 2409d551..4b80caba 100644 --- a/src/test/scala/scatan/model/TurnTest.scala +++ b/src/test/scala/scatan/model/TurnTest.scala @@ -4,33 +4,43 @@ import scatan.BaseTest class TurnTest extends BaseTest: + "A turn" should "have a number" in { + val turn = Turn(1, Player("a")) + turn.number shouldBe 1 + } + + it should "not allow to have a number less than 1" in { + assertThrows[IllegalArgumentException] { + Turn(0, Player("a")) + } + } + + it should "have a player" in { + val turn = Turn(1, Player("a")) + turn.player shouldBe Player("a") + } + +class NewGameTest extends BaseTest: + + val players = Seq(Player("a"), Player("b"), Player("c"), Player("d")) + "A game" should "have a turn" in { - val game = Game(Seq(Player("a"), Player("b"), Player("c"), Player("d"))) - game.currentTurn shouldBe Turn(1, Player("a")) + val game = Game(players) + game.currentTurn shouldBe Turn(1, players(0)) } it should "have a next turn" in { - val game = Game(Seq(Player("a"), Player("b"), Player("c"), Player("d"))) - game.nextTurn.currentTurn shouldBe Turn(2, Player("b")) + val game = Game(players) + game.nextTurn.currentTurn shouldBe Turn(2, players(1)) } it should "do a circular turn" in { - val gameWith4Players = Game(Seq(Player("a"), Player("b"), Player("c"), Player("d"))) + val gameWith4Players = Game(players) val playersTurnIterator = Iterator.iterate(gameWith4Players)(_.nextTurn).map(_.currentPlayer) - val playersIterator = Iterator.continually(Seq(Player("a"), Player("b"), Player("c"), Player("d"))).flatten + val playersIterator = Iterator.continually(players).flatten playersTurnIterator.take(100).toList shouldBe playersIterator.take(100).toList } - "A turn" should "have a number" in { - val turn = Turn(1, Player("a")) - turn.number shouldBe 1 - } - - it should "have a player" in { - val turn = Turn(1, Player("a")) - turn.player shouldBe Player("a") - } - /* it should "have a phase" in { val turn = Turn(1, Player("a"))