Jose Bedolla 5 gadus atpakaļ
vecāks
revīzija
86f02d0fae

Binārs
.DS_Store Parādīt failu


+ 11
- 11
README.md Parādīt failu

@@ -1,23 +1,23 @@
1
-# Kris-Tof Dice Toss
1
+# Kris-Tof Bedolla.Jose.Dice Toss
2 2
 
3
-Create a `Dice` class that acts like a set of N random-tossed dies.
3
+Create a `Bedolla.Jose.Dice` class that acts like a set of N random-tossed dies.
4 4
 ```
5
-Dice dice = new Dice(2); // for craps
6
-Dice dice = new Dice(5); // for yatzee
5
+Bedolla.Jose.Dice dice = new Bedolla.Jose.Dice(2); // for craps
6
+Bedolla.Jose.Dice dice = new Bedolla.Jose.Dice(5); // for yatzee
7 7
 
8 8
 Integer toss = dice.tossAndSum();
9 9
 ```
10
-make a couple unit tests for the Dice class. 
10
+make a couple unit tests for the Bedolla.Jose.Dice class. 
11 11
 
12
-Create a tracking class `Bins` that can be used to track the results of dice tosses.
12
+Create a tracking class `Bedolla.Jose.Bins` that can be used to track the results of dice tosses.
13 13
 
14 14
 ```
15
-Bins results = new Bins(2, 12); // for bins from 2..12
15
+Bedolla.Jose.Bins results = new Bedolla.Jose.Bins(2, 12); // for bins from 2..12
16 16
 Integer numberOfTens = results.getBin(10); // returns the number of tens in the 10 bin
17 17
 results.incrementBin(10); // should increment bin # 10
18 18
 
19 19
 ```
20
-make a couple unit tests for the Bins class. Your test methods should follow this template:
20
+make a couple unit tests for the Bedolla.Jose.Bins class. Your test methods should follow this template:
21 21
 
22 22
     in the tests
23 23
     Create a new Bin
@@ -27,7 +27,7 @@ make a couple unit tests for the Bins class. Your test methods should follow thi
27 27
     
28 28
     
29 29
 
30
-Create a `Simulation` class whose Constructor takes arguments:
30
+Create a `Bedolla.Jose.Simulation` class whose Constructor takes arguments:
31 31
     numberOfDies to throw
32 32
     numberOfTosses to run
33 33
 
@@ -35,7 +35,7 @@ Create a simulation where two dies are thrown *one million times*.
35 35
 Keep track of each roll by incrementing the correct Bin.
36 36
 
37 37
 ```
38
-Simulation sim = new Simulation(2, 10000);
38
+Bedolla.Jose.Simulation sim = new Bedolla.Jose.Simulation(2, 10000);
39 39
 
40 40
 sim.runSimulation();
41 41
 
@@ -53,7 +53,7 @@ the results of the sim.printResults() should be an output string that looks like
53 53
 
54 54
 ```
55 55
 ***
56
-Simulation of 2 dice tossed for 1000000 times.
56
+Bedolla.Jose.Simulation of 2 dice tossed for 1000000 times.
57 57
 ***
58 58
 
59 59
  2 :    27917: 0.03 **

+ 10
- 0
pom.xml Parādīt failu

@@ -8,5 +8,15 @@
8 8
     <artifactId>Dicey-Lab</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+<dependencies>
12
+        <!-- https://mvnrepository.com/artifact/junit/junit -->
13
+        <dependency>
14
+            <groupId>junit</groupId>
15
+            <artifactId>junit</artifactId>
16
+            <version>4.10</version>
17
+            <scope>test</scope>
18
+        </dependency>
19
+
20
+</dependencies>
11 21
 
12 22
 </project>

Binārs
src/.DS_Store Parādīt failu


+ 37
- 0
src/Test/java/Bedolla/Jose/BinsTest.java Parādīt failu

@@ -0,0 +1,37 @@
1
+package Bedolla.Jose;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import java.util.HashMap;
7
+
8
+public class BinsTest {
9
+
10
+    @Test
11
+    public void constructorTest()
12
+    {
13
+        Bins bin =  new Bins(2,12);
14
+
15
+        Integer actual = bin.bins.get(12);
16
+
17
+        Assert.assertTrue(actual==0);
18
+    }
19
+
20
+    @Test
21
+    public void trackTossTest()
22
+    {
23
+        //given
24
+        Bins bin = new Bins(2,12);
25
+
26
+        Dice dice = new Dice(2);
27
+        Integer tossSum = dice.tossAndSUM();
28
+        bin.trackToss(tossSum);
29
+        //when
30
+
31
+        Integer actual = bin.bins.get(tossSum);
32
+
33
+        //then
34
+        Assert.assertTrue(actual==1);
35
+
36
+    }
37
+}

+ 32
- 0
src/Test/java/Bedolla/Jose/DiceTest.java Parādīt failu

@@ -0,0 +1,32 @@
1
+package Bedolla.Jose;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class DiceTest {
7
+
8
+
9
+    @Test
10
+    public void getNumberOfDice()
11
+    {
12
+        //given
13
+        Dice dice = new Dice(2);
14
+
15
+        Integer expected = 2;
16
+
17
+        Integer actual = dice.getNumOfDice();
18
+
19
+        Assert.assertEquals(expected,actual);
20
+    }
21
+
22
+    @Test
23
+    public void tossAndSumTest()
24
+    {
25
+        Dice dice = new Dice(2);
26
+
27
+        Integer actual = dice.tossAndSUM();
28
+
29
+        Assert.assertTrue(actual >= 2 && actual <= 12);
30
+
31
+    }
32
+}

+ 28
- 0
src/Test/java/Bedolla/Jose/LocalTest.java Parādīt failu

@@ -0,0 +1,28 @@
1
+package Bedolla.Jose;
2
+import org.junit.Assert;
3
+import org.junit.Test;
4
+
5
+public class LocalTest {
6
+
7
+    @Test
8
+    public void rollTest()
9
+    {
10
+        //given
11
+        Local die = new Local();
12
+        //when
13
+        int actual = die.toss();
14
+        //then
15
+        Assert.assertTrue(actual>=1 && actual<=6);
16
+    }
17
+    @Test
18
+    public void rollTest2()
19
+    {
20
+
21
+        //given
22
+        Local die = new Local();
23
+        //when
24
+        int actual = die.toss();
25
+        //then
26
+        Assert.assertTrue(actual>=1 && actual<=20);
27
+    }
28
+}

+ 13
- 0
src/Test/java/Bedolla/Jose/SimulationTest.java Parādīt failu

@@ -0,0 +1,13 @@
1
+package Bedolla.Jose;
2
+
3
+import org.junit.Test;
4
+
5
+public class SimulationTest {
6
+    @Test
7
+    public void runSimulation()
8
+    {
9
+        Simulation simu = new Simulation(2,100);
10
+        simu.runSimulation();
11
+    }
12
+
13
+}

Binārs
src/main/.DS_Store Parādīt failu


+ 27
- 0
src/main/java/Bedolla/Jose/Bins.java Parādīt failu

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

+ 39
- 0
src/main/java/Bedolla/Jose/Dice.java Parādīt failu

@@ -0,0 +1,39 @@
1
+package Bedolla.Jose;
2
+
3
+import java.util.ArrayList;
4
+
5
+public class Dice {
6
+
7
+    ArrayList<Local> dice;
8
+
9
+    public Dice(Integer numberOfD) {
10
+
11
+        dice = new ArrayList<Local>();
12
+        initializeD(numberOfD);
13
+    }
14
+
15
+    private void initializeD(Integer number )
16
+    {
17
+        for(int i =0; i <number; i++)
18
+        {
19
+            Local die = new Local();
20
+            dice.add(die);
21
+        }
22
+    }
23
+
24
+    public Integer getNumOfDice()
25
+    {
26
+        return dice.size();
27
+    }
28
+
29
+    public Integer tossAndSUM()
30
+    {
31
+        Integer sum = 0;
32
+        for(Local d: dice)
33
+        {
34
+
35
+            sum+=d.toss();
36
+        }
37
+        return sum;
38
+    }
39
+}

+ 24
- 0
src/main/java/Bedolla/Jose/Local.java Parādīt failu

@@ -0,0 +1,24 @@
1
+package Bedolla.Jose;
2
+
3
+import java.util.Random;
4
+
5
+public class Local {
6
+    int side;
7
+
8
+    public Local(int side) {
9
+        this.side=side;
10
+    }
11
+
12
+    public Local()
13
+    {
14
+        this(6);
15
+    }
16
+
17
+    public Integer toss()
18
+    {
19
+
20
+        Random random = new Random();
21
+        return random.nextInt(6)+1;
22
+    }
23
+
24
+}

+ 10
- 0
src/main/java/Bedolla/Jose/Main.java Parādīt failu

@@ -0,0 +1,10 @@
1
+package Bedolla.Jose;
2
+
3
+public class Main {
4
+
5
+    public static void main(String[] args) {
6
+        Simulation simu = new Simulation(2,1000000000);
7
+        simu.runSimulation();
8
+        System.out.println(simu.bin.bins);
9
+    }
10
+}

+ 34
- 0
src/main/java/Bedolla/Jose/Simulation.java Parādīt failu

@@ -0,0 +1,34 @@
1
+package Bedolla.Jose;
2
+
3
+public class Simulation {
4
+
5
+    int numberOfDies;
6
+    int numberOfTosses;
7
+    Dice dice;
8
+    public Bins bin;
9
+
10
+    public Simulation(int numberOfDies, int numberOfTosses)
11
+    {
12
+    this.numberOfDies = numberOfDies;
13
+    this.numberOfTosses = numberOfTosses;
14
+    this.dice = new Dice(numberOfDies);
15
+    this.bin =  new Bins(numberOfDies,numberOfDies*6);
16
+    }
17
+
18
+    public void runSimulation()
19
+    {
20
+
21
+        for(int i =0; i< numberOfTosses; i++)
22
+        {
23
+            bin.trackToss(dice.tossAndSUM());
24
+        }
25
+    }
26
+
27
+    public Bins returnResults()
28
+    {
29
+        return this.bin;
30
+    }
31
+
32
+
33
+
34
+    }

+ 0
- 4
src/main/java/Bins.java Parādīt failu

@@ -1,4 +0,0 @@
1
-
2
-public class Bins {
3
-
4
-}

+ 0
- 4
src/main/java/Dice.java Parādīt failu

@@ -1,4 +0,0 @@
1
-public class Dice {
2
-
3
-
4
-}

+ 0
- 5
src/main/java/Simulation.java Parādīt failu

@@ -1,5 +0,0 @@
1
-public class Simulation {
2
-
3
-
4
-
5
-}