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

Mutations

86

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

90

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_ended()]
replaced boolean return with true for edu/ucsb/cs156/happiercows/entities/Game::gameInProgress → KILLED

103

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