Browse Source

Tests written for Yahtzee Class

Lauren Green 6 years ago
parent
commit
900126e38f

+ 1
- 1
src/main/java/io/zipcoder/casino/Game.java View File

@@ -1,7 +1,7 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 public interface Game {
4
-     void quit();
4
+
5 5
      void startGame();
6 6
      void startRound();
7 7
 }

+ 0
- 4
src/main/java/io/zipcoder/casino/SlotMachine.java View File

@@ -29,10 +29,6 @@ public class SlotMachine implements Game, Gamble {
29 29
 
30 30
     // implementd from game
31 31
 
32
-    @Override
33
-    public void quit() {
34
-
35
-    }
36 32
 
37 33
     @Override
38 34
     public void startGame() {

+ 0
- 3
src/main/java/io/zipcoder/casino/War.java View File

@@ -137,9 +137,6 @@ public class War extends CardGame implements Gamble, Game {
137 137
      * Below 3 Implemented from Game
138 138
      */
139 139
 
140
-    public void quit() {
141
-
142
-    }
143 140
 
144 141
     public void startGame() {
145 142
         System.out.println("Welcome to war!");

+ 10
- 17
src/main/java/io/zipcoder/casino/Yahtzee.java View File

@@ -43,22 +43,26 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
43 43
         for (int i = 0; i < ScoreSheet.getSize(); i++) {
44 44
             rollAll();
45 45
             for(int j = 0; j < 2; j++) {
46
-                int choice = console.getIntFromUser("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.\nNumber of Selection: ");
47
-                rollOptions(choice); }
46
+                int rollChoice = console.getIntFromUser("Would you like to:\n1. Roll all dice again.\n2. Roll some dice again.\n3. Stop rolling and score.\nNumber of Selection: ");
47
+                String diceToRoll = "";
48
+                if(rollChoice == 2) {
49
+                    diceToRoll = console.getLineFromUser("Which numbers would you like to reroll? List the numbers separated by spaces.");
50
+                }
51
+                rollOptions(rollChoice, diceToRoll); }
48 52
 
49 53
             boolean validEntry = false;
50 54
             ScoreSheet.ROW row = ScoreSheet.ROW.CHANCE;
51 55
             while (!validEntry) {
52 56
                 Printer.printMessage(dicePlayer.getScoreSheet().scoreCardToString());
53 57
 
54
-                int choice = console.getIntFromUser("Which row would you like to apply your turn to on the scoresheet?.\n" +
58
+                int rowChoice = console.getIntFromUser("Which row would you like to apply your turn to on the scoresheet?.\n" +
55 59
                         "Remember you can only use each row once!");
56
-                row = selectingRow(choice);
60
+
61
+                row = selectingRow(rowChoice);
57 62
                 validEntry = checkEmptyRow(row);
58 63
             }
59 64
             dicePlayer.getScoreSheet().setRow(row, dicePlayer.getCup());
60 65
             Printer.printMessage("\n" + dicePlayer.getScoreSheet().scoreCardToString());
61
-
62 66
         }
63 67
 
64 68
     }
@@ -71,7 +75,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
71 75
     }
72 76
 
73 77
 
74
-    public void rollOptions(int choice) {
78
+    public void rollOptions(int choice, String diceToRoll) {
75 79
 
76 80
         switch (choice) {
77 81
             case 1:
@@ -79,7 +83,6 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
79 83
                 break;
80 84
 
81 85
             case 2:
82
-                String diceToRoll = console.getLineFromUser("Which numbers would you like to reroll? List the numbers separated by spaces.");
83 86
                 reRoll(diceToRoll);
84 87
                 break;
85 88
 
@@ -180,14 +183,8 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
180 183
         int payOut = 0;
181 184
         if (score == 1575) {
182 185
             payOut = getBid() * 100;
183
-        } else if (score > 1000) {
184
-            payOut = getBid() * 20;
185 186
         } else if (score > 500) {
186 187
             payOut = getBid() * 10;
187
-        } else if (score > 400) {
188
-            payOut = getBid() * 5;
189
-        } else if (score > 300) {
190
-            payOut = getBid() * 3;
191 188
         } else if (score > 200) {
192 189
             payOut = getBid() * 2;
193 190
         } else {
@@ -197,10 +194,6 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
197 194
         Printer.printMessage("You won $" + payOut);
198 195
     }
199 196
 
200
-    @Override
201
-    public void quit() {
202
-
203
-    }
204 197
 
205 198
     public DicePlayer getDicePlayer() {
206 199
         return dicePlayer;

+ 157
- 3
src/test/java/io/zipcoder/casino/YahtzeeTest.java View File

@@ -50,7 +50,7 @@ public class YahtzeeTest {
50 50
         //When
51 51
         yahtzee.startGame();
52 52
         String expected = yahtzee.getDicePlayer().cupToString();
53
-        yahtzee.rollOptions(3);
53
+        yahtzee.rollOptions(3, "");
54 54
         String actual = yahtzee.getDicePlayer().cupToString();
55 55
 
56 56
         //Then
@@ -64,7 +64,7 @@ public class YahtzeeTest {
64 64
         //When
65 65
         yahtzee.startGame();
66 66
         String expected = yahtzee.getDicePlayer().cupToString();
67
-        yahtzee.rollOptions(1);
67
+        yahtzee.rollOptions(1, "");
68 68
         String actual = yahtzee.getDicePlayer().cupToString();
69 69
 
70 70
         //Then
@@ -79,7 +79,7 @@ public class YahtzeeTest {
79 79
         yahtzee.startGame();
80 80
         int diceOneValue = yahtzee.getDicePlayer().getCup()[0].getValue();
81 81
         int diceTwoValue = yahtzee.getDicePlayer().getCup()[1].getValue();
82
-        yahtzee.reRoll(Integer.toString(diceTwoValue));
82
+        yahtzee.rollOptions(2, Integer.toString(diceTwoValue));
83 83
         int actual = yahtzee.getDicePlayer().getCup()[0].getValue();
84 84
 
85 85
         //Then
@@ -112,5 +112,159 @@ public class YahtzeeTest {
112 112
 
113 113
     }
114 114
 
115
+    @Test
116
+    public void testPayout() {
117
+        //When
118
+        int expected = yahtzee.getDicePlayer().getPlayer().getCurrentBalance();
119
+        yahtzee.payout();
120
+        int actual = yahtzee.getDicePlayer().getPlayer().getCurrentBalance();
121
+
122
+        //Then
123
+        Assert.assertEquals(expected, actual);
124
+
125
+    }
126
+
127
+
128
+    @Test
129
+    public void testSelectingRow1() {
130
+        //When
131
+        ScoreSheet.ROW expected = ScoreSheet.ROW.ACES;
132
+        ScoreSheet.ROW actual = yahtzee.selectingRow(1);
133
+
134
+        //Then
135
+        Assert.assertEquals(expected, actual);
136
+
137
+    }
138
+
139
+    @Test
140
+    public void testSelectingRow2() {
141
+        //When
142
+        ScoreSheet.ROW expected = ScoreSheet.ROW.TWOS;
143
+        ScoreSheet.ROW actual = yahtzee.selectingRow(2);
144
+
145
+        //Then
146
+        Assert.assertEquals(expected, actual);
147
+
148
+    }
149
+
150
+    @Test
151
+    public void testSelectingRow3() {
152
+        //When
153
+        ScoreSheet.ROW expected = ScoreSheet.ROW.THREES;
154
+        ScoreSheet.ROW actual = yahtzee.selectingRow(3);
155
+
156
+        //Then
157
+        Assert.assertEquals(expected, actual);
158
+
159
+    }
160
+
161
+    @Test
162
+    public void testSelectingRow4() {
163
+        //When
164
+        ScoreSheet.ROW expected = ScoreSheet.ROW.FOURS;
165
+        ScoreSheet.ROW actual = yahtzee.selectingRow(4);
166
+
167
+        //Then
168
+        Assert.assertEquals(expected, actual);
169
+
170
+    }
171
+
172
+    @Test
173
+    public void testSelectingRow5() {
174
+        //When
175
+        ScoreSheet.ROW expected = ScoreSheet.ROW.FIVES;
176
+        ScoreSheet.ROW actual = yahtzee.selectingRow(5);
177
+
178
+        //Then
179
+        Assert.assertEquals(expected, actual);
180
+
181
+    }
182
+
183
+    @Test
184
+    public void testSelectingRow6() {
185
+        //When
186
+        ScoreSheet.ROW expected = ScoreSheet.ROW.SIXES;
187
+        ScoreSheet.ROW actual = yahtzee.selectingRow(6);
188
+
189
+        //Then
190
+        Assert.assertEquals(expected, actual);
191
+
192
+    }
115 193
 
194
+    @Test
195
+    public void testSelectingRow7() {
196
+        //When
197
+        ScoreSheet.ROW expected = ScoreSheet.ROW.THREEOFAKIND;
198
+        ScoreSheet.ROW actual = yahtzee.selectingRow(7);
199
+
200
+        //Then
201
+        Assert.assertEquals(expected, actual);
202
+
203
+    }
204
+
205
+    @Test
206
+    public void testSelectingRow8() {
207
+        //When
208
+        ScoreSheet.ROW expected = ScoreSheet.ROW.FOUROFAKIND;
209
+        ScoreSheet.ROW actual = yahtzee.selectingRow(8);
210
+
211
+        //Then
212
+        Assert.assertEquals(expected, actual);
213
+
214
+    }
215
+
216
+    @Test
217
+    public void testSelectingRow9() {
218
+        //When
219
+        ScoreSheet.ROW expected = ScoreSheet.ROW.FULLHOUSE;
220
+        ScoreSheet.ROW actual = yahtzee.selectingRow(9);
221
+
222
+        //Then
223
+        Assert.assertEquals(expected, actual);
224
+
225
+    }
226
+
227
+    @Test
228
+    public void testSelectingRow10() {
229
+        //When
230
+        ScoreSheet.ROW expected = ScoreSheet.ROW.SMALLSTRAIGHT;
231
+        ScoreSheet.ROW actual = yahtzee.selectingRow(10);
232
+
233
+        //Then
234
+        Assert.assertEquals(expected, actual);
235
+
236
+    }
237
+
238
+    @Test
239
+    public void testSelectingRow11() {
240
+        //When
241
+        ScoreSheet.ROW expected = ScoreSheet.ROW.LARGESTRAIGHT;
242
+        ScoreSheet.ROW actual = yahtzee.selectingRow(11);
243
+
244
+        //Then
245
+        Assert.assertEquals(expected, actual);
246
+
247
+    }
248
+
249
+    @Test
250
+    public void testSelectingRow12() {
251
+        //When
252
+        ScoreSheet.ROW expected = ScoreSheet.ROW.YAHTZEE;
253
+        ScoreSheet.ROW actual = yahtzee.selectingRow(12);
254
+
255
+        //Then
256
+        Assert.assertEquals(expected, actual);
257
+
258
+    }
259
+
260
+    @Test
261
+    public void testSelectingRow13() {
262
+        //When
263
+        ScoreSheet.ROW expected = ScoreSheet.ROW.CHANCE;
264
+        ScoreSheet.ROW actual = yahtzee.selectingRow(13);
265
+
266
+        //Then
267
+        Assert.assertEquals(expected, actual);
268
+
269
+    }
116 270
 }