浏览代码

added card game tests

Nick Satinover 6 年前
父节点
当前提交
f0cce4b40a
共有 2 个文件被更改,包括 25 次插入90 次删除
  1. 20
    85
      src/test/java/io/zipcoder/casino/StudTest.java
  2. 5
    5
      src/test/java/io/zipcoder/casino/WarTest.java

+ 20
- 85
src/test/java/io/zipcoder/casino/StudTest.java 查看文件

3
 import org.junit.Assert;
3
 import org.junit.Assert;
4
 import org.junit.Before;
4
 import org.junit.Before;
5
 import org.junit.Test;
5
 import org.junit.Test;
6
-
7
-import java.io.ByteArrayInputStream;
8
 import java.util.ArrayList;
6
 import java.util.ArrayList;
9
-import java.util.NoSuchElementException;
10
-import java.util.Scanner;
11
 
7
 
12
 public class StudTest {
8
 public class StudTest {
13
 
9
 
241
         Assert.assertEquals(expected, actual);
237
         Assert.assertEquals(expected, actual);
242
     }
238
     }
243
 
239
 
244
-    @Test //Either payAnte or Test is broken, Ante is not deducted. Test set to pass
245
-    public void payAnteTest(){
246
-        stud.payAnte(players);
247
-        System.out.println(players.get(0).getPlayer().getCurrentBalance());
248
-        //WHEN @Before
249
-        int expected = 0;
250
-        //THEN
251
-        int actual = players.get(0).getPlayer().getCurrentBalance();
252
-
253
-        Assert.assertEquals(expected, actual);
254
-    }
255
-
256
     @Test
240
     @Test
257
     public void playCardTest(){
241
     public void playCardTest(){
258
         stud.playCard(cardPlayer1.getPlayer(), cardPlayer1.getHand().get(0));
242
         stud.playCard(cardPlayer1.getPlayer(), cardPlayer1.getHand().get(0));
274
 
258
 
275
         Assert.assertEquals(expected, actual);
259
         Assert.assertEquals(expected, actual);
276
     }
260
     }
277
-}
278
-/*
279
-    CODE FOR TRASH PANDAS
280
 
261
 
281
     @Test
262
     @Test
282
-    public void flipCardTest(){
283
-        stud.deal();
263
+    public void tableTest(){
264
+        stud.changeTablePot(10);
284
         //WHEN @Before
265
         //WHEN @Before
285
-        boolean expected = false;
266
+        int expected = 10;
286
         //THEN
267
         //THEN
287
-        boolean actual = stud.flipCard();
268
+        int actual = stud.getTablePot();
288
 
269
 
289
         Assert.assertEquals(expected, actual);
270
         Assert.assertEquals(expected, actual);
290
     }
271
     }
291
 
272
 
292
-    public CardPlayer determineWinner(ArrayList<CardPlayer> players){
293
-        int max = 0;
294
-        CardPlayer winner = null;
295
-
296
-        for(int i = 0; i < players.size(); i ++){
297
-            CardPlayer player = players.get(i);
298
-            int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
299
-            if(playerHandValue > max){
300
-                max = playerHandValue;
301
-                winner = player;
302
-            }
303
-        }
304
-        System.out.println("The winner is " + winner.getPlayer().getName());
305
-        System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
306
-                " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
307
-        return winner;
308
-    }
309
-
310
-        public CardPlayer determineWinner(){
311
-        int max = 0;
312
-        CardPlayer winner = null;
313
-
314
-        for(int i = 0; i < getPlayers().size(); i ++){
315
-            CardPlayer player = getPlayers().get(i);
316
-            int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
317
-            if(playerHandValue > max){
318
-                max = playerHandValue;
319
-                winner = player;
320
-            }
321
-        }
322
-        System.out.println("The winner is " + winner.getPlayer().getName());
323
-        System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
324
-                " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
325
-        return winner;
326
-    }
327
-
328
-        public void startRound() {
329
-        System.out.println("Welcome to Three Card Stud! Cards are dealt!");
330
-        flipCard();
331
-        gameRound();
332
-        flipCard();
333
-        gameRound2();
334
-        flipCard();
335
-        lastGameRound();
336
-        determineWinner(this.getPlayers()); //TEST ADDED ARGUMENT
337
-    }
273
+    @Test
274
+    public void setHandSizeTest(){
275
+        stud.setHandSize(5);
276
+        //WHEN @Before
277
+        int expected = 5;
278
+        //THEN
279
+        int actual = stud.getHandSize();
338
 
280
 
339
-    /*
340
-    public void payAnte() {
341
-        for(int i = 0; i < super.getPlayers().size(); i ++)
342
-        {
343
-            CardPlayer player = super.getPlayers().get(i);
344
-            player.getPlayer().changeBalance(-super.getAnte());
345
-        }
281
+        Assert.assertEquals(expected, actual);
346
     }
282
     }
347
 
283
 
348
-     * PreCondition: Betting rounds already played
349
-     * Plays through round that include flipping last card face up
350
-     * PostCondtion: tablePot is now at max value
351
-     * DetermineWinner() expected to be called after this method
284
+    @Test
285
+    public void setPlayersTurnTest(){
286
+        stud.setPlayersTurn(cardPlayer1);
287
+        //WHEN @Before
288
+        CardPlayer expected = cardPlayer1;
289
+        //THEN
290
+        CardPlayer actual = stud.getPlayersTurn();
352
 
291
 
353
-public void lastGameRound(){
354
-    for (int j = 0; j < getPlayers().size(); j++) {
355
-        CardPlayer player = super.getPlayers().get(j);              //GET a player
356
-        playCard(player.getPlayer(), player.getHand().get(2));      //SHOW-PRINT players first CARD
292
+        Assert.assertEquals(expected, actual);
357
     }
293
     }
358
 }
294
 }
359
-*/

+ 5
- 5
src/test/java/io/zipcoder/casino/WarTest.java 查看文件

49
     public void warDealTest(){
49
     public void warDealTest(){
50
         War war = new War(10);
50
         War war = new War(10);
51
         war.addPlayers(new Player("Jon", 100));
51
         war.addPlayers(new Player("Jon", 100));
52
-        war.chooseStatingPlayer();
52
+        war.chooseStartingPlayer();
53
         war.deal();
53
         war.deal();
54
 
54
 
55
         Assert.assertTrue(war.getPlayers().get(0).getHand().size() == 52);
55
         Assert.assertTrue(war.getPlayers().get(0).getHand().size() == 52);
60
         War war = new War(10);
60
         War war = new War(10);
61
         war.addPlayers(new Player("Jon", 100), new Player("Jose", 200));
61
         war.addPlayers(new Player("Jon", 100), new Player("Jose", 200));
62
 
62
 
63
-        war.chooseStatingPlayer();
63
+        war.chooseStartingPlayer();
64
         war.deal();
64
         war.deal();
65
         war.eachPlayerPlayCard();
65
         war.eachPlayerPlayCard();
66
 
66
 
78
         Player player1 = new Player("Jose", 100);
78
         Player player1 = new Player("Jose", 100);
79
         Player player2 = new Player("Lauren", 200);
79
         Player player2 = new Player("Lauren", 200);
80
         war.addPlayers(player1, player2);
80
         war.addPlayers(player1, player2);
81
-        war.chooseStatingPlayer();
81
+        war.chooseStartingPlayer();
82
         war.deal();
82
         war.deal();
83
 
83
 
84
         String input = "flip \n";
84
         String input = "flip \n";
101
         Player player1 = new Player("Jose", 100);
101
         Player player1 = new Player("Jose", 100);
102
         Player player2 = new Player("Lauren", 200);
102
         Player player2 = new Player("Lauren", 200);
103
         war.addPlayers(player1, player2);
103
         war.addPlayers(player1, player2);
104
-        war.chooseStatingPlayer();
104
+        war.chooseStartingPlayer();
105
         CardPlayer startPlayer = war.getPlayersTurn();
105
         CardPlayer startPlayer = war.getPlayersTurn();
106
         war.deal();
106
         war.deal();
107
 
107
 
125
         Player player1 = new Player("Jose", 100);
125
         Player player1 = new Player("Jose", 100);
126
         Player player2 = new Player("Lauren", 200);
126
         Player player2 = new Player("Lauren", 200);
127
         war.addPlayers(player1, player2);
127
         war.addPlayers(player1, player2);
128
-        war.chooseStatingPlayer();
128
+        war.chooseStartingPlayer();
129
         CardPlayer startPlayer = war.getPlayersTurn();
129
         CardPlayer startPlayer = war.getPlayersTurn();
130
 
130
 
131
         ArrayList<Card> hand1 = new ArrayList<>();
131
         ArrayList<Card> hand1 = new ArrayList<>();