diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000000000000000000000000000000000000..b93ac08bcd0212375c3de0db5157d536abc599e9 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ +<?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 diff --git a/out/test/sp21-cs242-assignment1/cardDealTest.class b/out/test/sp21-cs242-assignment1/cardDealTest.class new file mode 100644 index 0000000000000000000000000000000000000000..33cd2ce1b1236cb0a8e86a00b7ae092483bc6674 Binary files /dev/null and b/out/test/sp21-cs242-assignment1/cardDealTest.class differ diff --git a/src/Test/cardDealTest.java b/src/Test/cardDealTest.java new file mode 100644 index 0000000000000000000000000000000000000000..130070a1c3f65a0eb7fc48b8fb8aed5ce92e7d11 --- /dev/null +++ b/src/Test/cardDealTest.java @@ -0,0 +1,110 @@ +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