Commons.java

1
package edu.ucsb.cs156.happiercows.entities;
2
3
import com.fasterxml.jackson.annotation.JsonGetter;
4
import com.fasterxml.jackson.annotation.JsonIgnore;
5
import com.fasterxml.jackson.annotation.JsonInclude;
6
7
import edu.ucsb.cs156.happiercows.repositories.CommonsRepository;
8
import edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategies;
9
import lombok.AllArgsConstructor;
10
import lombok.Builder;
11
import lombok.Data;
12
import lombok.NoArgsConstructor;
13
14
import javax.persistence.*;
15
16
import org.springframework.transaction.annotation.Transactional;
17
18
import java.time.LocalDateTime;
19
import java.util.List;
20
21
@Data
22
@AllArgsConstructor
23
@NoArgsConstructor
24
@Builder
25
@Entity(name = "commons")
26
public class Commons {
27
    @Id
28
    @GeneratedValue(strategy = GenerationType.IDENTITY)
29
    private long id;
30
31
    private String name;
32
    private double cowPrice;
33
    private double milkPrice;
34
    private double startingBalance;
35
    private LocalDateTime startingDate;
36
    private boolean showLeaderboard;
37
38
    private int carryingCapacity;
39
    private int capacityPerUser;
40
    private double degradationRate;
41
42
    // these defaults match old behavior
43
    @Enumerated(EnumType.STRING)
44
    @Builder.Default
45
    private CowHealthUpdateStrategies belowCapacityHealthUpdateStrategy = CowHealthUpdateStrategies.DEFAULT_BELOW_CAPACITY;
46
    @Enumerated(EnumType.STRING)
47
    @Builder.Default
48
    private CowHealthUpdateStrategies aboveCapacityHealthUpdateStrategy = CowHealthUpdateStrategies.DEFAULT_ABOVE_CAPACITY;
49
50
51
    @OneToMany(mappedBy = "commons", cascade = CascadeType.REMOVE)
52
    @JsonIgnore
53
    private List<UserCommons> joinedUsers;
54
55
56
    public static int computeEffectiveCapacity(Commons commons, CommonsRepository commonsRepository) {
57
        int numUsers = (commonsRepository.getNumUsers(commons.getId())).orElse(0);
58 2 1. computeEffectiveCapacity : Replaced integer multiplication with division → KILLED
2. computeEffectiveCapacity : replaced int return with 0 for edu/ucsb/cs156/happiercows/entities/Commons::computeEffectiveCapacity → KILLED
        return Math.max(commons.getCapacityPerUser() * numUsers, commons.getCarryingCapacity());
59
    }
60
61
}

Mutations

58

1.1
Location : computeEffectiveCapacity
Killed by : edu.ucsb.cs156.happiercows.entities.CommonsTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.entities.CommonsTest]/[method:testComputeEffectiveCapacity_nousers()]
Replaced integer multiplication with division → KILLED

2.2
Location : computeEffectiveCapacity
Killed by : edu.ucsb.cs156.happiercows.entities.CommonsTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.entities.CommonsTest]/[method:testComputeEffectiveCapacity_nousers()]
replaced int return with 0 for edu/ucsb/cs156/happiercows/entities/Commons::computeEffectiveCapacity → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3