diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index c4460a8..68360de 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -65,13 +65,22 @@ namespace QwirkleClassLibrary return board; } - public void StartGame() + public bool StartGame() { - this.GameRunning = true; + if(players.Count>= 2 && players.Count < 5) + { + this.GameRunning = true; + return true; + } + return false; } public Player GetPlayingPlayer() { + if(GetPlayingPlayerPosition() == -1) + { + throw new ArgumentException(); + } return players[GetPlayingPlayerPosition()]; } @@ -108,8 +117,16 @@ namespace QwirkleClassLibrary public string SetFirstPlayer() { - players[0].IsPlaying = true; - return players[0].NameTag; + if (GameRunning == true) + { + players[0].IsPlaying = true; + return players[0].NameTag; + } + else + { + throw new ArgumentException("Game is not running"); + } + } public string SetNextPlayer() diff --git a/Qwirkle/TestBase/TestBoard.cs b/Qwirkle/TestBase/TestBoard.cs index 1cffe4c..7428165 100644 --- a/Qwirkle/TestBase/TestBoard.cs +++ b/Qwirkle/TestBase/TestBoard.cs @@ -3,36 +3,58 @@ namespace TestBase; public class TestBoard { - - - public static IEnumerable Data_Board() { yield return new object[] { true, - new Cell(0,0), + 1, + 2, new Tile(Shape.Round, Color.Red) }; yield return new object[] { false, - new Cell(0,0), + -5, + 9999, new Tile(Shape.Round, Color.Red) }; } [Theory] [MemberData(nameof(Data_Board))] - public void Test_AddTile(bool except, Cell c, Tile t) + public void Test_BoardAddSolo(bool except, int x, int y, Tile t) { + + Board b = new Board(); + if (!except) { - c.SetTile(t); - Assert.False(c.SetTile(t)); + Assert.False(b.AddTileInCell(x, y, t)); return; + } - Assert.True(c.SetTile(t)); + Assert.True(b.AddTileInCell(x, y, t)); } + + public static IEnumerable Data_BoardDouble() + { + yield return new object[] + { + 1, + 2, + new Tile(Shape.Round, Color.Red) + }; + } + + [Theory] + [MemberData(nameof(Data_BoardDouble))] + public void Test_BoardFree(int x, int y, Tile t) + { + Board board = new Board(); + board.AddTileInCell(x, y, t); + Assert.False(board.AddTileInCell(x,y, t)); + } + } diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs new file mode 100644 index 0000000..121e8de --- /dev/null +++ b/Qwirkle/TestBase/TestGame.cs @@ -0,0 +1,127 @@ +using QwirkleClassLibrary; +namespace TestBase; + +public class TestGame +{ + + + [Theory] + [InlineData(true, false, "testt")] + [InlineData(false, false, "testt")] + public void Test_GameAddPlayerIngame(bool result, bool gamestate, string p) + { + Game game = new Game(); + + if (!result) { + game.AddPlayerInGame(p); + Assert.False(game.AddPlayerInGame(p)); + } + else + { + Assert.True(game.AddPlayerInGame(p)); + } + + if (gamestate) + { + Assert.False(game.AddPlayerInGame(p)); + } + + + + + + } + + [Theory] + [InlineData(false, null)] + [InlineData(true, "test")] + public void Test_GameAddPlayerIngame2(bool result, string p) + { + Game game = new Game(); + + if (!result) + { + Assert.False(game.AddPlayerInGame(p)); + } + + for (int i = 0; i < 4; i++) + { + string name = p + i; + game.AddPlayerInGame(name); + } + Assert.False(game.AddPlayerInGame(p)); + + } + + [Theory] + [InlineData("test")] + public void Test_GameCreatePlayers(string p) + { + Game game = new Game(); + Player player = new Player(p); + Assert.Equal(game.CreatePlayer(p).NameTag, player.NameTag); + } + + [Theory] + [InlineData(true, "test1", "test2")] + [InlineData(false, "test1", "test2")] + public void Test_GameState(bool result, string p1, string p2) + { + Game game = new Game(); + + if (!result) + { + game.StartGame(); + Assert.False(game.GameRunning); + } + game.AddPlayerInGame(p1); + game.AddPlayerInGame(p2); + game.StartGame(); + + Assert.True(game.GameRunning); + } + + + [Theory] + [InlineData(true, "test1", "test2", "test3")] + [InlineData(false, "test1", "test2", "test3")] + public void Test_GameGetPlayingPlayerPosition(bool result, string p1, string p2, string p3) + { + Game game = new Game(); + game.AddPlayerInGame(p1); + game.AddPlayerInGame(p2); + game.AddPlayerInGame(p3); + + if (!result) + { + Assert.Equal(-1, game.GetPlayingPlayerPosition()); + return; + } + game.StartGame(); + game.SetFirstPlayer(); + Assert.Equal(0, game.GetPlayingPlayerPosition()); + } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void Test_GameGetPlaylingPlayer(bool result) + { + Game game = new Game(); + game.AddPlayerInGame("patrick"); + game.AddPlayerInGame("jean"); + if (!result) + { + Assert.Throws(() => game.GetPlayingPlayer()); + } + game.StartGame(); + game.SetFirstPlayer(); + + Assert.Equal(game.PlayerList[0], game.GetPlayingPlayer()); + + } + + + +} +