public void TestDealer() { BlackjackBackend.App.Dealer d = new BlackjackBackend.App.Dealer(2); BlackjackBackend.App.Deck deck = new BlackjackBackend.App.Deck(1); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(d.Hand.Count == 0); System.Collections.Generic.List <int> ourHand = new System.Collections.Generic.List <int>(); int card; for (int i = 0; i < 4; i++) { card = deck.NextCard; ourHand.Add(card); d.AddCard(card); } foreach (int c in d.Hand) { Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(ourHand.Contains(c)); } foreach (int c in ourHand) { Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(d.Hand.Contains(c)); } Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(d.Id == 2); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(d.IsNPC); d.ResetHand(); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(d.Hand.Count == 0); }
public void TestNextCard() { BlackjackBackend.App.Deck d = new BlackjackBackend.App.Deck(1); System.Collections.Generic.HashSet <int> alreadySeen = new System.Collections.Generic.HashSet <int>(); int card; for (int i = 0; i < 52; i++) { card = d.NextCard; Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(card >= 0 && card <= 51, "Expected the card to be an int between 0 and 51"); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsFalse(alreadySeen.Contains(card), "expected only 1 of each card"); alreadySeen.Add(card); } try { int x = d.NextCard; throw new System.AccessViolationException("expected only 52 cards in the deck"); } catch (System.Exception e) { Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(e.Message == "Deck count not high enough"); } }