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

Mutations

91

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

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

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

95

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

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

108

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

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

Active mutators

Tests examined


Report generated by PIT 1.22.1