CowHealthUpdateStrategies.java

1
package edu.ucsb.cs156.happiercows.strategies;
2
3
import edu.ucsb.cs156.happiercows.entities.Commons;
4
import edu.ucsb.cs156.happiercows.entities.UserCommons;
5
import edu.ucsb.cs156.happiercows.repositories.CommonsRepository;
6
import lombok.AllArgsConstructor;
7
import lombok.Getter;
8
9
/**
10
 * The CowHealthUpdateStrategies enum provides a variety of strategies for updating cow health.
11
 *
12
 * For information on Java enum's, see the Oracle Java Tutorial on <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html">Enum Types</a>,
13
 * which are far more powerful in Java than enums in most other languages.
14
 */
15
16
@Getter
17
@AllArgsConstructor
18
public enum CowHealthUpdateStrategies implements CowHealthUpdateStrategy {
19
20
    Linear("Linear", "Cow health increases/decreases proportionally to the number of cows over/under the carrying capacity.") {
21
        @Override
22
        public double calculateNewCowHealth(Commons commons, UserCommons user, int totalCows, CommonsRepository commonsRepository) {
23 4 1. calculateNewCowHealth : Replaced integer subtraction with addition → KILLED
2. calculateNewCowHealth : Replaced double multiplication with division → KILLED
3. calculateNewCowHealth : Replaced double subtraction with addition → KILLED
4. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$1::calculateNewCowHealth → KILLED
            return user.getCowHealth() - (totalCows - Commons.computeEffectiveCapacity(commons, commonsRepository)) * commons.getDegradationRate();
24
        }
25
    },
26
    Constant("Constant", "Cow health changes increases/decreases by the degradation rate, depending on if the number of cows exceeds the carrying capacity.") {
27
        @Override
28
        public double calculateNewCowHealth(Commons commons, UserCommons user, int totalCows, CommonsRepository commonsRepository) {
29 2 1. calculateNewCowHealth : changed conditional boundary → KILLED
2. calculateNewCowHealth : negated conditional → KILLED
            if (totalCows <= Commons.computeEffectiveCapacity(commons, commonsRepository)) {
30 2 1. calculateNewCowHealth : Replaced double addition with subtraction → KILLED
2. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$2::calculateNewCowHealth → KILLED
                return user.getCowHealth() + commons.getDegradationRate();
31
            } else {
32 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 user.getCowHealth() - commons.getDegradationRate();
33
            }
34
        }
35
    },
36
    Noop("Do nothing", "Cow health does not change.") {
37
        @Override
38
        public double calculateNewCowHealth(Commons commons, UserCommons user, int totalCows, CommonsRepository commonsRepository) {
39 1 1. calculateNewCowHealth : replaced double return with 0.0d for edu/ucsb/cs156/happiercows/strategies/CowHealthUpdateStrategies$3::calculateNewCowHealth → KILLED
            return user.getCowHealth();
40
        }
41
    };
42
43
    private final String displayName;
44
    private final String description;
45
46
    public final static CowHealthUpdateStrategies DEFAULT_ABOVE_CAPACITY = Linear;
47
    public final static CowHealthUpdateStrategies DEFAULT_BELOW_CAPACITY = Constant;
48
}

Mutations

23

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 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:linear_updates_health_proportional_to_num_cows_over_capacity()]
Replaced double subtraction with addition → KILLED

4.4
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:constant_changes_by_constant_amount()]
changed conditional boundary → 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()]
negated conditional → KILLED

30

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 addition with subtraction → 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

32

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

39

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

Active mutators

Tests examined


Report generated by PIT 1.7.3