public void DrawPile_PlaceAtBottomTest() { // Arrange. var expectedCards = new IntCard[] { // 3 (new top), 2, 1, 4 (new bottom) new IntCard(3), new IntCard(2), new IntCard(1), new IntCard(4) }; var cards = new IntCard[] { // 1 (old bottom), 2, 3, 4 (old top) new IntCard(1), new IntCard(2), new IntCard(3), new IntCard(4) }; var drawPile = new DrawPile <IntCard>(cards); List <IntCard> actualCards; // Act. var drawnCard = drawPile.Draw(); drawPile.PlaceAtBottom(drawnCard); // place card with value 4 at the bottom actualCards = new List <IntCard>(drawPile.Cards); // Assert. // Use collections assertions for lists because HashSet is unable to compare different sets. // Otherwise, GetHashCode and Equals methods would have to be tamed. CollectionAssert.AreEqual(expectedCards, actualCards, Comparer <IntCard> .Create((a, b) => { return(a.Value - b.Value); })); }
public void DrawPile_BasicShuffleTest() { // Arrange. var cards = new IntCard[] { new IntCard(1), new IntCard(2), new IntCard(3) }; var expectedCardSet = new HashSet <IntCard>(cards); HashSet <IntCard> actualCardSet; var drawPile = new DrawPile <IntCard>(cards); // Act. drawPile.Shuffle(); actualCardSet = new HashSet <IntCard>(drawPile.Cards); // Assert. Assert.AreEqual(expectedCardSet.Count, actualCardSet.Count); Assert.IsTrue(expectedCardSet.SetEquals(actualCardSet)); }
public void DrawPile_DrawAllTest() { // Arrange. var cards = new IntCard[] { new IntCard(1), new IntCard(2), new IntCard(3) }; var expectedCardSet = new HashSet <IntCard>(cards); HashSet <IntCard> actualCardSet; var drawPile = new DrawPile <IntCard>(cards); IEnumerable <IntCard> drawnCards; // Act. actualCardSet = new HashSet <IntCard>(drawPile.Cards); drawnCards = drawPile.DrawAll(); // Assert. Assert.AreEqual(expectedCardSet.Count, actualCardSet.Count); Assert.IsTrue(expectedCardSet.SetEquals(actualCardSet)); Assert.IsTrue(expectedCardSet.SetEquals(new HashSet <IntCard>(drawnCards))); Assert.AreEqual(0, drawPile.Cards.Count); }