Browse Source

Slot tests

Lauren Green 6 years ago
parent
commit
3b592cab61

+ 16
- 11
src/main/java/io/zipcoder/casino/SlotMachine.java View File

@@ -41,14 +41,7 @@ public class SlotMachine implements Game, Gamble {
41 41
         }
42 42
         Printer.printMessage("Your slot is in progress" + "\n");
43 43
 
44
-        try {
45
-            Thread.sleep(3000);
46
-        } catch (InterruptedException e) {
47
-            e.printStackTrace();
48
-        }
49
-
50
-        generateWords();
51
-
44
+        startRound();
52 45
     }
53 46
 
54 47
     public void generateWords() {
@@ -94,18 +87,18 @@ public class SlotMachine implements Game, Gamble {
94 87
             if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
95 88
 
96 89
                 outputword= outputword + "\n"+" You have won $0";
97
-                payoutAmt=0;
90
+                setPayoutAmt(0);
98 91
             }
99 92
             else if( (word1.equals(word2) && (!word1.equals(word3))) || ((word1.equals(word3)) && (!word1.equals(word2))) || ((word2.equals(word3)) && (!word2.equals(word1)))){
100 93
 
101 94
                 outputword= outputword + "\n" +" You have won $" + (betAmount*2);
102
-                payoutAmt=betAmount*2;
95
+                setPayoutAmt(betAmount*2);
103 96
             }
104 97
 
105 98
 
106 99
             else if(word1.equals(word2) && word1.equals(word3)) {
107 100
                 outputword= outputword + "\n" + "You have won $" + (betAmount*3);
108
-                payoutAmt=betAmount*3;
101
+                setPayoutAmt(betAmount*3);
109 102
             }
110 103
 
111 104
             Printer.printMessage(( outputword + "\n" ));
@@ -119,11 +112,23 @@ public class SlotMachine implements Game, Gamble {
119 112
 
120 113
     @Override
121 114
     public void startRound() {
115
+        try {
116
+            Thread.sleep(3000);
117
+        } catch (InterruptedException e) {
118
+            e.printStackTrace();
119
+        }
122 120
 
121
+        generateWords();
123 122
     }
123
+
124 124
     public int getPayoutAmt() {
125 125
         return payoutAmt;
126 126
     }
127
+
128
+    public void setPayoutAmt(int payoutAmt) {
129
+        this.payoutAmt = payoutAmt;
130
+    }
131
+
127 132
     public void setWord1(String word1) {
128 133
         this.word1 = word1;
129 134
     }

+ 18
- 0
src/test/java/io/zipcoder/casino/SlotTest.java View File

@@ -98,4 +98,22 @@ public class SlotTest {
98 98
 
99 99
 
100 100
     }
101
+
102
+    @Test
103
+    public void testPayout() {
104
+        //Given
105
+        SlotMachine game = new SlotMachine(100, player);
106
+        int expected = 500;
107
+
108
+        //When
109
+        game.bet(100);
110
+        game.setPayoutAmt(200);
111
+        game.payout();
112
+        int actual = game.getPlayer().getCurrentBalance();
113
+
114
+        //Then
115
+        Assert.assertEquals(expected, actual);
116
+
117
+
118
+    }
101 119
 }