public void show_dealers_cards_hide_not_visible() { string output; string name = "Swifty"; IPlayer dealer = new Dealer(name); ICard card1 = new Card(Suit.Clubs, Rank.Jack); card1.Visible = false; ICard card2 = new Card(Suit.Hearts, Rank.Seven); ICard card3 = new Card(Suit.Hearts, Rank.Four); dealer.AddCardToHand(card1); dealer.AddCardToHand(card2); dealer.AddCardToHand(card3); output = ops.GetHandHeaderMessage(dealer); ops.DisplayMessage(output); output = ops.GetHandMessage(dealer.GetHand(), false); ops.DisplayMessage(output); Assert.AreEqual($"Dealer {name} has: ", mockConsoleIO.GetConsoleWrites()[0]); Assert.AreEqual($"{Hand.FACEDOWN},Seven of Hearts,Four of Hearts", mockConsoleIO.GetConsoleWrites()[1]); Assert.AreEqual(2, mockConsoleIO.GetConsoleWrites().Count); Dependencies.consoleIO.reset(); }
private void AddMockCardToHand(Value value) { var mockCard1 = new Mock <ICard>(); mockCard1.Setup(card => card.GetValue()).Returns(value); sut.AddCardToHand(mockCard1.Object); }
public void Dealer_WhenGivenAceAnd5_ShouldReturnMustStopFalse() { // Arrange Dealer dealer = new Dealer(); // Act dealer.AddCardToHand(new Card("", 11)); dealer.AddCardToHand(new Card("", 5)); // Assert Assert.IsFalse(dealer.MustStop); }
public void show_dealers_score_and_hand() { string output; int score; string name = "John"; IPlayer dealer = new Dealer(name); ICard card1 = new Card(Suit.Clubs, Rank.Nine); card1.Visible = false; ICard card2 = new Card(Suit.Hearts, Rank.Two); dealer.AddCardToHand(card1); dealer.AddCardToHand(card2); score = 2; output = ops.GetScoreMessage(dealer); ops.DisplayMessage(output); output = ops.GetHandMessage(dealer.GetHand(), false); ops.DisplayMessage(output); Assert.AreEqual($"Dealer Score Showing={score}", mockConsoleIO.GetConsoleWrites()[0]); Assert.AreEqual($"{Hand.FACEDOWN},Two of Hearts", mockConsoleIO.GetConsoleWrites()[1]); Assert.AreEqual(2, mockConsoleIO.GetConsoleWrites().Count); mockConsoleIO.ClearWriteConsole(); ICard card3 = new Card(Suit.Hearts, Rank.Five); dealer.AddCardToHand(card3); score = 7; output = ops.GetScoreMessage(dealer); ops.DisplayMessage(output); output = ops.GetHandMessage(dealer.GetHand(), false); ops.DisplayMessage(output); Assert.AreEqual($"Dealer Score Showing={score}", mockConsoleIO.GetConsoleWrites()[0]); Assert.AreEqual($"{Hand.FACEDOWN},Two of Hearts,Five of Hearts", mockConsoleIO.GetConsoleWrites()[1]); Assert.AreEqual(2, mockConsoleIO.GetConsoleWrites().Count); mockConsoleIO.ClearWriteConsole(); ICard card4 = new Card(Suit.Spades, Rank.Eight); dealer.AddCardToHand(card4); score = 15; output = ops.GetScoreMessage(dealer); ops.DisplayMessage(output); output = ops.GetHandMessage(dealer.GetHand(), false); ops.DisplayMessage(output); Assert.AreEqual($"Dealer Score Showing={score}", mockConsoleIO.GetConsoleWrites()[0]); Assert.AreEqual($"{Hand.FACEDOWN},Two of Hearts,Five of Hearts,Eight of Spades", mockConsoleIO.GetConsoleWrites()[1]); Assert.AreEqual(2, mockConsoleIO.GetConsoleWrites().Count); Dependencies.consoleIO.reset(); }
public void get_final_results_when_dealer_and_player_have_same_score_push() { Dealer dealer = new Dealer(); IPlayer player = new HumanPlayer(); ICard card1 = new Card(Suit.Clubs, Rank.Queen); ICard card2 = new Card(Suit.Diamonds, Rank.Ten); ICard card3 = new Card(Suit.Spades, Rank.King); ICard card4 = new Card(Suit.Hearts, Rank.Jack); dealer.AddCardToHand(card1); dealer.AddCardToHand(card2); player.AddCardToHand(card3); player.AddCardToHand(card4); GameResult result = ops.GetFinalResults(dealer, player); Assert.AreEqual(GameResult.Push, result); }
public void get_final_results_player_wins() { Dealer dealer = new Dealer(); IPlayer player = new HumanPlayer(); ICard card1 = new Card(Suit.Clubs, Rank.Seven); ICard card2 = new Card(Suit.Diamonds, Rank.Ten); ICard card3 = new Card(Suit.Spades, Rank.King); ICard card4 = new Card(Suit.Hearts, Rank.Eight); dealer.AddCardToHand(card1); dealer.AddCardToHand(card2); player.AddCardToHand(card3); player.AddCardToHand(card4); GameResult result = ops.GetFinalResults(dealer, player); Assert.AreEqual(GameResult.PlayerWin, result); }
public void get_final_results_dealer_has_blackjack() { Dealer dealer = new Dealer(); IPlayer player = new HumanPlayer(); ICard card1 = new Card(Suit.Clubs, Rank.Ace); ICard card2 = new Card(Suit.Diamonds, Rank.Ten); ICard card3 = new Card(Suit.Spades, Rank.Seven); ICard card4 = new Card(Suit.Hearts, Rank.Ace); dealer.AddCardToHand(card1); dealer.AddCardToHand(card2); player.AddCardToHand(card3); player.AddCardToHand(card4); GameResult result = ops.GetFinalResults(dealer, player); Assert.AreEqual(GameResult.DealerBlackjack, result); }
public void next_action_busted_because_total_is_greater_than_21() { IPlayer dealer = new Dealer(); IHand playerHand = new Hand(); Card card0 = new Card(Suit.Spades, Rank.King); playerHand.AddCard(card0); Card card1 = new Card(Suit.Clubs, Rank.King); Card card2 = new Card(Suit.Clubs, Rank.Seven); Card card3 = new Card(Suit.Clubs, Rank.Five); dealer.AddCardToHand(card1); dealer.AddCardToHand(card2); dealer.AddCardToHand(card3); PlayerAction action = dealer.NextAction(playerHand); Assert.AreEqual(PlayerAction.Busted, action); }
public void next_action_stay_when_total_is_17_or_more() { IPlayer player = new ComputerPlayer(); Dealer dealer = new Dealer(); Card card0 = new Card(Suit.Spades, Rank.King); Card card1 = new Card(Suit.Spades, Rank.Six); dealer.AddCardToHand(card0); dealer.AddCardToHand(card1); Card card2 = new Card(Suit.Clubs, Rank.King); Card card3 = new Card(Suit.Clubs, Rank.Seven); player.AddCardToHand(card1); player.AddCardToHand(card2); PlayerAction action = player.NextAction(dealer.GetHand()); Assert.AreEqual(PlayerAction.Stand, action); }
public void NextMoveStayGivenDeckValueGreaterThenStayThreshold() { var deckMock = new Mock <IDeck>(); deckMock.Setup(dM => dM.Hit()).Returns(new Card(Suit.Clubs, Face.Ace)); var dealerName = "Robert"; var sut = new Dealer(dealerName, deckMock.Object); sut.AddCardToHand(sut.Hit()); deckMock.Setup(dM => dM.Hit()).Returns(new Card(Suit.Clubs, Face.Ten)); sut.AddCardToHand(sut.Hit()); var expectedValue = 21; var expectedNextMove = Move.Stay; Assert.Equal(sut.GetHandValue(), expectedValue); Assert.Equal(sut.NextMove(), expectedNextMove); }
public void show_dealers_cards_show_not_visible() { string name = "Swifty"; string output; IPlayer dealer = new Dealer(name); ICard card1 = new Card(Suit.Diamonds, Rank.King); ICard card2 = new Card(Suit.Spades, Rank.Jack); ICard card3 = new Card(Suit.Hearts, Rank.Ace); dealer.AddCardToHand(card1); dealer.AddCardToHand(card2); dealer.AddCardToHand(card3); output = ops.GetHandHeaderMessage(dealer); ops.DisplayMessage(output); output = ops.GetHandMessage(dealer.GetHand(), false); ops.DisplayMessage(output); Assert.AreEqual($"Dealer {name} has: ", mockConsoleIO.GetConsoleWrites()[0]); Assert.AreEqual("King of Diamonds,Jack of Spades,Ace of Hearts", mockConsoleIO.GetConsoleWrites()[1]); Assert.AreEqual(2, mockConsoleIO.GetConsoleWrites().Count); Dependencies.consoleIO.reset(); }