Skip to content

Commit

Permalink
iluwatar#105 Updates as per Sonar checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanty97 committed Feb 11, 2024
1 parent 31377d7 commit 79037ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/main/java/math/DiceThrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
*/
public class DiceThrow {

private static Random random = new Random();

/**
* Enum for standardized sided dice (4,6,8,10,12 and 20).
*/
Expand Down Expand Up @@ -59,14 +61,14 @@ public int getDiceSides() {
* Returns the sum of sides for the given number of sides of each dice.
*
* @param noOfDice number of dice
* @param diceSides sides of a dice
* @param sides sides of a dice
* @return int sum of sides for number of dice
*/
public static int throwDice(int noOfDice, DiceSides diceSides) {
public static int throwDice(int noOfDice, DiceSides sides) {

int sum = 0;
for (int i = 0; i < noOfDice; i++) {
sum = sum + (1 + new Random().nextInt(diceSides.getDiceSides()));
sum = sum + (1 + random.nextInt(sides.getDiceSides()));
}

return sum;
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/math/DiceThrowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package math;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import math.DiceThrow.DiceSides;
Expand All @@ -46,7 +47,7 @@ void test_throwDice() {
assertTrue(DiceThrow.throwDice(4, DiceSides.TEN) <= 40);
assertTrue(DiceThrow.throwDice(1, DiceSides.TWELVE) <= 12);
assertTrue(DiceThrow.throwDice(2, DiceSides.TWENTY) <= 40);
assertTrue(DiceThrow.throwDice(0, DiceSides.FOUR) == 0);
assertEquals(0, DiceThrow.throwDice(0, DiceSides.FOUR));

}
}

0 comments on commit 79037ac

Please sign in to comment.