CowHealthUpdateStrategies.java

1
package edu.ucsb.cs156.happiercows.strategies;
2
3
import edu.ucsb.cs156.happiercows.entities.CommonsPlus;
4
import edu.ucsb.cs156.happiercows.entities.UserCommons;
5
import lombok.AllArgsConstructor;
6
import lombok.Getter;
7
import lombok.extern.slf4j.Slf4j;
8
9
/**
10
 * The CowHealthUpdateStrategies enum provides a variety of strategies for
11
 * updating cow health.
12
 *
13
 * For information on Java enum's, see the Oracle Java Tutorial on
14
 * <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html">Enum
15
 * Types</a>,
16
 * which are far more powerful in Java than enums in most other languages.
17
 */
18
19
@Getter
20
@AllArgsConstructor
21
@Slf4j
22
public enum CowHealthUpdateStrategies implements CowHealthUpdateStrategy {
23
24
    Linear("Linear",
25
            "Cow health increases/decreases proportionally to the number of cows over/under the carrying capacity.") {
26
        @Override
27
        public double calculateNewCowHealth(CommonsPlus commonsPlus, UserCommons uC, int totalCows) {
28 1 1. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$1::calculateNewCowHealth → KILLED
            return uC.getCowHealth()
29 3 1. calculateNewCowHealth : Replaced integer subtraction with addition → KILLED
2. calculateNewCowHealth : Replaced double subtraction with addition → KILLED
3. calculateNewCowHealth : Replaced double multiplication with division → KILLED
                    - (totalCows - commonsPlus.getEffectiveCapacity()) * commonsPlus.getCommons().getDegradationRate();
30
        }
31
    },
32
    Constant("Constant",
33
            "Cow health changes increases/decreases by the degradation rate, depending on if the number of cows exceeds the carrying capacity.") {
34
        @Override
35
        public double calculateNewCowHealth(CommonsPlus commonsPlus, UserCommons uC, int totalCows) {
36 2 1. calculateNewCowHealth : negated conditional → KILLED
2. calculateNewCowHealth : changed conditional boundary → KILLED
            if (totalCows <= commonsPlus.getEffectiveCapacity()) {
37 2 1. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$2::calculateNewCowHealth → KILLED
2. calculateNewCowHealth : Replaced double addition with subtraction → KILLED
                return uC.getCowHealth() + commonsPlus.getCommons().getDegradationRate();
38
            } else {
39 2 1. calculateNewCowHealth : Replaced double subtraction with addition → KILLED
2. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$2::calculateNewCowHealth → KILLED
                return uC.getCowHealth() - commonsPlus.getCommons().getDegradationRate();
40
            }
41
        }
42
    },
43
    Noop("Do nothing", "Cow health does not change.") {
44
        @Override
45
        public double calculateNewCowHealth(CommonsPlus commonsPlus, UserCommons uC, int totalCows) {
46 1 1. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$3::calculateNewCowHealth → KILLED
            return uC.getCowHealth();
47
        }
48
    },
49
    Milan("Milan",
50
            "Cow health increases/decreases proportionally to the square of ratio of cows/total capacity according to a formula from Milan de Vries.") {
51
        @Override
52
        public double calculateNewCowHealth(CommonsPlus commonsPlus, UserCommons uC, int totalCows) {
53 1 1. calculateNewCowHealth : Replaced integer subtraction with addition → KILLED
            double excess = totalCows - commonsPlus.getEffectiveCapacity();
54
            double adjustmentFactor = 1.0;
55 1 1. calculateNewCowHealth : Replaced double division with multiplication → KILLED
            double x = (excess / commonsPlus.getEffectiveCapacity());
56 1 1. calculateNewCowHealth : negated conditional → KILLED
            if(excess != 0){
57 2 1. calculateNewCowHealth : Replaced double multiplication with division → KILLED
2. calculateNewCowHealth : Replaced double division with multiplication → KILLED
                double sign = -1 * excess / Math.abs(excess);
58 3 1. calculateNewCowHealth : Replaced double multiplication with division → KILLED
2. calculateNewCowHealth : Replaced double multiplication with division → KILLED
3. calculateNewCowHealth : Replaced double addition with subtraction → KILLED
                adjustmentFactor = 1.0 + sign * x * x;
59
            }
60
            adjustmentFactor = Math.max(0.0, adjustmentFactor);
61 2 1. calculateNewCowHealth : Replaced double multiplication with division → KILLED
2. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$4::calculateNewCowHealth → KILLED
            return uC.getCowHealth() * adjustmentFactor;
62
        }
63
    },
64
    Mattanjah("Mattanjah",
65
            "Cow health increases/decreases proportionally to the square of ratio of excess/total capacity * degradation rate according to a formula from Mattanjah de Vries.") {
66
        @Override
67
        public double calculateNewCowHealth(CommonsPlus commonsPlus, UserCommons uC, int totalCows) {
68
69 1 1. calculateNewCowHealth : Replaced integer subtraction with addition → KILLED
            double excess = totalCows - commonsPlus.getEffectiveCapacity();
70
            double adjustmentFactor = 1.0;
71 2 1. calculateNewCowHealth : Replaced double multiplication with division → KILLED
2. calculateNewCowHealth : Replaced double division with multiplication → KILLED
            double x = (excess / commonsPlus.getEffectiveCapacity()) * commonsPlus.getCommons().getDegradationRate();
72 1 1. calculateNewCowHealth : negated conditional → KILLED
            if(excess != 0){
73 2 1. calculateNewCowHealth : Replaced double multiplication with division → KILLED
2. calculateNewCowHealth : Replaced double division with multiplication → KILLED
                double sign = -1 * excess / Math.abs(excess);
74 3 1. calculateNewCowHealth : Replaced double multiplication with division → KILLED
2. calculateNewCowHealth : Replaced double multiplication with division → KILLED
3. calculateNewCowHealth : Replaced double addition with subtraction → KILLED
                adjustmentFactor = 1.0 + sign * x * x;
75
            }
76
            adjustmentFactor = Math.max(0.0, adjustmentFactor);
77 2 1. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$5::calculateNewCowHealth → KILLED
2. calculateNewCowHealth : Replaced double multiplication with division → KILLED
            return uC.getCowHealth() * adjustmentFactor;
78
        }
79
    };
80
81
    private final String displayName;
82
    private final String description;
83
84
    public final static CowHealthUpdateStrategies DEFAULT_ABOVE_CAPACITY = Linear;
85
    public final static CowHealthUpdateStrategies DEFAULT_BELOW_CAPACITY = Constant;
86
}

