Commons.java

1
package edu.ucsb.cs156.happiercows.entities;
2
3
import com.fasterxml.jackson.annotation.JsonIgnore;
4
import edu.ucsb.cs156.happiercows.strategies.CowHealthUpdateStrategies;
5
import lombok.AllArgsConstructor;
6
import lombok.Builder;
7
import lombok.Data;
8
import lombok.NoArgsConstructor;
9
10
import jakarta.persistence.*;
11
import java.time.LocalDateTime;
12
import java.util.List;
13
14
15
16
@Data
17
@AllArgsConstructor
18
@NoArgsConstructor
19
@Builder
20
@Entity(name = "commons")
21
public class Commons {
22
    @Id
23
    @GeneratedValue(strategy = GenerationType.IDENTITY)
24
    private long id;
25
26
    private String name;
27
    private double cowPrice;
28
    private double milkPrice;
29
    private double startingBalance;
30
    private LocalDateTime startingDate;
31
32
    @Column(nullable = false)
33
    private LocalDateTime lastDate;
34
35
    private boolean showLeaderboard;
36
37
    private boolean showChat;
38
39
    private boolean showOverviewSection;
40
    private boolean showCowsPerFarmerSection;
41
    private boolean showHistogramSection;
42
    private boolean showTrendsSection;
43
    private boolean showHealthSection;
44
    private boolean showTotalCowsSection;
45
    private boolean showFarmerLeaderboardSection;
46
    
47
    private int capacityPerUser;
48
    private int carryingCapacity;
49
    private double degradationRate;
50
51
    private boolean hidden;
52
53
    // Optional link to a Course (see issue #251). When set, only students and
54
    // staff enrolled in this course (or admins) may see/join this commons.
55
    private Long courseId;
56
57
    // these defaults match old behavior
58
    @Enumerated(EnumType.STRING)
59
    @Builder.Default
60
    private CowHealthUpdateStrategies belowCapacityHealthUpdateStrategy = CowHealthUpdateStrategies.DEFAULT_BELOW_CAPACITY;
61
    @Enumerated(EnumType.STRING)
62
    @Builder.Default
63
    private CowHealthUpdateStrategies aboveCapacityHealthUpdateStrategy = CowHealthUpdateStrategies.DEFAULT_ABOVE_CAPACITY;
64
65
66
    @OneToMany(mappedBy = "commons", cascade = CascadeType.REMOVE)
67
    @JsonIgnore
68
    private List<UserCommons> joinedUsers;
69
70
    /**
71
     * The starting date is the first day of play, and the last date is the
72
     * last day of play: a game is in progress from midnight (00:00 local
73
     * time) at the beginning of the starting date, up to (but not including)
74
     * midnight at the end of the last date.
75
     *
76
     * @param now the date/time to check against
77
     * @return whether the game is in progress at <code>now</code>
78
     */
79
    public boolean gameInProgress(LocalDateTime now) {
80
        LocalDateTime gameStart = startingDate.toLocalDate().atStartOfDay();
81
        LocalDateTime gameEnd = lastDate.toLocalDate().plusDays(1).atStartOfDay();
82 3 1. gameInProgress : replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED
2. gameInProgress : negated conditional → KILLED
3. gameInProgress : negated conditional → KILLED
        return !now.isBefore(gameStart) && now.isBefore(gameEnd);
83
    }
84
85
    public boolean gameInProgress() {
86 2 1. gameInProgress : replaced boolean return with false for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED
2. gameInProgress : replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED
        return gameInProgress(LocalDateTime.now());
87
    }
88
89
    /**
90
     * The end date has passed when <code>now</code> is at or after midnight
91
     * at the end of the last date (i.e. the last date is the last day of
92
     * play).
93
     *
94
     * @param now the date/time to check against
95
     * @return whether the game has ended as of <code>now</code>
96
     */
97
    public boolean endDateHasPassed(LocalDateTime now) {
98
        LocalDateTime gameEnd = lastDate.toLocalDate().plusDays(1).atStartOfDay();
99 2 1. endDateHasPassed : negated conditional → KILLED
2. endDateHasPassed : replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Commons::endDateHasPassed → KILLED
        return !now.isBefore(gameEnd);
100
    }
101
}

Mutations

82

1.1
Location : gameInProgress
Killed by : edu.ucsb.cs156.happiercows.entities.CommonsTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.entities.CommonsTests]/[method:test_gameInProgress_false_before_start_date()]
replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED

2.2
Location : gameInProgress
Killed by : edu.ucsb.cs156.happiercows.entities.CommonsTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.entities.CommonsTests]/[method:test_gameInProgress_false_before_start_date()]
negated conditional → KILLED

3.3
Location : gameInProgress
Killed by : edu.ucsb.cs156.happiercows.entities.CommonsTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.entities.CommonsTests]/[method:test_gameInProgress_true_just_after_midnight_on_start_date()]
negated conditional → KILLED

86

1.1
Location : gameInProgress
Killed by : edu.ucsb.cs156.happiercows.entities.CommonsTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.entities.CommonsTests]/[method:test_gameInProgress_true()]
replaced boolean return with false for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED

2.2
Location : gameInProgress
Killed by : edu.ucsb.cs156.happiercows.entities.CommonsTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.entities.CommonsTests]/[method:test_gameInProgress_not_started()]
replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Commons::gameInProgress → KILLED

99

1.1
Location : endDateHasPassed
Killed by : edu.ucsb.cs156.happiercows.entities.CommonsTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.entities.CommonsTests]/[method:test_endDateHasPassed_false_during_the_last_date()]
negated conditional → KILLED

2.2
Location : endDateHasPassed
Killed by : edu.ucsb.cs156.happiercows.entities.CommonsTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.entities.CommonsTests]/[method:test_endDateHasPassed_false_during_the_last_date()]
replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Commons::endDateHasPassed → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0