public void Trick_OrderedMoves() { var participants = new List <Participant>() { new Participant(), new Participant(), new Participant(), new Participant(), new Participant() }; var playerList = participants.Select(p => p.Player).ToList(); var startingPlayer = playerList[3]; var cardList = new List <SheepCard>() { 0, (SheepCard)1, (SheepCard)2, (SheepCard)3, (SheepCard)4, }; var trickList = new List <ITrick>(); var handMock = GetHand(startingPlayer, playerList); var trick = new Trick(handMock.Object); for (var i = 0; i < 5; ++i) { var index = i + 3 < 5 ? i + 3 : i + 3 - 5; //We want to start with player 4. trick.Add(playerList[index], cardList[index]); } for (var i = 0; i < 5; ++i) { var index = i + 3 < 5 ? i + 3 : i + 3 - 5; //We want to start with player 4. Assert.AreSame(playerList[index], trick.OrderedMoves[i].Key, "Expected players to match at move " + i); Assert.AreEqual(cardList[index], trick.OrderedMoves[i].Value, "Expected cards to match at move " + i); } }
public void Trick_IsLegal_PlayerDoesNotHaveSuit() { var firstPlayer = new Participant() { Cards = "9♠" }.Player; var player = new Participant() { Cards = "K♥;7♥;Q♣;8♣" }.Player; var startingPlayerCalcMock = new Mock <IStartingPlayerCalculator>(); startingPlayerCalcMock.Setup(m => m.GetStartingPlayer(It.IsAny <IHand>(), It.IsAny <ITrick>())).Returns(firstPlayer); var handMock = new Mock <IHand>(); handMock.Setup(m => m.Players).Returns(new List <IPlayer>()); handMock.Setup(m => m.ITricks).Returns(new List <ITrick>()); handMock.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.JackOfDiamonds); handMock.Setup(m => m.PartnerCardEnum).Returns(SheepCard.JACK_DIAMONDS); var trick = new Trick(handMock.Object, startingPlayerCalcMock.Object); trick.Add(firstPlayer, SheepCard.N9_SPADES); Assert.IsTrue(trick.IsLegalAddition(SheepCard.N7_HEARTS, player), "There is no spades in the hand. Hearts is fine."); Assert.IsTrue(trick.IsLegalAddition(SheepCard.N8_CLUBS, player), "There is no spades in the hand. Clubs is fine."); Assert.IsTrue(trick.IsLegalAddition(SheepCard.QUEEN_CLUBS, player), "There is no spades in the hand. Trump is fine."); }
public void Trick_IsComplete() { var firstPlayer = new Mock <IPlayer>().Object; var startingPlayerCalcMock = new Mock <IStartingPlayerCalculator>(); startingPlayerCalcMock.Setup(m => m.GetStartingPlayer(It.IsAny <IHand>(), It.IsAny <ITrick>())).Returns(firstPlayer); var mockHand = new Mock <IHand>(); mockHand.Setup(m => m.Players).Returns(new List <IPlayer>()); mockHand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.N10_DIAMONDS); var trickList = new List <ITrick>(); mockHand.Setup(m => m.ITricks).Returns(trickList); mockHand.Setup(m => m.AddTrick(It.IsAny <ITrick>())).Callback((ITrick newTrick) => { trickList.Add(newTrick); }); foreach (var playerCount in new[] { 3, 5 }) { mockHand.Setup(m => m.PlayerCount).Returns(playerCount); var trick = new Trick(mockHand.Object, startingPlayerCalcMock.Object); for (var cardsInTrick = 0; cardsInTrick < playerCount; ++cardsInTrick) { Assert.IsFalse(trick.IsComplete(), "Trick should not be complete when there are " + cardsInTrick + " cards in the trick and " + playerCount + " players in the game."); trick.Add(new MockPlayer(), 0); } Assert.IsTrue(trick.IsComplete(), "Trick should be complete when there are " + playerCount + " cards in the trick and " + playerCount + " players in the game."); } }
public void Trick_SetPartner() { var firstPlayer = new Mock <IPlayer>().Object; var startingPlayerCalcMock = new Mock <IStartingPlayerCalculator>(); startingPlayerCalcMock.Setup(m => m.GetStartingPlayer(It.IsAny <IHand>(), It.IsAny <ITrick>())).Returns(firstPlayer); var trickList = new List <ITrick>(); var mockHand = new Mock <IHand>(); mockHand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.QUEEN_DIAMONDS); mockHand.Setup(m => m.PlayerCount).Returns(5); mockHand.Setup(m => m.Players).Returns(new List <IPlayer>()); mockHand.Setup(m => m.ITricks).Returns(trickList); mockHand.Setup(m => m.AddTrick(It.IsAny <ITrick>())).Callback((ITrick newTrick) => { trickList.Add(newTrick); }); var hand = mockHand.Object; var trick = new Trick(hand, startingPlayerCalcMock.Object); var player = new Mock <IPlayer>(); player.Setup(c => c.Name).Returns("DesiredPlayer"); player.Setup(c => c.Cards).Returns(new List <SheepCard>() { SheepCard.QUEEN_DIAMONDS }); player.Setup(c => c.Participant).Returns(new Participant()); IPlayer partner = player.Object; var _methodCalled = false; mockHand.Setup(f => f.SetPartner(It.IsAny <IPlayer>(), It.IsAny <ITrick>())).Callback((IPlayer pl, ITrick tr) => { _methodCalled = true; Assert.AreEqual(partner, pl); Assert.AreEqual(trick, tr); }); trick.Add(player.Object, SheepCard.QUEEN_DIAMONDS); Assert.IsTrue(_methodCalled, "When someone adds the partner card to the trick, the hand's partner get's specified."); }
public void Trick_IsLegal_PartnerMustFollowWithPartnerCard() { var partner = new Participant() { Cards = "T♥;T♠;A♥;J♦;7♠;A♠" }.Player; var curTrick = new Mock <ITrick>(); var hand = new Mock <IHand>(); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_SPADES); hand.Setup(m => m.ITricks).Returns(new List <ITrick>()); hand.Setup(m => m.Players).Returns(new List <IPlayer>() { partner }); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(partner); var trick = new Trick(hand.Object, calculator.Object); trick.Add(new Participant().Player, SheepCard.N8_SPADES); Assert.IsTrue(trick.IsLegalAddition(SheepCard.ACE_SPADES, partner), "Partner must follow suit and must place partner card before anything else in this suit."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N10_HEARTS, partner), "No other cards can be played."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N10_SPADES, partner), "No other cards can be played."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.ACE_HEARTS, partner), "No other cards can be played."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.JACK_SPADES, partner), "No other cards can be played."); Assert.IsFalse(trick.IsLegalAddition(SheepCard.N7_SPADES, partner), "No other cards can be played."); }
public void Trick_IsLegal_PickerCanFollowWithLastCardOfCalledSuit() { var startingPlayer = new Participant().Player; var picker = new Participant() { Cards = "9♦;Q♥;9♥;A♣;K♣;7♠" }.Player; var hand = new Mock <IHand>(); hand.Setup(m => m.Players).Returns(new List <IPlayer>() { startingPlayer, picker }); hand.Setup(m => m.ITricks).Returns(new List <ITrick>()); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_HEARTS); var calculator = new Mock <IStartingPlayerCalculator>(); calculator.Setup(m => m.GetStartingPlayer(hand.Object, It.IsAny <ITrick>())).Returns(startingPlayer); var trick = new Trick(hand.Object, calculator.Object); trick.Add(startingPlayer, SheepCard.N10_HEARTS); Assert.IsTrue(trick.IsLegalAddition(SheepCard.N9_HEARTS, picker)); }
public void Trick_Winner() { var player1 = new Participant().Player; var player2 = new Participant().Player; var player3 = new Participant().Player; var player4 = new Participant().Player; var player5 = new Participant().Player; var hand = new Mock <IHand>(); hand.Setup(m => m.ITricks).Returns(new List <ITrick>()); hand.Setup(m => m.Players).Returns(new List <IPlayer>() { player1, player2, player3, player4, player5 }); hand.Setup(m => m.IGame.PartnerMethodEnum).Returns(PartnerMethod.CalledAce); hand.Setup(m => m.PartnerCardEnum).Returns(SheepCard.ACE_SPADES); var startingPlayerCalcMock = new Mock <IStartingPlayerCalculator>(); startingPlayerCalcMock.Setup(m => m.GetStartingPlayer(It.IsAny <IHand>(), It.IsAny <ITrick>())).Returns(player1); { var trick = new Trick(hand.Object, startingPlayerCalcMock.Object); trick.Add(player1, SheepCard.N8_HEARTS); trick.Add(player2, SheepCard.ACE_SPADES); trick.Add(player3, SheepCard.N10_HEARTS); trick.Add(player4, SheepCard.KING_HEARTS); trick.Add(player5, SheepCard.ACE_CLUBS); //The order of the plays should be based on SortOrder, not on the database. trick.TrickPlays = new List <TrickPlay>() { trick.TrickPlays.ElementAt(4), trick.TrickPlays.ElementAt(2), trick.TrickPlays.ElementAt(1), trick.TrickPlays.ElementAt(3), trick.TrickPlays.ElementAt(0), }; var winner = trick.Winner(); Assert.AreEqual(player3, winner.Player, "Ten of hearts has the hightest rank of the correct suite."); Assert.AreEqual(36, winner.Points, "Expected points for 2 Aces, 1 King, 1 Ten."); } { var trick = new Trick(hand.Object, startingPlayerCalcMock.Object); trick.Add(player1, SheepCard.N8_HEARTS); trick.Add(player2, SheepCard.N8_DIAMONDS); trick.Add(player3, SheepCard.N10_HEARTS); trick.Add(player4, SheepCard.KING_HEARTS); trick.Add(player5, SheepCard.ACE_CLUBS); var winner = trick.Winner(); Assert.AreEqual(player2, winner.Player, "Trump has the highest rank."); Assert.AreEqual(25, winner.Points, "Expected points for 1 Aces, 1 Ten, 1 King."); } { var trick = new Trick(hand.Object, startingPlayerCalcMock.Object); trick.Add(player1, SheepCard.N8_DIAMONDS); trick.Add(player2, SheepCard.ACE_SPADES); trick.Add(player3, SheepCard.N10_HEARTS); trick.Add(player4, SheepCard.KING_DIAMONDS); trick.Add(player5, SheepCard.ACE_CLUBS); var winner = trick.Winner(); Assert.AreEqual(player4, winner.Player, "Trump has the highest rank when it is played first, too."); Assert.AreEqual(36, winner.Points, "Expected points for 2 Aces, 1 King, 1 Ten."); } }