Mutations

28

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:linear_updates_health_proportional_to_num_cows_over_capacity()]
replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$1::calculateNewCowHealth → KILLED

29

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:linear_updates_health_proportional_to_num_cows_over_capacity()]
Replaced integer subtraction with addition → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:linear_updates_health_proportional_to_num_cows_over_capacity()]
Replaced double subtraction with addition → KILLED

3.3
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:linear_updates_health_proportional_to_num_cows_over_capacity()]
Replaced double multiplication with division → KILLED

36

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:constant_changes_by_constant_amount()]
negated conditional → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:constant_changes_by_constant_amount()]
changed conditional boundary → KILLED

37

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:constant_changes_by_constant_amount()]
replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$2::calculateNewCowHealth → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:constant_changes_by_constant_amount()]
Replaced double addition with subtraction → KILLED

39

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:constant_changes_by_constant_amount()]
Replaced double subtraction with addition → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:constant_changes_by_constant_amount()]
replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$2::calculateNewCowHealth → KILLED

46

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:noop_does_nothing()]
replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$3::calculateNewCowHealth → KILLED

53

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:milan_calculates_correctly()]
Replaced integer subtraction with addition → KILLED

55

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:milan_calculates_correctly()]
Replaced double division with multiplication → KILLED

56

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:milan_calculates_correctly()]
negated conditional → KILLED

57

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:milan_calculates_correctly()]
Replaced double multiplication with division → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:milan_calculates_correctly()]
Replaced double division with multiplication → KILLED

58

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:milan_calculates_correctly()]
Replaced double multiplication with division → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:milan_calculates_correctly()]
Replaced double multiplication with division → KILLED

3.3
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:milan_calculates_correctly()]
Replaced double addition with subtraction → KILLED

61

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:milan_calculates_correctly()]
Replaced double multiplication with division → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:milan_calculates_correctly()]
replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$4::calculateNewCowHealth → KILLED

69

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
Replaced integer subtraction with addition → KILLED

71

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
Replaced double multiplication with division → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
Replaced double division with multiplication → KILLED

72

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
negated conditional → KILLED

73

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
Replaced double multiplication with division → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
Replaced double division with multiplication → KILLED

74

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
Replaced double multiplication with division → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
Replaced double multiplication with division → KILLED

3.3
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
Replaced double addition with subtraction → KILLED

77

1.1
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$5::calculateNewCowHealth → KILLED

2.2
Location : calculateNewCowHealth
Killed by : edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategyTests]/[method:mattanjah_calculates_correctly()]
Replaced double multiplication with division → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0