Trinh Tong преди 6 години
родител
ревизия
c3344b4ccd
променени са 3 файла, в които са добавени 23 реда и са изтрити 15 реда
  1. 1
    5
      src/main/java/Bins.java
  2. 20
    10
      src/test/java/BinsTest.java
  3. 2
    0
      src/test/java/SimulationTest.java

+ 1
- 5
src/main/java/Bins.java Целия файл

@@ -1,7 +1,7 @@
1 1
 import java.util.HashMap;
2 2
 
3 3
 public class Bins {
4
-    private HashMap<Integer, Integer> results;
4
+    public HashMap<Integer, Integer> results;
5 5
     int min = 0;
6 6
     int max = 0;
7 7
     // creates an array of required length
@@ -17,8 +17,4 @@ public class Bins {
17 17
             this.results.put(i, 0);
18 18
         }
19 19
     }
20
-
21
-    public HashMap getHashMap() {
22
-        return this.results;
23
-    }
24 20
 }

+ 20
- 10
src/test/java/BinsTest.java Целия файл

@@ -1,16 +1,13 @@
1
+import org.junit.Assert;
1 2
 import org.junit.Test;
2 3
 
4
+import java.util.Set;
5
+
3 6
 public class BinsTest {
4 7
 
5 8
     Dice testDice;
6 9
     Bins testBins;
7 10
 
8
-
9
-    /**
10
-     * test to make?
11
-     * get bin # { how many in that bin? }
12
-     *
13
-     */
14 11
     public BinsTest() {
15 12
 
16 13
         testDice = new Dice(2);
@@ -18,14 +15,27 @@ public class BinsTest {
18 15
 
19 16
     }
20 17
 
21
-
22 18
     @Test
23 19
     public void testHashMap() {
24 20
 
25
-        for (int key: testBins.results.keySet()) {
26
-
21
+        // Given
22
+        int[] expected = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
23
+        boolean keyMatches = false;
24
+        boolean expectedKey = true;
25
+        int i = 0;
26
+
27
+        // When
28
+        Set<Integer> actual = testBins.results.keySet();
29
+
30
+        for (int key: actual) {
31
+            if (key == expected[i]) {
32
+                keyMatches = true;
33
+                break;
34
+            }
35
+            i++;
27 36
         }
28 37
 
29
-
38
+        // Then
39
+        Assert.assertTrue(keyMatches);
30 40
     }
31 41
 }

+ 2
- 0
src/test/java/SimulationTest.java Целия файл

@@ -0,0 +1,2 @@
1
+public class SimulationTest {
2
+}