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

Mutations

93

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

97

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

110

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