public void TestDeck_Initialize() { //Arrange var deckBl = new DeckBL(); var deck = new Deck(); //Act deckBl.Initialize(deck); //Assert Assert.AreEqual(deck.CardDeck.Count, 52, "Deck failed to initialize"); }
public void TestDeck_PullCard() { //Arrange var deckBl = new DeckBL(); var deck = new Deck(); //Act deckBl.Initialize(deck); var card = deckBl.PullCard(deck); var isCardValid = (card.Rank != CardRank.None && card.Suit != CardSuit.None); //Assert Assert.AreEqual(isCardValid, true, "Card pulled from Deck is not valid"); Assert.AreEqual(deck.CardDeck.Count, 52, "Deck does not contain expected number of cards after pulling a card."); }
public void TestDeck_Duplicates() { //Arrange var deckBl = new DeckBL(); var deck = new Deck(); //Act deckBl.Initialize(deck); //deck.CardDeck.Add(new Card(CardRank.Ace, CardSuit.Spades)); INSERT DUPLICATE var duplicateList = deck.CardDeck.GroupBy(x => new { x.Rank, x.Suit }) .Where(group => group.Count() >= 2) .Select(group => group.First()); //Assert Assert.AreEqual(duplicateList.Any(), false, "There are duplicate cards in the deck."); }
public void TestPokerHand_PullCard() { //Arrange var pokerHandBl = new PokerHandBL(); var deckBl = new DeckBL(); var deck = new Deck(); deckBl.Initialize(deck); var pokerHandPlayer1 = new PokerHand(deck, "Player1"); var pokerHandPlayer2 = new PokerHand(deck, "Player2"); var deckCardsFirstSet = new List <Card>() { deck.CardDeck[0], deck.CardDeck[1], deck.CardDeck[2], deck.CardDeck[3], deck.CardDeck[4], }; var deckCardsSecondSet = new List <Card>() { deck.CardDeck[5], deck.CardDeck[6], deck.CardDeck[7], deck.CardDeck[8], deck.CardDeck[9], }; //Act pokerHandPlayer1.Hand = pokerHandBl.PullCards(pokerHandPlayer1); pokerHandPlayer2.Hand = pokerHandBl.PullCards(pokerHandPlayer2); var isFirstSetOfCardsEqual = deckCardsFirstSet.All(pokerHandPlayer1.Hand.Contains) && deckCardsFirstSet.Count == pokerHandPlayer1.Hand.Count; var isSecondSetOfCardsEqual = deckCardsSecondSet.All(pokerHandPlayer2.Hand.Contains) && deckCardsSecondSet.Count == pokerHandPlayer2.Hand.Count; //Assert Assert.AreEqual(pokerHandPlayer1.Hand.Count, 5, "Cards in hand is not equal to 5"); Assert.AreEqual(isFirstSetOfCardsEqual, true, "First set of Cards in Deck is not equal to first Pull."); Assert.AreEqual(isSecondSetOfCardsEqual, true, "Secont set of Cards in Deck is not equal to second Pull."); }
public void TestEvaluateWinningHand() { //Arrange PokerBL pokerBl = new PokerBL(); PokerHandBL pokerHandBl = new PokerHandBL(); DeckBL deckBl = new DeckBL(); Deck deck = new Deck(); deckBl.Initialize(deck); PokerHand player1 = new PokerHand(deck, "Player1"); PokerHand player2 = new PokerHand(deck, "Player2"); PokerHand player3 = new PokerHand(deck, "Player3"); player1.Hand = pokerHandBl.PullCards(player1); player2.Hand = pokerHandBl.PullCards(player2); player3.Hand = pokerHandBl.PullCards(player3); var playerList = new List <PokerHand>() { player1, player2, player3 }; foreach (var player in playerList) { player.PokerScore = pokerBl.EvaluatePokerHand(player); } var winningHand = playerList.OrderByDescending(x => x.PokerScore).First(); //This test does not determine which player won the game in case of a tie, only the hand with highest score (first or default) //Act var result = pokerBl.EvaluateWinningHand(playerList); //Assert Assert.AreEqual(winningHand.PokerScore, result.PokerScore, "Poker Hand with highest score did not win the game."); }
public void TestDeck_Shuffle() { //Arrange var deckBl = new DeckBL(); var deck = new Deck(); //Act deckBl.Initialize(deck); var firstCard = deck.CardDeck[0]; deckBl.ShuffleDeck(deck, 1); var isShuffled = firstCard != deck.CardDeck[0]; var duplicateList = deck.CardDeck.GroupBy(x => new { x.Rank, x.Suit }) .Where(group => group.Count() >= 2) .Select(group => group.First()); //Assert Assert.AreEqual(isShuffled, true, "Deck may not be shuffled."); Assert.AreEqual(deck.CardDeck.Count, 52, "Deck does not contain expected number of cards after shuffle."); Assert.AreEqual(duplicateList.Any(), false, "There are duplicate cards in the deck after shuffle."); }
public void TestThreeOfAKindTieBreaker() { //Arrange PokerBL pokerBl = new PokerBL(); PokerHandBL pokerHandBl = new PokerHandBL(); DeckBL deckBl = new DeckBL(); Deck deck = new Deck(); deckBl.Initialize(deck); PokerHand player1 = new PokerHand(deck, "Player1"); PokerHand player2 = new PokerHand(deck, "Player2"); PokerHand player3 = new PokerHand(deck, "Player3"); //Assign cards to players manually to simulate One Pair Tie Breaker var player1CardList = new List <Card>() { new Card(CardRank.Jack, CardSuit.Hearts), new Card(CardRank.Six, CardSuit.Diamonds), new Card(CardRank.Jack, CardSuit.Spades), new Card(CardRank.Jack, CardSuit.Club), new Card(CardRank.Jack, CardSuit.Diamonds) }; var player2CardList = new List <Card>() { new Card(CardRank.Two, CardSuit.Spades), new Card(CardRank.Two, CardSuit.Diamonds), new Card(CardRank.Jack, CardSuit.Spades), new Card(CardRank.King, CardSuit.Club), new Card(CardRank.Two, CardSuit.Hearts) }; var player3CardList = new List <Card>() { new Card(CardRank.King, CardSuit.Spades), new Card(CardRank.King, CardSuit.Diamonds), new Card(CardRank.Jack, CardSuit.Spades), new Card(CardRank.King, CardSuit.Club), new Card(CardRank.Ace, CardSuit.Spades) }; player1.Hand = player1CardList; player2.Hand = player2CardList; player3.Hand = player3CardList; var playerList = new List <PokerHand>() { player1, player2, player3 }; var winningHand = player3; //Act var result = pokerBl.EvaluateWinningHand(playerList); //Assert Assert.AreEqual(winningHand.PlayerName, result.PlayerName, "Player with winning three of a kind hand did not win the game."); }