Browse Source

test methods covered

Simran Bhutani 6 years ago
parent
commit
e6ab1ea0ea

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

2
 
2
 
3
 
3
 
4
 import java.util.ArrayList;
4
 import java.util.ArrayList;
5
-import java.util.InputMismatchException;
6
 
5
 
7
 public class Casino {
6
 public class Casino {
8
     public boolean running = true;
7
     public boolean running = true;

+ 9
- 2
src/main/java/io/zipcoder/casino/SlotMachine.java View File

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

+ 36
- 5
src/test/java/io/zipcoder/casino/SlotTest.java View File

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
 
3
 
4
+import org.junit.Before;
4
 import org.junit.Test;
5
 import org.junit.Test;
5
 import org.junit.Assert;
6
 import org.junit.Assert;
6
 
7
 
8
+import java.util.Random;
9
+
7
 
10
 
8
 public class SlotTest {
11
 public class SlotTest {
12
+    private int betAmount = 10;
13
+    private SlotMachine slotmachine = new SlotMachine(betAmount);
9
 
14
 
10
     @Test
15
     @Test
11
     public void testSlotResult1(){
16
     public void testSlotResult1(){
12
-        int betAmount=10;
13
         String word1="MOUSE";
17
         String word1="MOUSE";
14
         String word2="MOUSE";
18
         String word2="MOUSE";
15
         String word3="MOUSE";
19
         String word3="MOUSE";
16
         //given
20
         //given
17
-        SlotMachine slotmachine = new SlotMachine(betAmount);
18
         slotmachine.setWord1(word1);
21
         slotmachine.setWord1(word1);
19
         slotmachine.setWord2(word2);
22
         slotmachine.setWord2(word2);
20
         slotmachine.setWord3(word3);
23
         slotmachine.setWord3(word3);
27
 
30
 
28
     @Test
31
     @Test
29
     public void testSlotResult2(){
32
     public void testSlotResult2(){
30
-        int betAmount=10;
31
         String word1="MOUSE";
33
         String word1="MOUSE";
32
         String word2="MOUSE";
34
         String word2="MOUSE";
33
         String word3="CAT";
35
         String word3="CAT";
34
 
36
 
35
 
37
 
36
         //given
38
         //given
37
-        SlotMachine slotmachine = new SlotMachine(betAmount);
38
-
39
         slotmachine.setWord1(word1);
39
         slotmachine.setWord1(word1);
40
         slotmachine.setWord2(word2);
40
         slotmachine.setWord2(word2);
41
         slotmachine.setWord3(word3);
41
         slotmachine.setWord3(word3);
65
         Assert.assertEquals(0,payout);
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
 }