using System; using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; using BlackjackClasses; using System.Collections; namespace NunitTests { [TestFixture] public class RoundTest { [Test] public void DealCard() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); player.Hand.Add(r.dealCard()); } [Test] public void HouseWin() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List blackJack = new List(); blackJack.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Ace)); blackJack.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Jack)); List playerHand = new List(); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Two)); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Three)); r.CheatRound(blackJack, playerHand); Assert.True(r.status.Equals(Round.GameStatus.DealerWin), "Dealer did not win: " + r.status); } [Test] public void PlayerWin() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List blackJack = new List(); blackJack.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Ace)); blackJack.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Jack)); List houseHand = new List(); houseHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Two)); houseHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Three)); r.CheatRound(houseHand,blackJack); Assert.True(r.status.Equals(Round.GameStatus.PlayerWin), "or player did not win" + r.status); } [Test] public void DrawBothOn21Round() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List blackJack = new List(); blackJack.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Ace)); blackJack.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Jack)); List redJack = new List(); redJack.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Ace)); redJack.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Jack)); r.CheatRound(blackJack, redJack); Assert.True(r.status.Equals(Round.GameStatus.Draw), "Game was not a draw: " + r.status); } [Test] public void TwoAcesMake12() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List houseHand = new List(); houseHand.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Ace)); houseHand.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Ace)); List playerHand = new List(); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Two)); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Three)); r.CheatRound(houseHand, playerHand); Assert.True(house.Score == 12 && r.status.Equals(Round.GameStatus.UnfinishedGame), "Score was not 12, and/or game has finished " + r.status); } [Test] public void ThreeAcesMake13() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List houseHand = new List(); houseHand.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Ace)); houseHand.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Ace)); List playerHand = new List(); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Two)); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Three)); r.CheatRound(houseHand, playerHand); r.cheatHitDealer(new Card(Card.CardSuits.Hearts, Card.CardValues.Ace)); Assert.True(house.Score == 13); } [Test] public void FourAcesMake14() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List houseHand = new List(); List playerHand = new List(); houseHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Two)); houseHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Three)); playerHand.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Ace)); playerHand.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Ace)); r.CheatRound(houseHand, playerHand); r.cheatHitPlayer(new Card(Card.CardSuits.Hearts, Card.CardValues.Ace)); r.cheatHitPlayer(new Card(Card.CardSuits.Diamonds, Card.CardValues.Ace)); Assert.True(player.Score == 14, "Score was not 14 it was: " + player.Score); } [Test] public void playerStayDealerHas17andWins() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List houseHand = new List(); houseHand.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Jack)); houseHand.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Seven)); List playerHand = new List(); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Two)); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Three)); r.CheatRound(houseHand, playerHand); r.stay(); Assert.True(r.status.Equals(Round.GameStatus.DealerWin), "Dealer did not win " + r.status); } [Test] public void BothOn17PlayerStayTestDraw() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List houseHand = new List(); houseHand.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Jack)); houseHand.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Seven)); List playerHand = new List(); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Jack)); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Three)); r.CheatRound(houseHand, playerHand); r.cheatHitPlayer(new Card(Card.CardSuits.Diamonds, Card.CardValues.Four)); r.stay(); Assert.True(r.status.Equals(Round.GameStatus.Draw), "Game was not a draw " + r.status); } [Test] public void BothOn19PlayerStayTestDraw() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List houseHand = new List(); houseHand.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Jack)); houseHand.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Nine)); List playerHand = new List(); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Jack)); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Three)); r.CheatRound(houseHand, playerHand); r.cheatHitPlayer(new Card(Card.CardSuits.Diamonds, Card.CardValues.Six)); r.stay(); Assert.True(r.status.Equals(Round.GameStatus.Draw), "Game was not a draw" + r.status); } [Test] public void Dealer17Player20TestWin() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List houseHand = new List(); houseHand.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Jack)); houseHand.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Seven)); List playerHand = new List(); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Jack)); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Three)); r.CheatRound(houseHand, playerHand); r.cheatHitPlayer(new Card(Card.CardSuits.Diamonds, Card.CardValues.Six)); r.stay(); Assert.True(r.status.Equals(Round.GameStatus.PlayerWin), "Game was not Player Win" + r.status); } [Test] public void PlayerBustDealerWin() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List houseHand = new List(); houseHand.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Jack)); houseHand.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Seven)); List playerHand = new List(); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Jack)); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.King)); r.CheatRound(houseHand, playerHand); r.cheatHitPlayer(new Card(Card.CardSuits.Diamonds, Card.CardValues.Two)); Assert.True(r.status.Equals(Round.GameStatus.DealerWin), "Dealer did not win " + r.status); } [Test] public void houseBustPlayerWin() { Player house = new Player(); Player player = new Player(); Round r = new Round(house, player); List houseHand = new List(); houseHand.Add(new Card(Card.CardSuits.Clubs, Card.CardValues.Jack)); houseHand.Add(new Card(Card.CardSuits.Spades, Card.CardValues.Six)); List playerHand = new List(); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.Jack)); playerHand.Add(new Card(Card.CardSuits.Hearts, Card.CardValues.King)); r.CheatRound(houseHand, playerHand); r.cheatHitDealer(new Card(Card.CardSuits.Diamonds, Card.CardValues.Six)); Assert.True(r.status.Equals(Round.GameStatus.PlayerWin), "Dealer was not BUST " + r.status); } } [TestFixture] public class UserTests { [Test] public void lookupNonExistantUser() { User u = new User("MichaelOkarimia", "michael@gmail.com"); } [Test] public void newGameExistingPlayer() { User u = new User("MichaelOkarimia", "michael@gmail.com"); u.NewGame(); u.saveRound(); } [Test] public void newGameNewPLayer() { User u = new User(DateTime.Now.Ticks.ToString(), "michael@gmail.com"); u.NewGame(); u.saveRound(); } [Test] public void getPlayerHistory() { User u = new User("MichaelOkarimia", "michael@gmail.com"); for (int i = 0; i < 2; i++) { u.NewGame(); while (u.Status.Equals(Round.GameStatus.UnfinishedGame)) u.hit(); u.saveRound(); } List roundHistory = u.getRoundHistory(); Assert.That(roundHistory.Count > 0); } [Test] public void createUserSaveThenRetrieveFromDB() { User u = new User("NewMichaelTest", "michael@gmail.com"); for (int i = 0; i < 2; i++) { u.NewGame(); while (u.Status.Equals(Round.GameStatus.UnfinishedGame)) u.hit(); u.saveRound(); } bool doesExists = false; User user2 = new User(ref doesExists, "MichaelOkarimia", "michael@gmail.com"); List roundHistory = user2.getRoundHistory(); Assert.True(roundHistory.Count > 0, "User was either not saved, or retireved form the DB"); } } }