Pārlūkot izejas kodu

tests fixed, highlow fixed

yauhenip 6 gadus atpakaļ
vecāks
revīzija
e5880aeefa

+ 3
- 8
pom.xml Parādīt failu

@@ -9,16 +9,11 @@
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11 11
     <dependencies>
12
-        <!-- https://mvnrepository.com/artifact/junit/junit -->
13
-        <!-- https://mvnrepository.com/artifact/junit/junit -->
14 12
         <dependency>
15
-            <groupId>junit</groupId>
16
-            <artifactId>junit</artifactId>
17
-            <version>3.8.1</version>
13
+            <groupId>org.junit.jupiter</groupId>
14
+            <artifactId>junit-jupiter-api</artifactId>
15
+            <version>5.2.0</version>
18 16
             <scope>test</scope>
19 17
         </dependency>
20
-
21
-
22
-
23 18
     </dependencies>
24 19
 </project>

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

@@ -321,4 +321,3 @@ public class BlackJack {
321 321
         }
322 322
     }
323 323
 }
324
->>>>>>> newblackjack

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

@@ -18,9 +18,9 @@ public abstract class DiceGame implements Gamble, Game{
18 18
 
19 19
     public abstract int rollDice();
20 20
 
21
-    public abstract void winBet();
21
+    public abstract void winBet(int currentBet);
22 22
 
23
-    public abstract void loseBet();
23
+    public abstract void loseBet(int currentBet);
24 24
 
25 25
     public abstract void declareWinner();
26 26
 }

+ 8
- 4
src/main/java/io/zipcoder/casino/HighLow.java Parādīt failu

@@ -32,6 +32,10 @@ public class HighLow extends DiceGame{
32 32
         return wager;
33 33
     }
34 34
 
