Dice.java

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
Location : roll
Killed by : com.takenoko.weather.DiceTest.[engine:junit-jupiter]/[class:com.takenoko.weather.DiceTest]/[nested-class:Roll]/[method:shouldReturnANumberBetween0And5WhenRandomIsBetween0And5()]
replaced int return with 0 for com/takenoko/weather/Dice::roll → KILLED

46

1.1
Location : equals
Killed by : com.takenoko.weather.DiceTest.[engine:junit-jupiter]/[class:com.takenoko.weather.DiceTest]/[nested-class:Equals]/[method:shouldReturnFalseWhenTheNumberOfSidesIsDifferent()]
negated conditional → KILLED

2.2
Location : equals
Killed by : com.takenoko.weather.DiceTest.[engine:junit-jupiter]/[class:com.takenoko.weather.DiceTest]/[nested-class:Equals]/[method:shouldReturnTrueWhenTheObjectIsTheSameTestEqual()]
replaced boolean return with false for com/takenoko/weather/Dice::equals → KILLED

47

1.1
Location : equals
Killed by : com.takenoko.weather.DiceTest.[engine:junit-jupiter]/[class:com.takenoko.weather.DiceTest]/[nested-class:Equals]/[method:shouldReturnTrueWhenTheNumberOfSidesIsTheSame()]
negated conditional → KILLED

2.2
Location : equals
Killed by : com.takenoko.weather.DiceTest.[engine:junit-jupiter]/[class:com.takenoko.weather.DiceTest]/[nested-class:Equals]/[method:shouldReturnFalseWhenTheObjectIsNotADice()]
negated conditional → KILLED

3.3
Location : equals
Killed by : com.takenoko.weather.DiceTest.[engine:junit-jupiter]/[class:com.takenoko.weather.DiceTest]/[nested-class:Equals]/[method:shouldReturnFalseWhenTheObjectIsNotADice()]
replaced boolean return with true for com/takenoko/weather/Dice::equals → KILLED

49

1.1
Location : equals
Killed by : com.takenoko.weather.DiceTest.[engine:junit-jupiter]/[class:com.takenoko.weather.DiceTest]/[nested-class:Equals]/[method:shouldReturnFalseWhenTheNumberOfSidesIsDifferent()]
negated conditional → KILLED

2.2
Location : equals
Killed by : com.takenoko.weather.DiceTest.[engine:junit-jupiter]/[class:com.takenoko.weather.DiceTest]/[nested-class:Equals]/[method:shouldReturnFalseWhenTheNumberOfSidesIsDifferent()]
replaced boolean return with true for com/takenoko/weather/Dice::equals → KILLED

54

1.1
Location : hashCode
Killed by : com.takenoko.weather.DiceTest.[engine:junit-jupiter]/[class:com.takenoko.weather.DiceTest]/[nested-class:HashCode]/[method:shouldReturnADifferentHashCodeWhenTheNumberOfSidesIsDifferent()]
replaced int return with 0 for com/takenoko/weather/Dice::hashCode → KILLED

58

1.1
Location : peek
Killed by : com.takenoko.weather.DiceTest.[engine:junit-jupiter]/[class:com.takenoko.weather.DiceTest]/[nested-class:Peek]/[method:shouldReturnTheLastRollWhenTheDiceIsRolled()]
replaced int return with 0 for com/takenoko/weather/Dice::peek → KILLED

Active mutators

Tests examined


Report generated by PIT 1.8.0