#30 Steffon Williams,Dice

Open
Stwillia94 wants to merge 1 commits from Stwillia94/ZCW-DiceyLab:master into master

+ 22
- 0
src/Test/Java/BinsTest.java View File

1
+import Williams.Steffon.Bins;
2
+import org.junit.Assert;
3
+import org.junit.Test;
4
+
5
+import java.util.HashMap;
6
+
7
+public class BinsTest {
8
+
9
+    @Test
10
+
11
+    public void constructorTest() {
12
+       // Given
13
+        Bins bin = new Bins(2,12);
14
+        // When
15
+        Integer actual = bin.bins.get(12);
16
+
17
+        //Then
18
+        Assert.assertTrue(actual == 0);
19
+    }
20
+
21
+
22
+}

+ 35
- 0
src/Test/Java/Steffon/Williams/DiceTest.java View File

1
+package Steffon.Williams;
2
+
3
+import Williams.Steffon.Dice;
4
+import org.junit.jupiter.api.Test;
5
+import org.junit.Assert;
6
+
7
+public class DiceTest {
8
+
9
+    @Test
10
+    public void getNumberOfDiceTest(){
11
+        //Given
12
+        Dice dice = new Dice(2);
13
+        //
14
+         Integer expected = 2;
15
+         Integer actual = dice.getNumberOfDice();
16
+
17
+         Assert.assertEquals(expected,actual);
18
+
19
+    }
20
+
21
+    @Test
22
+    public void tossAndSumTest() {
23
+        //Given
24
+        Dice dice = new Dice(2);
25
+        //
26
+        Integer actual = dice.tossAndSum();
27
+
28
+        Assert.assertTrue( actual >=2 && actual <= 12);
29
+
30
+
31
+
32
+    }
33
+
34
+
35
+}

+ 30
- 0
src/Test/Java/Steffon/Williams/DieTest.java View File

1
+package Steffon.Williams;
2
+
3
+import Williams.Steffon.Die;
4
+import org.junit.Assert;
5
+import org.junit.Test;
6
+
7
+public class DieTest {
8
+
9
+    @Test
10
+    public void rollTest(){
11
+    // Given
12
+    Die die = new Die();
13
+    //When
14
+    Integer actual = die.roll();
15
+    //Then
16
+    Assert.assertTrue(actual >= 1 && actual <= 6);
17
+    }
18
+
19
+@Test
20
+public void roll20Test (){
21
+        //Given
22
+    Die die = new Die();
23
+    // When
24
+    Integer actual = die.roll();
25
+    // Then
26
+    Assert.assertTrue(actual >= 1 && actual <= 20);
27
+
28
+}
29
+
30
+}

+ 0
- 4
src/main/java/Bins.java View File

1
-
2
-public class Bins {
3
-
4
-}

+ 0
- 4
src/main/java/Dice.java View File

1
-public class Dice {
2
-
3
-
4
-}

+ 0
- 5
src/main/java/Simulation.java View File

1
-public class Simulation {
2
-
3
-
4
-
5
-}

+ 29
- 0
src/main/java/Williams/Steffon/Bins.java View File

1
+package Williams.Steffon;
2
+
3
+import java.util.HashMap;
4
+import java.util.Map;
5
+
6
+public class Bins {
7
+
8
+    HashMap<Integer,Integer> bins;
9
+
10
+
11
+    public Bins(int min, int max){
12
+        bins = new  HashMap<Integer,Integer>();
13
+        initializeBins(min, max);
14
+    }
15
+    private void initializeBins(Integer min, Integer max){
16
+
17
+        for(int i = min; i <= max; i++) {
18
+            bins.put(i,0);
19
+        }
20
+
21
+    }
22
+    public void trackToss(int tossSum) {
23
+       bins.put(tossSum, bins.get(tossSum)+1);
24
+
25
+    }
26
+
27
+
28
+
29
+}

+ 37
- 0
src/main/java/Williams/Steffon/Dice.java View File

1
+package Williams.Steffon;
2
+
3
+import java.util.ArrayList;
4
+
5
+public class Dice {
6
+    ArrayList<Die> dice;
7
+
8
+    public Dice (Integer number){
9
+       dice = new ArrayList<Die>();
10
+       initializeDice(number);
11
+
12
+    }
13
+
14
+    private void initializeDice(Integer number){
15
+        for(int i = 0; i < number; i++) {
16
+            Die die = new Die();
17
+            dice.add(die);
18
+        }
19
+
20
+
21
+    }
22
+
23
+    public Integer getNumberOfDice(){
24
+
25
+        return dice.size();
26
+    }
27
+
28
+    public Integer tossAndSum() {
29
+        Integer sum = 0;
30
+
31
+for (Die die : dice) {
32
+    sum += die.roll();
33
+}
34
+return sum;
35
+
36
+    }
37
+}

+ 24
- 0
src/main/java/Williams/Steffon/Die.java View File

1
+package Williams.Steffon;
2
+
3
+import java.util.Random;
4
+
5
+public class Die {
6
+
7
+    int sides;
8
+
9
+
10
+    public Die(int sides) {
11
+        this.sides = sides;
12
+
13
+    }
14
+
15
+    public Die( ){
16
+      this(6);
17
+
18
+    }
19
+
20
+    public Integer roll (){
21
+        Random random = new Random();
22
+        return random.nextInt(6)+ 1;
23
+    }
24
+}

+ 26
- 0
src/main/java/Williams/Steffon/Simulation.java View File

1
+package Williams.Steffon;
2
+
3
+public class Simulation {
4
+
5
+    int numberOfDies;
6
+    int numberOfTosses;
7
+
8
+    public Simulation(int numberOfDices, int numberOfTosses){
9
+      this.numberOfDies = numberOfDies;
10
+      this.numberOfTosses = numberOfTosses;
11
+
12
+    }
13
+   // public void runSimulation()
14
+
15
+   // Simulation sim = new Simulation(2, 10000);
16
+
17
+//sim.runSimulation();
18
+
19
+//sim.printResults();
20
+
21
+    //numberOfDies to throw
22
+    //numberOfTosses to run
23
+
24
+
25
+
26
+}

+ 16
- 0
src/main/java/Williams/Steffon/SimulationTest.java View File

1
+package Williams.Steffon;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+public class SimulationTest {
6
+
7
+    @Test
8
+    public void runSimulation(){
9
+        //Given
10
+        Die die = new Die;
11
+        //When
12
+
13
+        //This
14
+
15
+    }
16
+}

+ 0
- 0
src/main/java/Williams/Steffon/package-info.java View File