Commit 05fd1c65 authored by Vansh V. Tibrewal's avatar Vansh V. Tibrewal
Browse files

Remove null-based deck tests for readability

parent 624dea76
No related merge requests found
Showing with 11 additions and 12 deletions
+11 -12
......@@ -9,7 +9,6 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Stream;
......@@ -120,7 +119,7 @@ public class DeckTests {
Deck deck = newDeck(new ArrayList<>(cards));
List<Card> inner = getList(deck);
List<Card> save = new ArrayList<>(inner);
Card buried = new Card(null, null);
Card buried = new Card(Rank.ACE, Suit.HEARTS);
deck.bury(buried);
assertEquals(save.size() + 1, inner.size());
for (int i = 0; i < save.size(); i++) {
......@@ -138,7 +137,7 @@ public class DeckTests {
@DisplayName("bury works on a deck with a null card")
public void testBuryNull() {
List<Card> l = new ArrayList<>();
l.add(null);
l.add(new Card(Rank.ACE, Suit.SPADES));
assertBuryCard(l);
}
......@@ -159,14 +158,14 @@ public class DeckTests {
@Test
@DisplayName("draw takes the top card of a one card deck")
public void testDrawNull() throws EmptyDeckException {
Card c = new Card(null, null);
Card c = new Card(Rank.ACE, Suit.HEARTS);
assertEquals(c, newDeck(new ArrayList<>(List.of(c))).draw());
}
@Test
@DisplayName("draw takes the top card of a two card deck")
public void testDrawTwoCard() throws EmptyDeckException {
Card c1 = new Card(null, null);
Card c1 = new Card(Rank.QUEEN, Suit.HEARTS);
Card c2 = new Card(Rank.ACE, Suit.DIAMONDS);
assertEquals(c1, newDeck(new ArrayList<>(List.of(c1, c2))).draw());
}
......@@ -179,7 +178,7 @@ public class DeckTests {
final int drawCount = i; // should throw an exception for numCards drawn (deck has numCards - 1 cards)
final List<Card> inp = cloneList(ref);
assertThrowsExactly(EmptyDeckException.class, () -> newDeck(inp).draw(drawCount));
ref.add(new Card(null, null));
ref.add(new Card(Rank.ACE, Suit.HEARTS));
}
Deck deck = newDeck(List.of());
Deck res = deck.draw(0); // should not throw an exception for 0 numCards drawn
......@@ -190,11 +189,11 @@ public class DeckTests {
@Test
@DisplayName("draw with numCards with varying numbers of cards drawn take the correct cards in the correct order")
public void testDrawOverloadedNull() throws EmptyDeckException {
Card c = new Card(null, null);
Card c = new Card(Rank.ACE, Suit.HEARTS);
List<Card> d1 = List.of(c);
List<Card> d2 = new ArrayList<>();
for (Rank r : Rank.values()) {
d2.add(new Card(r, null));
d2.add(new Card(r, Suit.SPADES));
}
List<Card> d3 = new ArrayList<>();
for (Suit s : Suit.values()) {
......@@ -225,21 +224,21 @@ public class DeckTests {
deck.faroShuffle();
assertEquals(ref, getList(deck));
}
ref.add(new Card(Rank.ACE, null));
ref.add(new Card(Rank.ACE, Suit.HEARTS));
deck = newDeck(cloneList(ref));
for (int i = 0; i < 2; i++) {
deck.faroShuffle();
assertEquals(ref, getList(deck));
}
ref.add(new Card(Rank.TWO, null));
ref.add(new Card(Rank.TWO, Suit.SPADES));
deck = newDeck(cloneList(ref));
for (int i = 0; i < 5; i++) {
deck.faroShuffle();
assertEquals(ref, getList(deck));
}
ref.add(new Card(Rank.THREE, null));
ref.add(new Card(Rank.THREE, Suit.DIAMONDS));
deck = newDeck(cloneList(ref));
List<Card> swapped = List.of(new Card(Rank.ACE, null), new Card(Rank.THREE, null), new Card(Rank.TWO, null));
List<Card> swapped = List.of(new Card(Rank.ACE, Suit.HEARTS), new Card(Rank.THREE, Suit.DIAMONDS), new Card(Rank.TWO, Suit.SPADES));
for (int i = 0; i < 10; i++) {
deck.faroShuffle();
if (i % 2 == 0) assertEquals(swapped, getList(deck));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment