Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sp21-cs242-assignment1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xinyupi2
sp21-cs242-assignment1
Commits
ade9f4e7
Commit
ade9f4e7
authored
4 years ago
by
FrederickPi1969
Browse files
Options
Downloads
Patches
Plain Diff
Add test for card manager
parent
3201c4c8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.idea/uiDesigner.xml
+124
-0
124 additions, 0 deletions
.idea/uiDesigner.xml
out/test/sp21-cs242-assignment1/cardDealTest.class
+0
-0
0 additions, 0 deletions
out/test/sp21-cs242-assignment1/cardDealTest.class
src/Test/cardDealTest.java
+110
-0
110 additions, 0 deletions
src/Test/cardDealTest.java
with
234 additions
and
0 deletions
.idea/uiDesigner.xml
0 → 100644
+
124
−
0
View file @
ade9f4e7
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"Palette2"
>
<group
name=
"Swing"
>
<item
class=
"com.intellij.uiDesigner.HSpacer"
tooltip-text=
"Horizontal Spacer"
icon=
"/com/intellij/uiDesigner/icons/hspacer.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"1"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"com.intellij.uiDesigner.VSpacer"
tooltip-text=
"Vertical Spacer"
icon=
"/com/intellij/uiDesigner/icons/vspacer.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"1"
anchor=
"0"
fill=
"2"
/>
</item>
<item
class=
"javax.swing.JPanel"
icon=
"/com/intellij/uiDesigner/icons/panel.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JScrollPane"
icon=
"/com/intellij/uiDesigner/icons/scrollPane.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"7"
hsize-policy=
"7"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JButton"
icon=
"/com/intellij/uiDesigner/icons/button.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"0"
fill=
"1"
/>
<initial-values>
<property
name=
"text"
value=
"Button"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JRadioButton"
icon=
"/com/intellij/uiDesigner/icons/radioButton.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"RadioButton"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JCheckBox"
icon=
"/com/intellij/uiDesigner/icons/checkBox.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"3"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"CheckBox"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JLabel"
icon=
"/com/intellij/uiDesigner/icons/label.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"8"
fill=
"0"
/>
<initial-values>
<property
name=
"text"
value=
"Label"
/>
</initial-values>
</item>
<item
class=
"javax.swing.JTextField"
icon=
"/com/intellij/uiDesigner/icons/textField.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JPasswordField"
icon=
"/com/intellij/uiDesigner/icons/passwordField.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JFormattedTextField"
icon=
"/com/intellij/uiDesigner/icons/formattedTextField.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
>
<preferred-size
width=
"150"
height=
"-1"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTextArea"
icon=
"/com/intellij/uiDesigner/icons/textArea.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTextPane"
icon=
"/com/intellij/uiDesigner/icons/textPane.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JEditorPane"
icon=
"/com/intellij/uiDesigner/icons/editorPane.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JComboBox"
icon=
"/com/intellij/uiDesigner/icons/comboBox.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"2"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JTable"
icon=
"/com/intellij/uiDesigner/icons/table.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JList"
icon=
"/com/intellij/uiDesigner/icons/list.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"2"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTree"
icon=
"/com/intellij/uiDesigner/icons/tree.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"150"
height=
"50"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JTabbedPane"
icon=
"/com/intellij/uiDesigner/icons/tabbedPane.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"200"
height=
"200"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JSplitPane"
icon=
"/com/intellij/uiDesigner/icons/splitPane.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
>
<preferred-size
width=
"200"
height=
"200"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JSpinner"
icon=
"/com/intellij/uiDesigner/icons/spinner.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"true"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JSlider"
icon=
"/com/intellij/uiDesigner/icons/slider.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"8"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JSeparator"
icon=
"/com/intellij/uiDesigner/icons/separator.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"6"
anchor=
"0"
fill=
"3"
/>
</item>
<item
class=
"javax.swing.JProgressBar"
icon=
"/com/intellij/uiDesigner/icons/progressbar.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JToolBar"
icon=
"/com/intellij/uiDesigner/icons/toolbar.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"6"
anchor=
"0"
fill=
"1"
>
<preferred-size
width=
"-1"
height=
"20"
/>
</default-constraints>
</item>
<item
class=
"javax.swing.JToolBar$Separator"
icon=
"/com/intellij/uiDesigner/icons/toolbarSeparator.png"
removable=
"false"
auto-create-binding=
"false"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"0"
fill=
"1"
/>
</item>
<item
class=
"javax.swing.JScrollBar"
icon=
"/com/intellij/uiDesigner/icons/scrollbar.png"
removable=
"false"
auto-create-binding=
"true"
can-attach-label=
"false"
>
<default-constraints
vsize-policy=
"6"
hsize-policy=
"0"
anchor=
"0"
fill=
"2"
/>
</item>
</group>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
out/test/sp21-cs242-assignment1/cardDealTest.class
0 → 100644
+
0
−
0
View file @
ade9f4e7
File added
This diff is collapsed.
Click to expand it.
src/Test/cardDealTest.java
0 → 100644
+
110
−
0
View file @
ade9f4e7
import
org.junit.jupiter.api.Test
;
import
java.util.ArrayList
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
/**
* These testcases test behavior of many functions, includes
* 1. All functions in CardManager
* 2. Interaction between Game and CardManager
* 3. Player.{drawCards, playOneRound}
*/
class
cardDealTest
{
@Test
/**
* Test card manager can initialize 108 cards correctly
*/
void
testInitialization
()
throws
Exception
{
CardManager
cardManager
=
new
CardManager
();
assert
(
cardManager
.
getCardPile
().
size
()
==
108
);
for
(
int
i
=
1
;
i
<=
108
;
i
++)
{
assert
(
cardManager
.
getCardPile
().
contains
(
i
));
}
}
@Test
/**
* Given n players, test behavior of initial deal, as well as behavior of draw pile
* dependencies: Player.drawCards, CardManager.*
*/
void
testInitialDeal
()
throws
Exception
{
Game
game1
=
new
Game
(
1
);
for
(
Player
p
:
game1
.
players
)
{
assert
(
p
.
getCards
().
size
()
==
7
);
}
assert
(
game1
.
gameCardManager
.
numCardLeft
()
==
101
);
// 108 - 7
Game
game2
=
new
Game
(
5
);
for
(
Player
p
:
game2
.
players
)
{
assert
(
p
.
getCards
().
size
()
==
7
);
}
assert
(
game2
.
gameCardManager
.
numCardLeft
()
==
73
);
// 108 - 35
Game
game3
=
new
Game
(
10
);
for
(
Player
p
:
game3
.
players
)
{
assert
(
p
.
getCards
().
size
()
==
7
);
}
assert
(
game3
.
gameCardManager
.
numCardLeft
()
==
38
);
// 108 - 70
}
@Test
/**
* Test the behavior of Player.drawCards
* under the condition where draw pile is not enough to draw, should draw from discard pile instead
* case 1: completely draw from discard pile
*/
void
testDrawFromDiscardWhenDrawNotEnough_Case1
()
throws
Exception
{
Game
game
=
new
Game
(
1
);
Player
player
=
game
.
players
.
get
(
0
);
ArrayList
<
Integer
>
cards
=
player
.
getCards
();
// direct reference to player's card
player
.
drawCards
(
game
.
gameCardManager
.
numCardLeft
());
// get all cards in draw pile
assert
(
game
.
gameCardManager
.
numCardLeft
()
==
0
);
// move 30 cards from players' to discard
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
int
cardID
=
cards
.
get
(
0
);
cards
.
remove
(
0
);
game
.
gameCardManager
.
insertOneCardToDiscardPile
(
cardID
);
}
assert
(
game
.
gameCardManager
.
numLeftDiscardPile
()
==
30
);
// then drawCards
player
.
drawCards
(
4
);
assert
(
game
.
gameCardManager
.
numLeftDiscardPile
()
==
26
);
}
@Test
/**
* Test the behavior of Player.drawCards
* under the condition where draw pile is not enough to draw, should draw from discard pile instead
* case 2: partially from draw pile, partially from discard pile
*/
void
testDrawFromDiscardWhenDrawNotEnough_Case2
()
throws
Exception
{
Game
game
=
new
Game
(
1
);
Player
player
=
game
.
players
.
get
(
0
);
ArrayList
<
Integer
>
cards
=
player
.
getCards
();
// direct reference to player's card
player
.
drawCards
(
game
.
gameCardManager
.
numCardLeft
()
-
2
);
// get 99 cards from draw pile
assert
(
game
.
gameCardManager
.
numCardLeft
()
==
2
);
// move 30 cards from players' to discard
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
int
cardID
=
cards
.
get
(
0
);
cards
.
remove
(
0
);
game
.
gameCardManager
.
insertOneCardToDiscardPile
(
cardID
);
}
assert
(
game
.
gameCardManager
.
numLeftDiscardPile
()
==
30
);
// 2 from discard, 2 from draw
player
.
drawCards
(
4
);
assert
(
game
.
gameCardManager
.
numCardLeft
()
==
0
);
assert
(
game
.
gameCardManager
.
numLeftDiscardPile
()
==
28
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment