Pārlūkot izejas kodu

test methods covered

Simran Bhutani 6 gadus atpakaļ
vecāks
revīzija
e6ab1ea0ea

+ 0
- 1
src/main/java/io/zipcoder/casino/Casino.java Parādīt failu

@@ -2,7 +2,6 @@ package io.zipcoder.casino;
2 2
 
3 3
 
4 4
 import java.util.ArrayList;
5
-import java.util.InputMismatchException;
6 5
 
7 6
 public class Casino {
8 7
     public boolean running = true;

+ 9
- 2
src/main/java/io/zipcoder/casino/SlotMachine.java Parādīt failu

@@ -3,7 +3,7 @@ package io.zipcoder.casino;
3 3
 import java.util.Random;
4 4
 
5 5
 public class SlotMachine implements Game, Gamble {
6
-    private int betAmount;
6
+    protected int betAmount;
7 7
     private int payoutAmt=0;
8 8
     String word="";
9 9
     String outputword="";
@@ -19,6 +19,7 @@ public class SlotMachine implements Game, Gamble {
19 19
 
20 20
     @Override
21 21
     public void bet(int betAmount) {
22
+
22 23
         this.betAmount= betAmount;
23 24
     }
24 25
 
@@ -47,6 +48,11 @@ public class SlotMachine implements Game, Gamble {
47 48
 
48 49
         Random rand = new Random();
49 50
 
51
+        generateWords(rand);
52
+
53
+    }
54
+
55
+    protected void generateWords(Random rand) {
50 56
         for (int i = 1; i <= 3; i++) {
51 57
             int randnum = rand.nextInt(6);
52 58
 
@@ -79,7 +85,6 @@ public class SlotMachine implements Game, Gamble {
79 85
                 word3 = word;
80 86
             }
81 87
         }
82
-
83 88
     }
84 89
 
85 90
     public void slotResult()
@@ -117,9 +122,11 @@ public class SlotMachine implements Game, Gamble {
117 122
 
118 123
     }
119 124
     public int getPayoutAmt() {
125
+
120 126
         return payoutAmt;
121 127
     }
122 128
     public void setWord1(String word1) {
129
+
123 130
         this.word1 = word1;
124 131
     }
125 132
 

+ 36
- 5
src/test/java/io/zipcoder/casino/SlotTest.java Parādīt failu

@@ -1,20 +1,23 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 
4
+import org.junit.Before;
4 5
 import org.junit.Test;
5 6
 import org.junit.Assert;
6 7
 
8
+import java.util.Random;
9
+
7 10
 
8 11
 public class SlotTest {
12
+    private int betAmount = 10;
13
+    private SlotMachine slotmachine = new SlotMachine(betAmount);
9 14
 
10 15
     @Test
11 16
     public void testSlotResult1(){
12
-        int betAmount=10;
13 17
         String word1="MOUSE";
14 18
         String word2="MOUSE";
15 19
         String word3="MOUSE";
16 20
         //given
17
-        SlotMachine slotmachine = new SlotMachine(betAmount);
18 21
         slotmachine.setWord1(word1);
19 22
         slotmachine.setWord2(word2);
20 23
         slotmachine.setWord3(word3);
@@ -27,15 +30,12 @@ public class SlotTest {
27 30
 
28 31
     @Test
29 32
     public void testSlotResult2(){
30
-        int betAmount=10;
31 33
         String word1="MOUSE";
32 34
         String word2="MOUSE";
33 35
         String word3="CAT";
34 36
 
35 37
 
36 38
         //given
37
-        SlotMachine slotmachine = new SlotMachine(betAmount);
38
-
39 39
         slotmachine.setWord1(word1);
40 40
         slotmachine.setWord2(word2);
41 41
         slotmachine.setWord3(word3);
@@ -65,4 +65,35 @@ public class SlotTest {
65 65
         Assert.assertEquals(0,payout);
66 66
 
67 67
     }
68
+
69
+    @Test
70
+    public void testSetBetAmount(){
71
+        int betAmount=10;
72
+        SlotMachine slotmachine = new SlotMachine(betAmount);
73
+
74
+        int newBet = 40;
75
+
76
+        slotmachine.bet(newBet);
77
+
78
+        int actual = slotmachine.betAmount;
79
+
80
+        Assert.assertEquals(newBet, actual);
81
+
82
+    }
83
+
84
+    @Test
85
+    public void testGenerateWords(){
86
+        Random random = new Random(1);
87
+
88
+
89
+        String expectedWord1 = "SQUIRREL";
90
+        String expectedWord2 = "FISH";
91
+        String expectedWord3 = "CAT";
92
+
93
+        slotmachine.generateWords(random);
94
+
95
+        Assert.assertEquals(expectedWord1, slotmachine.word1);
96
+
97
+    }
98
+
68 99
 }