Katrice Williams-Dredden 6 vuotta sitten
vanhempi
commit
2736adcfd6
5 muutettua tiedostoa jossa 71 lisäystä ja 26 poistoa
  1. 3
    5
      pom.xml
  2. 27
    11
      src/main/java/Bins.java
  3. 15
    0
      src/main/java/BinsTest.java
  4. 1
    1
      src/main/java/Dice.java
  5. 25
    9
      src/main/java/DiceTest.java

+ 3
- 5
pom.xml Näytä tiedosto

@@ -9,11 +9,9 @@
9 9
     <version>1.0-SNAPSHOT</version>
10 10
     <dependencies>
11 11
         <dependency>
12
-            <groupId>org.junit.jupiter</groupId>
13
-            <artifactId>junit-jupiter-api</artifactId>
14
-            <version>RELEASE</version>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>4.12</version>
15 15
         </dependency>
16 16
     </dependencies>
17
-
18
-
19 17
 </project>

+ 27
- 11
src/main/java/Bins.java Näytä tiedosto

@@ -1,16 +1,32 @@
1
+import java.util.TreeMap;
1 2
 
2 3
 public class Bins {
4
+    //The treemap will hold the starting roll, and the ending roll
5
+    private TreeMap<Integer, Integer> sumOfRollsMap;
6
+    private Integer startingRoll;
7
+    private Integer endingRoll;
3 8
 
9
+    //the constructor
10
+    public Bins(Integer startingRoll, Integer endingRoll){
11
+        sumOfRollsMap = new TreeMap<Integer, Integer>();
12
+    }
4 13
 
5
-//    private int startingBound;
6
-//    private int endingBound;
7
-//
8
-//    private int[] rollSums;
9
-//
10
-//
11
-//
12
-//
13
-//    public Bins(int startingBound, int endingBound) {
14
-//        sumOfRolls = new int[endingBound+1];
15
-//    }
14
+    //methods
15
+    public int getBin(Integer val){
16
+        if(sumOfRollsMap.containsKey(val)){
17
+            return sumOfRollsMap.get(val);
18
+        }
19
+        return 0;
20
+    }
21
+
22
+    public void addToBin(Integer val) {
23
+        if (sumOfRollsMap.containsKey(val)) {
24
+            int currentSum = sumOfRollsMap.get(val);
25
+            sumOfRollsMap.put(startingRoll, currentSum + 1);
26
+        } else {
27
+            sumOfRollsMap.put(val, 1);
28
+        }
29
+
30
+
31
+    }
16 32
 }

+ 15
- 0
src/main/java/BinsTest.java Näytä tiedosto

@@ -0,0 +1,15 @@
1
+import org.junit.Test;
2
+
3
+import static org.junit.Assert.*;
4
+
5
+public class BinsTest {
6
+
7
+    @Test
8
+    public void testConstructorStartRollandEndingRoll(){
9
+        //Given
10
+        Bins results = new Bins(2, 12);
11
+        //When
12
+
13
+    }
14
+
15
+}

+ 1
- 1
src/main/java/Dice.java Näytä tiedosto

@@ -18,7 +18,7 @@ public class Dice {
18 18
 
19 19
         }
20 20
 
21
-        return dice;
21
+        return sumOfRoll;
22 22
     }
23 23
 
24 24
 

+ 25
- 9
src/main/java/DiceTest.java Näytä tiedosto

@@ -1,11 +1,5 @@
1
-
2
-
3
-import org.junit.jupiter.api.Test;
4
-import sun.jvm.hotspot.utilities.Assert;
5 1
 import org.junit.Assert;
6
-
7
-
8
-
2
+import org.junit.Test;
9 3
 
10 4
 public class DiceTest {
11 5
 
@@ -28,8 +22,30 @@ public class DiceTest {
28 22
 
29 23
         Integer actualToss = dice.sumOfToss();
30 24
 
31
-        Assert.
32
-//                (actualToss >= dice.numberOfDice && actualToss <= dice.numberOfDice * 6);
25
+        Assert.assertTrue(actualToss >= dice.numberOfDice && actualToss <= dice.numberOfDice * 6);
26
+
27
+    }
28
+
29
+    @Test
30
+    public void testSumOfToss2(){
31
+        //Given
32
+        Dice dice = new Dice(5);
33
+
34
+        Integer actualToss = dice.sumOfToss();
35
+
36
+        Assert.assertTrue(actualToss >= dice.numberOfDice && actualToss <= dice.numberOfDice * 6);
37
+
38
+    }
39
+
40
+    @Test
41
+    public void testSumOfToss3(){
42
+        //Given
43
+        Dice dice = new Dice(8);
44
+
45
+        Integer actualToss = dice.sumOfToss();
46
+
47
+        Assert.assertTrue(actualToss >= dice.numberOfDice && actualToss <= dice.numberOfDice * 6);
48
+
33 49
     }
34 50
 
35 51
 }