35
+    public void bet(int bet) {
36
+
37
+    }
38
+
35 39
     public String makeBet() {
36 40
         betCondition = Console.askForInput("What are you betting on?  (H / L / 7)");
37 41
         if (betCondition.toLowerCase().equals("h") ||
@@ -55,9 +59,9 @@ public class HighLow extends DiceGame{
55 59
                 (betCondition.toUpperCase().equals("L") && rolledDiceResult <  7) ||
56 60
                 (betCondition.toUpperCase().equals("7") && rolledDiceResult == 7)) {
57 61
             winnings = rolledDiceResult == 7 ? this.totalBet * 4 : this.totalBet * 2;
58
-            winBet();
62
+            winBet(winnings);
59 63
         } else {
60
-            loseBet();
64
+            loseBet(winnings);
61 65
         }
62 66
     }
63 67
 
@@ -76,12 +80,12 @@ public class HighLow extends DiceGame{
76 80
         return askToContinue();
77 81
     }
78 82
 
79
-    public void winBet() {
83
+    public void winBet(int winnings) {
80 84
         player.addToBankroll(winnings);
81 85
         Console.output("You won " + winnings);
82 86
     }
83 87
 
84
-    public void loseBet() {
88
+    public void loseBet(int bet) {
85 89
         Console.output("You lost :(");
86 90
     }
87 91
 

+ 1
- 2
src/test/java/io/zipcoder/casino/BlackJackTest.java Parādīt failu

@@ -1,8 +1,7 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
-import org.junit.jupiter.api.Test;
4 3
 
5
-import static org.junit.jupiter.api.Assertions.*;
4
+import org.junit.jupiter.api.Test;
6 5
 
7 6
 class BlackJackTest {
8 7
 

+ 7
- 49
src/test/java/io/zipcoder/casino/DiceTest.java Parādīt failu

@@ -1,51 +1,10 @@
1
- HEAD
2 1
 package io.zipcoder.casino;
3 2
 
4
-import org.junit.Assert;
5
-import org.junit.Before;
6
-import org.junit.Test;
7 3
 
4
+import org.junit.jupiter.api.Assertions;
5
+import org.junit.jupiter.api.Test;
8 6
 
9
-public class DiceTest {
10
-
11
-    @Test
12
-    public void getSum1(){
13
-        Dice dice = new Dice(2);
14
-        int expected = 6;
15
-        int actual = dice.getSum();
16
-        Assert.assertEquals(expected, actual, 6);
17
-    }
18
-
19
-    @Test
20
-    public void getSum2(){
21
-        Dice dice = new Dice(5);
22
-        int expected = 13;
23
-        int actual = dice.getSum();
24
-        Assert.assertEquals(expected, actual, 12);
25
-    }
26
-
27
-    @Test
28
-    public void getEach1(){
29
-        Dice dice = new Dice(2);
30
-        int expected = 3;
31
-        int actual = dice.getEach()[1];
32
-        Assert.assertEquals(expected, actual, 3);
33
-    }
34
-
35
-    @Test
36
-    public void getEach2(){
37
-        Dice dice = new Dice(6);
38
-        int expected = 3;
39
-        int actual = dice.getEach()[3];
40
-        Assert.assertEquals(expected, actual, 3);
41
-    }
42
-}
43
-=======
44
-package io.zipcoder.casino;
45
-
46
-import org.junit.Assert;
47
-import org.junit.Before;
48
-import org.junit.Test;
7
+import static org.junit.jupiter.api.Assertions.assertEquals;
49 8
 
50 9
 public class DiceTest {
51 10
 
@@ -54,7 +13,7 @@ public class DiceTest {
54 13
         Dice dice = new Dice(2);
55 14
         int expected = 6;
56 15
         int actual = dice.getSum();
57
-        Assert.assertEquals(expected, actual, 6);
16
+        assertEquals(expected, actual, 6);
58 17
     }
59 18
 
60 19
     @Test
@@ -62,7 +21,7 @@ public class DiceTest {
62 21
         Dice dice = new Dice(5);
63 22
         int expected = 13;
64 23
         int actual = dice.getSum();
65
-        Assert.assertEquals(expected, actual, 12);
24
+        assertEquals(expected, actual, 12);
66 25
     }
67 26
 
68 27
     @Test
@@ -70,7 +29,7 @@ public class DiceTest {
70 29
         Dice dice = new Dice(2);
71 30
         int expected = 3;
72 31
         int actual = dice.getEach()[1];
73
-        Assert.assertEquals(expected, actual, 3);
32
+        assertEquals(expected, actual, 3);
74 33
     }
75 34
 
76 35
     @Test
@@ -78,7 +37,6 @@ public class DiceTest {
78 37
         Dice dice = new Dice(6);
79 38
         int expected = 3;
80 39
         int actual = dice.getEach()[3];
81
-        Assert.assertEquals(expected, actual, 3);
40
+        assertEquals(expected, actual, 3);
82 41
     }
83 42
 }
84
->>>>>>> origin/dev

+ 29
- 3
src/test/java/io/zipcoder/casino/HighLowTest.java Parādīt failu

@@ -1,7 +1,9 @@
1 1
 package io.zipcoder.casino;
2 2
 
3
-import org.junit.Assert;
4
-import org.junit.Test;
3
+
4
+import org.junit.jupiter.api.Test;
5
+
6
+import static org.junit.jupiter.api.Assertions.assertEquals;
5 7
 
6 8
 public class HighLowTest {
7 9
 
@@ -12,8 +14,32 @@ public class HighLowTest {
12 14
     public void rollDice1(){
13 15
         int expected = 6;
14 16
         int actual = game.rollDice();
15
-        Assert.assertEquals(expected, actual, 6);
17
+        assertEquals(expected, actual, 6);
16 18
     }
17 19
 
20
+    @Test
21
+    public void askForWager() {
22
+        int expected = 10;
23
+
24
+        int wager = 0;
25
+        boolean flag = true;
26
+        Console.output("Current bankroll: " + this.player.getBankroll());
27
+        while (flag) {
28
+            try {
29
+                wager = 10;
30
+                if (wager <= 0 || wager > this.player.getBankroll()) {
31
+                    Console.output("Wrong input! Try again!");
32
+                } else {
33
+                    flag = false;
34
+                }
35
+            } catch(NumberFormatException e) {
36
+                Console.output("Wrong input! Try again!");
37
+            }
38
+        }
39
+        this.player.subtractFromBankroll(wager);
40
+        int actual = wager;
41
+
42
+        assertEquals(expected, actual);
43
+    }
18 44
 
19 45
 }