| 1 | package com.takenoko.weather; | |
| 2 | ||
| 3 | import java.security.SecureRandom; | |
| 4 | import java.util.Objects; | |
| 5 | import java.util.Random; | |
| 6 | ||
| 7 | /** Dice with N sides, by default it has 6. */ | |
| 8 | public class Dice { | |
| 9 | private final Random random; | |
| 10 | private final int sides; | |
| 11 | private int lastRoll; | |
| 12 | ||
| 13 | /** | |
| 14 | * Specify the number of sides and the Random Generator | |
| 15 | * | |
| 16 | * @param sides number of sides of the dice | |
| 17 | * @param random random number generator | |
| 18 | */ | |
| 19 | public Dice(int sides, Random random) { | |
| 20 | this.sides = sides; | |
| 21 | this.random = random; | |
| 22 | this.lastRoll = 0; | |
| 23 | } | |
| 24 | ||
| 25 | /** | |
| 26 | * Specify the number of sides | |
| 27 | * | |
| 28 | * @param sides number of sides of the dice | |
| 29 | */ | |
| 30 | public Dice(int sides) { | |
| 31 | this(sides, new SecureRandom()); | |
| 32 | } | |
| 33 | ||
| 34 | /** | |
| 35 | * Roll the dice | |
| 36 | * | |
| 37 | * @return the result of the roll (between 0 and N-1) | |
| 38 | */ | |
| 39 | protected int roll() { | |
| 40 | lastRoll = random.nextInt(sides); | |
| 41 |
1
1. roll : replaced int return with 0 for com/takenoko/weather/Dice::roll → KILLED |
return lastRoll; |
| 42 | } | |
| 43 | ||
| 44 | @Override | |
| 45 | public boolean equals(Object o) { | |
| 46 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with false for com/takenoko/weather/Dice::equals → KILLED |
if (this == o) return true; |
| 47 |
3
1. equals : negated conditional → KILLED 2. equals : negated conditional → KILLED 3. equals : replaced boolean return with true for com/takenoko/weather/Dice::equals → KILLED |
if (o == null || getClass() != o.getClass()) return false; |
| 48 | Dice dice = (Dice) o; | |
| 49 |
2
1. equals : negated conditional → KILLED 2. equals : replaced boolean return with true for com/takenoko/weather/Dice::equals → KILLED |
return sides == dice.sides; |
| 50 | } | |
| 51 | ||
| 52 | @Override | |
| 53 | public int hashCode() { | |
| 54 |
1
1. hashCode : replaced int return with 0 for com/takenoko/weather/Dice::hashCode → KILLED |
return Objects.hash(sides); |
| 55 | } | |
| 56 | ||
| 57 | protected int peek() { | |
| 58 |
1
1. peek : replaced int return with 0 for com/takenoko/weather/Dice::peek → KILLED |
return lastRoll; |
| 59 | } | |
| 60 | } | |
Mutations | ||
| 41 |
1.1 |
|
| 46 |
1.1 2.2 |
|
| 47 |
1.1 2.2 3.3 |
|
| 49 |
1.1 2.2 |
|
| 54 |
1.1 |
|
| 58 |
1.1 |