public void Pop_ManyFromEmptyPile_Throws() { var position = _f.Create <PilePosition>(); var pile = new Pile(); var ex = Assert.Catch <InvalidOperationException>(() => pile.Pop(position, 2)); Assert.That(ex.Message, Contains.Substring("is empty").IgnoreCase); }
public void Pop_Bottom_TakesOrderedGroupFromTail() { var source = new[] { RndCard(1), RndCard(2), RndCard(3), RndCard(4) }; var pile = new Pile(source); var result = pile.Pop(PilePosition.Bottom, 2); CollectionAssert.AreEqual(new[] { source[2], source[3] }, result); CollectionAssert.AreEqual(new[] { source[0], source[1] }, pile); }
public void Pop_Bottom_TakesFromTail() { var source = new[] { RndCard(1), RndCard(2), RndCard(3), RndCard(4) }; var pile = new Pile(source); var result = pile.Pop(PilePosition.Bottom); Assert.AreEqual(3, pile.Size); Assert.AreSame(source[3], result); }
public void Pop_Top_TakesFromHead() { var source = new[] { RndCard(1), RndCard(2), RndCard(3), RndCard(4) }; var pile = new Pile(source); var result = pile.Pop(PilePosition.Top); Assert.AreEqual(3, pile.Size); Assert.AreSame(source[0], result); }
public void Pop_CountExactlyAsSizeOfPile_EmptyPile() { var position = _f.Create <PilePosition>(); var pile = new Pile(new[] { RndCard(), RndCard() }); pile.Pop(position, 2); Assert.AreEqual(0, pile.Size); Assert.IsTrue(pile.IsEmpty); }
public void Pop_Middle_OneLessThanCardsInPile_AlsoTakesCardFromHeadOrTail() { var source = new[] { RndCard(1), RndCard(2), RndCard(3), RndCard(4) }; var pile = new Pile(source); var result = pile.Pop(PilePosition.Middle, 3); Assert.AreEqual(3, result.Count, "result size"); Assert.AreEqual(1, pile.Size); Assert.IsTrue(pile.First().Rank.Value == 1 || pile.First().Rank.Value == 4); }
public void Pop_MoreThanCardsInPile_ReturnsAllCards() { var position = _f.Create <PilePosition>(); var pile = new Pile(new[] { RndCard() }); var result = pile.Pop(position, 2); Assert.AreEqual(0, pile.Size); Assert.IsTrue(pile.IsEmpty); Assert.AreEqual(1, result.Count); }
private void DrawCardsToFillHands(Pile stockPile) { _movements .Select(movement => movement.PlayerName) .Distinct() .OrderBy(name => name == _defendingPlayer?.Name ? 1 : 0) // defending is last .Select(name => _players.First(p => p.Name == name).Hand) .Select(hand => (hand, lack: _rules.HandSize - hand.Size)) .TakeWhile(_ => stockPile.Size > 0) .Select(x => (x.hand, drawnCards: stockPile.Pop(PilePosition.Top, x.lack))) .ForEach(x => x.hand.Push(x.drawnCards, PilePosition.Default)); }
public void Pop_Middle_TakesOrderedGroup() { var source = new[] { RndCard(1), RndCard(2), RndCard(3), RndCard(4) }; var pile = new Pile(source); using (Random.Returing(new[] { 2 })) { var result = pile.Pop(PilePosition.Middle, 2); CollectionAssert.AreEqual(new[] { source[1], source[2] }, result); Assert.AreEqual(2, result.Count, "result size"); Assert.AreEqual(2, pile.Size); Assert.AreSame(source[0], pile.First(), "first"); Assert.AreSame(source[3], pile.Last(), "last"); } }
public void Pop_Middle_TakesRandomCard() { var source = new[] { RndCard(1), RndCard(2), RndCard(3), RndCard(4) }; var dict = new Dictionary <int, int>(); for (var i = 0; i < 50; i++) { var pile = new Pile(source); var result = pile.Pop(PilePosition.Middle); IncValueForKey(dict, result.Rank.Value); } Assert.That(dict.Select(x => x.Value), Has.All.GreaterThan(1)); Assert.AreEqual(4, dict.Keys.Count); }
private void HandOut(Pile allCardsForNextGame) { var totalHands = _parties.Players.Count(); if (allCardsForNextGame.Size < totalHands * _rules.HandSize) { throw new InvalidOperationException($"Not enough free cards ({allCardsForNextGame.Size}) to hand out between {totalHands} players"); } foreach (var player in _parties.Players) { var dealtPacket = allCardsForNextGame.Pop(PilePosition.Top, _rules.HandSize); if (dealtPacket.Count < _rules.HandSize) { throw new NotImplementedException("Can not deal at end of game"); } Debug.Assert(player.Hand.IsEmpty, "hand not empty before HandOut"); player.Hand.Push(dealtPacket, PilePosition.Default); } }