public void ShootAt_ShouldReturnHitWhenAShipIsHit() { //Arrange var playerBuilder = new PlayerBuilder(); playerBuilder.GridMock.Setup(g => g.Shoot(It.IsAny <GridCoordinate>())).Returns((GridCoordinate c) => new GridSquare(c) { Status = GridSquareStatus.Hit }); var kind = ShipKind.All.NextRandomElement(); IShip hitShip = new ShipBuilder(kind).Build(); playerBuilder.FleetMock.Setup(f => f.FindShipAtCoordinate(It.IsAny <GridCoordinate>())).Returns(hitShip); IPlayer opponent = playerBuilder.Build(); GridCoordinate coordinate = new GridCoordinateBuilder().Build(); _humanPlayer.ReloadBombs(); //Act var result = _humanPlayer.ShootAt(opponent, coordinate); //Assert playerBuilder.GridMock.Verify(g => g.Shoot(coordinate), Times.Once, "The Shoot method of the opponent grid should have been called."); Assert.That(result.ShotFired, Is.True, "The result should indicate that the shot was fired."); Assert.That(result.Hit, Is.True, "The result should indicate that it was a hit."); playerBuilder.FleetMock.Verify(f => f.FindShipAtCoordinate(coordinate), Times.Once, "Use the FindShipAtCoordinate of the opponent fleet to determine which kind of ship was hit."); }
public void ShootAutomatically_ShouldUseTheShootingStrategyToShoot() { //Arrange _computerPlayer.ReloadBombs(); var playerBuilder = new PlayerBuilder(); IPlayer opponent = playerBuilder.Build(); GridCoordinate determinedCoordinate = new GridCoordinateBuilder().Build(); _shootingStrategyMock.Setup(ss => ss.DetermineTargetCoordinate()).Returns(determinedCoordinate); //Act _computerPlayer.ShootAutomatically(opponent); //Assert _shootingStrategyMock.Verify(ss => ss.DetermineTargetCoordinate(), "Use the DetermineTargetCoordinate method of the shooting strategy."); var opponentGridMock = playerBuilder.GridMock; opponentGridMock.Verify(g => g.Shoot(determinedCoordinate), Times.AtLeastOnce, "Use the ShootAt method to shoot at the opponent on the coordinate determined by the strategy."); _shootingStrategyMock.Verify(ss => ss.RegisterShotResult(It.IsAny <GridCoordinate>(), It.IsAny <ShotResult>()), "After shooting, the result should be registered with the shooting strategy."); }
public void PlayNextAddsToCorrespondingSuiteWithFollowingCardOnTop() { const Suite suite = Suite.Blue; var cardToPlay = new Card(suite, Number.Two); var playedPile = new Mock <IPile>(); playedPile .Setup(p => p.Top) .Returns(new Card(suite, Number.One)); var playerBuilder = new PlayerBuilder { Cards = cardToPlay.AsEnumerable(), TableBuilder = new TableBuilder { PlayedCards = new Dictionary <Suite, IPile> { [suite] = playedPile.Object, }, }, }; var player = playerBuilder.Build(); player.Play(cardToPlay); playedPile.Verify(p => p.Add(cardToPlay), Times.Once); }
public void PlayFiveReplenishesInformationToken() { const Suite suite = Suite.Blue; var informationTokens = new Mock <ITokens>(); var playedPile = new Mock <IPile>(); playedPile .Setup(p => p.Top) .Returns(new Card(suite, Number.Four)); var playerBuilder = new PlayerBuilder { Cards = new Card(suite, Number.Five).AsEnumerable(), TableBuilder = new TableBuilder { InformationTokens = informationTokens.Object, PlayedCards = new Dictionary <Suite, IPile> { [suite] = playedPile.Object, }, }, }; var player = playerBuilder.Build(); player.Play(player.Cards.First()); informationTokens.Verify(t => t.Replenish(), Times.Once); }
public void PlayMovesFromTopOfDeckToBeginningOfHand(int cardIndexToPlay) { var newCard = new Card(Suite.Red, Number.One); var deck = new Mock <IDeck>(); deck .Setup(d => d.Draw()) .Returns(newCard); var playerBuilder = new PlayerBuilder { TableBuilder = new TableBuilder { Deck = deck.Object, }, }; var player = playerBuilder.Build(); var oldCards = player.Cards .ExceptAt(cardIndexToPlay) .ToList(); player.Play(player.Cards[cardIndexToPlay]); var newCards = newCard.AsEnumerable(); var expectedCards = Enumerable.Concat(newCards, oldCards); player.Cards.Should().Equal(expectedCards); }
public void GiveInformationWithSuiteCallsReceiveInformation() { var ownedCard = new Card(Suite.White, Number.One); var informationTokens = new Mock <ITokens>(MockBehavior.Strict); informationTokens .Setup(t => t.Amount) .Returns(1); informationTokens .Setup(t => t.Use()); var playerBuilder = new PlayerBuilder { TableBuilder = new TableBuilder { InformationTokens = informationTokens.Object, }, }; var player = playerBuilder.Build(); var otherPlayer = new Mock <IInformationReceiverReadOnlyPlayer>(MockBehavior.Strict); otherPlayer .Setup(p => p.Cards) .Returns(new List <Card> { ownedCard }); otherPlayer .Setup(p => p.Information[ownedCard]) .Returns(new Information()); otherPlayer .Setup(p => p.ReceiveInformation(ownedCard.Suite)); player.GiveInformation(otherPlayer.Object, ownedCard.Suite); otherPlayer.Verify(p => p.ReceiveInformation(ownedCard.Suite), Times.Once); }
public void BuildShouldReturnPlayerInstance() { var playerBuilder = new PlayerBuilder(randomNumber); var player = playerBuilder.Build(); Assert.That(player, Is.Not.Null); }
public void Setup() { _settings = new GameSettingsBuilder().Build(); _player1Builder = new PlayerBuilder().WithFleetPositionedOnGrid(true); _player1 = _player1Builder.Build(); _player2Builder = new PlayerBuilder().WithFleetPositionedOnGrid(true); _player2 = _player2Builder.Build(); _game = new Game(_settings, _player1, _player2); }
public void TestRankFrequency() { const string testcase0 = "player1 10D 10H 10S QH QS"; var builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase0))); var player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("player1", player.Name); Assert.IsFalse(player.Flush); var rankFrequencyExpected = new List <int>(new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2, 0, 0 }); var sortedRankFrequencyExpected = new List <Tuple <int, int> >(new Tuple <int, int>[] { new Tuple <int, int>(3, 8), new Tuple <int, int>(2, 10) }); Assert.IsTrue(Enumerable.SequenceEqual(rankFrequencyExpected, player.RankFrequency)); Assert.IsTrue(Enumerable.SequenceEqual(sortedRankFrequencyExpected, player.SortedRankFrequency)); const string testcase1 = "player1 10D 9H 10S QH QS"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase1))); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("player1", player.Name); Assert.IsFalse(player.Flush); rankFrequencyExpected = new List <int>(new int[] { 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 0, 0 }); sortedRankFrequencyExpected = new List <Tuple <int, int> >(new Tuple <int, int>[] { new Tuple <int, int>(2, 10), new Tuple <int, int>(2, 8), new Tuple <int, int>(1, 7), }); Assert.IsTrue(Enumerable.SequenceEqual(rankFrequencyExpected, player.RankFrequency)); Assert.IsTrue(Enumerable.SequenceEqual(sortedRankFrequencyExpected, player.SortedRankFrequency)); const string testcase2 = "player1 10D 9H 9S QH QS"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase2))); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("player1", player.Name); Assert.IsFalse(player.Flush); rankFrequencyExpected = new List <int>(new int[] { 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 2, 0, 0 }); sortedRankFrequencyExpected = new List <Tuple <int, int> >(new Tuple <int, int>[] { new Tuple <int, int>(2, 10), new Tuple <int, int>(2, 7), new Tuple <int, int>(1, 8) }); Assert.IsTrue(Enumerable.SequenceEqual(rankFrequencyExpected, player.RankFrequency)); Assert.IsTrue(Enumerable.SequenceEqual(sortedRankFrequencyExpected, player.SortedRankFrequency)); const string testcase3 = "player1 2D 9D QD QD QD"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase3))); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("player1", player.Name); Assert.IsTrue(player.Flush); rankFrequencyExpected = new List <int>(new int[] { 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 3, 0, 0 }); sortedRankFrequencyExpected = new List <Tuple <int, int> >(new Tuple <int, int>[] { new Tuple <int, int>(3, 10), new Tuple <int, int>(1, 7), new Tuple <int, int>(1, 0) }); Assert.IsTrue(Enumerable.SequenceEqual(rankFrequencyExpected, player.RankFrequency)); Assert.IsTrue(Enumerable.SequenceEqual(sortedRankFrequencyExpected, player.SortedRankFrequency)); }
public void MultiCompareTest() { const string testcase0 = "Player1 8H 8C 8D QH QC\r\nplayer2 8H 8C 8D QH QC"; var builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase0))); Assert.AreEqual(0, RuleUtils.MultiCompare(builder.Build(), builder.Build())); const string testcase1 = "Player1 8H 8C 8D QH KC\r\nplayer2 8H 8C 8D QH QC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase1))); Assert.AreEqual(1, RuleUtils.MultiCompare(builder.Build(), builder.Build())); const string testcase2 = "Player1 6H 8C 8D QH QC\r\nplayer2 7H 8C 8D QH QC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase2))); Assert.AreEqual(-1, RuleUtils.MultiCompare(builder.Build(), builder.Build())); const string testcase3 = "Player1 6H 8C 8D QH QC\r\nplayer2 5H 8C 8D QH QC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase3))); Assert.AreEqual(1, RuleUtils.MultiCompare(builder.Build(), builder.Build())); const string testcase4 = "Player1 6H 6C 6D 6H QC\r\nplayer2 7H 7C 7D 7H QC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase4))); Assert.AreEqual(-1, RuleUtils.MultiCompare(builder.Build(), builder.Build())); const string testcase5 = "Player1 6H 6C 6D 6H QC\r\nplayer2 6H 6C 6D 6H QC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase5))); Assert.AreEqual(0, RuleUtils.MultiCompare(builder.Build(), builder.Build())); const string testcase6 = "Player1 6H 6C 6D 6H QC\r\nplayer2 6H 6C 6D 6H KC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase6))); Assert.AreEqual(-1, RuleUtils.MultiCompare(builder.Build(), builder.Build())); const string testcase7 = "Player1 8H 7C 9D KH KC\r\nplayer2 7D 6C 5H KS KH"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase7))); Assert.AreEqual(1, RuleUtils.MultiCompare(builder.Build(), builder.Build())); }
public void HighCardCompareTest() { const string testcase0 = "Player1 8H 8C 8D QH QC\r\nplayer2 8H 8C 8D QH QC"; var builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase0))); Assert.AreEqual(0, RuleUtils.HighCardCompare(builder.Build(), builder.Build())); const string testcase1 = "Player1 7H 8C 9D 10H JC\r\nplayer2 7H 8C 9D 10H JC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase1))); Assert.AreEqual(0, RuleUtils.HighCardCompare(builder.Build(), builder.Build())); const string testcase2 = "Player1 7H 8C 9D 10H JC\r\nplayer2 6H 8C 9D 10H JC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase2))); Assert.AreEqual(1, RuleUtils.HighCardCompare(builder.Build(), builder.Build())); const string testcase3 = "Player1 6H 8C 9D 10H JC\r\nplayer2 7H 8C 9D 10H JC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase3))); Assert.AreEqual(-1, RuleUtils.HighCardCompare(builder.Build(), builder.Build())); const string testcase4 = "Player1 7H 9C 9D 10H JC\r\nplayer2 7H 8C 9D 10H JC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase4))); Assert.AreEqual(1, RuleUtils.HighCardCompare(builder.Build(), builder.Build())); const string testcase5 = "Player1 7H 9C 9D 10H JC\r\nplayer2 7H 8C 10D 10H JC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase5))); Assert.AreEqual(-1, RuleUtils.HighCardCompare(builder.Build(), builder.Build())); const string testcase6 = "Player1 7H 9C 10D 10H JC\r\nplayer2 7H 8C 9D 10H QC"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase6))); Assert.AreEqual(-1, RuleUtils.HighCardCompare(builder.Build(), builder.Build())); const string testcase7 = "Player1 7H 9C 10D 10H 10C\r\nplayer2 7H 8C 9D 10H 10C"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase7))); Assert.AreEqual(1, RuleUtils.HighCardCompare(builder.Build(), builder.Build())); }
public void TestProperties([Values] PlayerType type, [Values("a", "b", "c")] string name) { var builder = new PlayerBuilder { Color = Colors.Beige, Name = name, SelectedPlayerType = type }; var player = builder.Build(); Assert.AreEqual(player.Color, Colors.Beige); Assert.AreEqual(player.Name, name); Assert.AreEqual(player.Type, type); }
public void DiscardReplenishesInformationToken() { var informationTokens = new Mock <ITokens>(); var playerBuilder = new PlayerBuilder { TableBuilder = new TableBuilder { InformationTokens = informationTokens.Object, }, }; var player = playerBuilder.Build(); player.Discard(player.Cards.First()); informationTokens.Verify(t => t.Replenish(), Times.Once); }
public void Setup() { try { _settings = new GameSettingsBuilder().Build(); _player1Builder = new PlayerBuilder().WithFleetPositionedOnGrid(true); _player1 = _player1Builder.Build(); _player2Builder = new PlayerBuilder().WithFleetPositionedOnGrid(true); _player2 = _player2Builder.Build(); _game = new Game(_settings, _player1, _player2); } catch (Exception) { Debug.WriteLine("Setup of GameTests failed"); } }
public void DiscardAddsCardToDiscardPile() { var discardPile = new Mock <IPile>(); var playerBuilder = new PlayerBuilder { TableBuilder = new TableBuilder { DiscardPile = discardPile.Object, }, }; var player = playerBuilder.Build(); player.Discard(player.Cards.First()); discardPile.Verify(p => p.Add(It.IsAny <Card>()), Times.Once); }
public void ShootAt_ShouldResultInHasBombsLoadedBeingFalse() { //Arrange var playerBuilder = new PlayerBuilder(); IPlayer opponent = playerBuilder.Build(); GridCoordinate coordinate = new GridCoordinateBuilder().Build(); _humanPlayer.ReloadBombs(); //Act _humanPlayer.ShootAt(opponent, coordinate); //Assert playerBuilder.GridMock.Verify(g => g.Shoot(coordinate), Times.Once, "The Shoot method of the opponent grid should have been called."); Assert.That(_humanPlayer.HasBombsLoaded, Is.False); }
public void ShootAt_ShouldReturnMissedWhenTheShotIsAMiss() { //Arrange var playerBuilder = new PlayerBuilder(); IPlayer opponent = playerBuilder.Build(); GridCoordinate coordinate = new GridCoordinateBuilder().Build(); _humanPlayer.ReloadBombs(); //Act var result = _humanPlayer.ShootAt(opponent, coordinate); //Assert playerBuilder.GridMock.Verify(g => g.Shoot(coordinate), Times.Once, "The Shoot method of the opponent grid should have been called."); Assert.That(result.ShotFired, Is.True, "The result should indicate that the shot was fired."); Assert.That(result.Hit, Is.False, "The result should indicate that it was not a hit."); }
public void CanNotGiveInformationForNumberWithNoInformationTokens() { var informationTokens = new Mock <ITokens>(MockBehavior.Strict); informationTokens .Setup(t => t.Amount) .Returns(0); var playerBuilder = new PlayerBuilder { TableBuilder = new TableBuilder { InformationTokens = informationTokens.Object, }, }; var player = playerBuilder.Build(); var otherPlayer = new Mock <IPlayer>(MockBehavior.Strict); player.CanGiveInformation(otherPlayer.Object, Number.One).Should().BeFalse(); }
public void PlayDrawsFromDeck() { var deck = new Mock <IDeck>(); deck .Setup(d => d.Draw()) .Returns(new Card(Suite.Red, Number.One)); var playerBuilder = new PlayerBuilder { TableBuilder = new TableBuilder { Deck = deck.Object, }, }; var player = playerBuilder.Build(); player.Play(player.Cards.First()); deck.Verify(d => d.Draw(), Times.Once); }
public void PlayAddsEmptyInformationForDrawnCard() { var newCard = new Card(Suite.Red, Number.One); var deck = new Mock <IDeck>(); deck .Setup(d => d.Draw()) .Returns(newCard); var playerBuilder = new PlayerBuilder { TableBuilder = new TableBuilder { Deck = deck.Object, }, }; var player = playerBuilder.Build(); player.Play(player.Cards.First()); player.Information.Keys.Should().Contain(newCard); }
public void GiveInformationWithSuiteThrowsForNoInformationToken() { var informationTokens = new Mock <ITokens>(MockBehavior.Strict); informationTokens .Setup(t => t.Amount) .Returns(0); var playerBuilder = new PlayerBuilder { TableBuilder = new TableBuilder { InformationTokens = informationTokens.Object, }, }; var player = playerBuilder.Build(); var otherPlayer = new Mock <IInformationReceiverReadOnlyPlayer>(MockBehavior.Strict); player .Invoking(p => p.GiveInformation(otherPlayer.Object, Suite.White)) .Should() .Throw <InvalidOperationException>(); }
public void PlayWrongNumberGivesFuseTokenAndDiscardsCard(Number playedNumber, Number?lastNumber) { // TODO Split complex tests! const Suite suite = Suite.Blue; var cardToPlay = new Card(suite, playedNumber); var discardPile = new Mock <IPile>(); var fuseTokens = new Mock <ITokens>(); var topCardPlayed = lastNumber.HasValue ? new Card(suite, lastNumber.Value) : null; var playedPile = new Mock <IPile>(); playedPile .Setup(p => p.Top) .Returns(topCardPlayed); var playerBuilder = new PlayerBuilder { Cards = cardToPlay.AsEnumerable(), TableBuilder = new TableBuilder { DiscardPile = discardPile.Object, FuseTokens = fuseTokens.Object, PlayedCards = new Dictionary <Suite, IPile> { [suite] = playedPile.Object, }, }, }; var player = playerBuilder.Build(); player.Play(cardToPlay); playedPile.Verify(p => p.Add(It.IsAny <Card>()), Times.Never); fuseTokens.Verify(t => t.Replenish(), Times.Once); discardPile.Verify(p => p.Add(cardToPlay), Times.Once); }
public void GivenWithoutAnyResources() { _player = _playerBuilder.Build(); }
public void TestPlayerBuilder() { const string testcase0 = ""; var builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase0))); Assert.IsNull(builder.Build()); const string testcase1 = "player1 AH"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase1))); var ex = Assert.ThrowsException <Exception>(() => builder.Build()); Assert.AreEqual(ex.Message, "Invalid player format"); const string testcase2 = "player1 AH KH QH JH"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase2))); ex = Assert.ThrowsException <Exception>(() => builder.Build()); Assert.AreEqual(ex.Message, "Invalid player format"); const string testcase3 = "player1 AH KH QH JH 10a"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase3))); ex = Assert.ThrowsException <Exception>(() => builder.Build()); Assert.AreEqual(ex.Message, "Invalid card format"); const string testcase4 = "player1 AH KH QH JH 10H"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase4))); var player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("player1", player.Name); Assert.AreEqual("A", player.Hand[0].Rank); Assert.AreEqual('H', player.Hand[0].Suit); Assert.AreEqual("K", player.Hand[1].Rank); Assert.AreEqual('H', player.Hand[1].Suit); Assert.AreEqual("Q", player.Hand[2].Rank); Assert.AreEqual('H', player.Hand[2].Suit); Assert.AreEqual("J", player.Hand[3].Rank); Assert.AreEqual('H', player.Hand[3].Suit); Assert.AreEqual("10", player.Hand[4].Rank); Assert.AreEqual('H', player.Hand[4].Suit); var rankFrequencyExpected = new List <int>(new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 }); Assert.AreEqual(rankFrequencyExpected.Count, player.RankFrequency.Count); Assert.IsTrue(Enumerable.SequenceEqual(rankFrequencyExpected, player.RankFrequency)); Assert.IsNull(builder.Build()); Assert.IsNull(builder.Build()); const string testcase5 = "player1 AH KH QH JH 10H player2 10C 9C 8C 7c 6c"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase5))); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("player1", player.Name); Assert.AreEqual("A", player.Hand[0].Rank); Assert.AreEqual('H', player.Hand[0].Suit); Assert.AreEqual("K", player.Hand[1].Rank); Assert.AreEqual('H', player.Hand[1].Suit); Assert.AreEqual("Q", player.Hand[2].Rank); Assert.AreEqual('H', player.Hand[2].Suit); Assert.AreEqual("J", player.Hand[3].Rank); Assert.AreEqual('H', player.Hand[3].Suit); Assert.AreEqual("10", player.Hand[4].Rank); Assert.AreEqual('H', player.Hand[4].Suit); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("player2", player.Name); Assert.AreEqual("10", player.Hand[0].Rank); Assert.AreEqual('C', player.Hand[0].Suit); Assert.AreEqual("9", player.Hand[1].Rank); Assert.AreEqual('C', player.Hand[1].Suit); Assert.AreEqual("8", player.Hand[2].Rank); Assert.AreEqual('C', player.Hand[2].Suit); Assert.AreEqual("7", player.Hand[3].Rank); Assert.AreEqual('C', player.Hand[3].Suit); Assert.AreEqual("6", player.Hand[4].Rank); Assert.AreEqual('C', player.Hand[4].Suit); Assert.IsNull(builder.Build()); Assert.IsNull(builder.Build()); const string testcase6 = "playerA AH \nKH QH \n\tJH 10H playerB 10C \r\n9C 8C 7c 6c"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase6))); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("playerA", player.Name); Assert.AreEqual("A", player.Hand[0].Rank); Assert.AreEqual('H', player.Hand[0].Suit); Assert.AreEqual("K", player.Hand[1].Rank); Assert.AreEqual('H', player.Hand[1].Suit); Assert.AreEqual("Q", player.Hand[2].Rank); Assert.AreEqual('H', player.Hand[2].Suit); Assert.AreEqual("J", player.Hand[3].Rank); Assert.AreEqual('H', player.Hand[3].Suit); Assert.AreEqual("10", player.Hand[4].Rank); Assert.AreEqual('H', player.Hand[4].Suit); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("playerB", player.Name); Assert.AreEqual("10", player.Hand[0].Rank); Assert.AreEqual('C', player.Hand[0].Suit); Assert.AreEqual("9", player.Hand[1].Rank); Assert.AreEqual('C', player.Hand[1].Suit); Assert.AreEqual("8", player.Hand[2].Rank); Assert.AreEqual('C', player.Hand[2].Suit); Assert.AreEqual("7", player.Hand[3].Rank); Assert.AreEqual('C', player.Hand[3].Suit); Assert.AreEqual("6", player.Hand[4].Rank); Assert.AreEqual('C', player.Hand[4].Suit); Assert.IsNull(builder.Build()); Assert.IsNull(builder.Build()); const string testcase7 = "playerA\nAH\nKH\nQH\nJH\n10H\nplayerB\n10C\n9C\n8C\n7c\n6c\n\n\n\n"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase7))); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("playerA", player.Name); Assert.AreEqual("A", player.Hand[0].Rank); Assert.AreEqual('H', player.Hand[0].Suit); Assert.AreEqual("K", player.Hand[1].Rank); Assert.AreEqual('H', player.Hand[1].Suit); Assert.AreEqual("Q", player.Hand[2].Rank); Assert.AreEqual('H', player.Hand[2].Suit); Assert.AreEqual("J", player.Hand[3].Rank); Assert.AreEqual('H', player.Hand[3].Suit); Assert.AreEqual("10", player.Hand[4].Rank); Assert.AreEqual('H', player.Hand[4].Suit); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("playerB", player.Name); Assert.AreEqual("10", player.Hand[0].Rank); Assert.AreEqual('C', player.Hand[0].Suit); Assert.AreEqual("9", player.Hand[1].Rank); Assert.AreEqual('C', player.Hand[1].Suit); Assert.AreEqual("8", player.Hand[2].Rank); Assert.AreEqual('C', player.Hand[2].Suit); Assert.AreEqual("7", player.Hand[3].Rank); Assert.AreEqual('C', player.Hand[3].Suit); Assert.AreEqual("6", player.Hand[4].Rank); Assert.AreEqual('C', player.Hand[4].Suit); Assert.IsNull(builder.Build()); Assert.IsNull(builder.Build()); const string testcase8 = "player1 10D KH JH QH AS"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase8))); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("player1", player.Name); Assert.AreEqual("A", player.Hand[4].Rank); Assert.AreEqual('S', player.Hand[4].Suit); Assert.AreEqual("K", player.Hand[1].Rank); Assert.AreEqual('H', player.Hand[1].Suit); Assert.AreEqual("Q", player.Hand[3].Rank); Assert.AreEqual('H', player.Hand[3].Suit); Assert.AreEqual("J", player.Hand[2].Rank); Assert.AreEqual('H', player.Hand[2].Suit); Assert.AreEqual("10", player.Hand[0].Rank); Assert.AreEqual('D', player.Hand[0].Suit); const string testcase9 = "player1 10D 10H 10S QH QS"; builder = new PlayerBuilder(new Tokenizer(new StringReader(testcase9))); player = builder.Build(); Assert.IsNotNull(player); Assert.AreEqual("player1", player.Name); rankFrequencyExpected = new List <int>(new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2, 0, 0 }); Assert.AreEqual(rankFrequencyExpected.Count, player.RankFrequency.Count); Assert.IsTrue(Enumerable.SequenceEqual(rankFrequencyExpected, player.RankFrequency)); }