Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs0a-24su
war
Commits
05fd1c65
Commit
05fd1c65
authored
1 year ago
by
Vansh V. Tibrewal
Browse files
Options
Download
Email Patches
Plain Diff
Remove null-based deck tests for readability
parent
624dea76
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/edu/caltech/cs0/war/DeckTests.java
+11
-12
tests/edu/caltech/cs0/war/DeckTests.java
with
11 additions
and
12 deletions
+11
-12
tests/edu/caltech/cs0/war/DeckTests.java
View file @
05fd1c65
...
...
@@ -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
(
n
ull
);
l
.
add
(
n
ew
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
));
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help