History.java

1
package com.takenoko.engine;
2
3
import com.takenoko.bot.utils.HistoryAnalysis;
4
import com.takenoko.stats.HistoryStatistics;
5
import com.takenoko.stats.HistoryStatisticsItem;
6
import java.util.*;
7
import java.util.stream.Collectors;
8
9
/** Class that stores the history of a game. */
10
public class History extends HashMap<UUID, List<TurnHistory>> {
11
12
    private UUID currentBotManagerUUID;
13
    private HistoryStatistics historyStatistics = new HistoryStatistics();
14
15
    public History(History historyMap) {
16
        super(historyMap);
17
        currentBotManagerUUID = historyMap.currentBotManagerUUID;
18
        historyStatistics = historyMap.historyStatistics;
19
    }
20
21
    public History() {
22
        super();
23
    }
24
25
    public UUID getCurrentBotManagerUUID() {
26 1 1. getCurrentBotManagerUUID : replaced return value with null for com/takenoko/engine/History::getCurrentBotManagerUUID → TIMED_OUT
        return currentBotManagerUUID;
27
    }
28
29
    public void setCurrentBotManagerUUID(UUID currentBotManagerUUID) {
30
        this.currentBotManagerUUID = currentBotManagerUUID;
31
    }
32
33
    public void addBotManager(BotManager botManager) {
34
        put(botManager.getUniqueID(), new ArrayList<>(List.of()));
35
        historyStatistics.put(botManager, new HistoryStatisticsItem());
36
    }
37
38
    public void addTurnHistory(BotManager botManager, TurnHistory turnHistory) {
39 1 1. lambda$addTurnHistory$0 : replaced return value with Collections.emptyList for com/takenoko/engine/History::lambda$addTurnHistory$0 → NO_COVERAGE
        computeIfAbsent(botManager.getUniqueID(), k -> new ArrayList<>()).add(turnHistory);
40
    }
41
42
    public void updateHistoryStatistics(BotManager botManager) {
43 3 1. updateHistoryStatistics : changed conditional boundary → TIMED_OUT
2. updateHistoryStatistics : negated conditional → TIMED_OUT
3. updateHistoryStatistics : negated conditional → TIMED_OUT
        if (containsKey(botManager.getUniqueID()) && get(botManager.getUniqueID()).size() > 1) {
44 1 1. updateHistoryStatistics : removed call to com/takenoko/stats/HistoryStatistics::incrementNumberOfRounds → TIMED_OUT
            historyStatistics.incrementNumberOfRounds(
45
                    botManager, HistoryAnalysis.getGameProgress(this));
46 1 1. updateHistoryStatistics : removed call to com/takenoko/stats/HistoryStatistics::updateEvolution → TIMED_OUT
            historyStatistics.updateEvolution(botManager, this);
47
        }
48
    }
49
50
    public History copy() {
51 1 1. copy : replaced return value with null for com/takenoko/engine/History::copy → KILLED
        return new History(this);
52
    }
53
54
    /**
55
     * Returns a map of the latest history item for each bot manager in the history.
56
     *
57
     * @return a map of the latest history item for each bot manager.
58
     */
59
    public Map<UUID, HistoryItem> getLatestHistoryItems() {
60 1 1. getLatestHistoryItems : replaced return value with Collections.emptyMap for com/takenoko/engine/History::getLatestHistoryItems → KILLED
        return entrySet().stream()
61 2 1. lambda$getLatestHistoryItems$1 : replaced boolean return with true for com/takenoko/engine/History::lambda$getLatestHistoryItems$1 → TIMED_OUT
2. lambda$getLatestHistoryItems$1 : negated conditional → KILLED
                .filter(uuidListEntry -> !uuidListEntry.getValue().isEmpty())
62
                .map(
63
                        uuidListEntry -> {
64
                            TurnHistory lastRound =
65
                                    uuidListEntry
66
                                            .getValue()
67 1 1. lambda$getLatestHistoryItems$2 : Replaced integer subtraction with addition → KILLED
                                            .get(uuidListEntry.getValue().size() - 1);
68 1 1. lambda$getLatestHistoryItems$2 : Replaced integer subtraction with addition → KILLED
                            HistoryItem lastHistoryItem = lastRound.get(lastRound.size() - 1);
69
70 1 1. lambda$getLatestHistoryItems$2 : replaced return value with null for com/takenoko/engine/History::lambda$getLatestHistoryItems$2 → KILLED
                            return new AbstractMap.SimpleEntry<>(
71
                                    uuidListEntry.getKey(), lastHistoryItem);
72
                        })
73
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
74
    }
75
76
    @Override
77
    public boolean equals(Object o) {
78 2 1. equals : negated conditional → KILLED
2. equals : replaced boolean return with false for com/takenoko/engine/History::equals → KILLED
        if (this == o) return true;
79 3 1. equals : negated conditional → KILLED
2. equals : negated conditional → KILLED
3. equals : replaced boolean return with true for com/takenoko/engine/History::equals → KILLED
        if (o == null || getClass() != o.getClass()) return false;
80 2 1. equals : negated conditional → KILLED
2. equals : replaced boolean return with true for com/takenoko/engine/History::equals → KILLED
        if (!super.equals(o)) return false;
81
        History history = (History) o;
82 2 1. equals : replaced boolean return with true for com/takenoko/engine/History::equals → SURVIVED
2. equals : replaced boolean return with false for com/takenoko/engine/History::equals → KILLED
        return Objects.equals(getCurrentBotManagerUUID(), history.getCurrentBotManagerUUID());
83
    }
84
85
    @Override
86
    public int hashCode() {
87 1 1. hashCode : replaced int return with 0 for com/takenoko/engine/History::hashCode → KILLED
        return Objects.hash(super.hashCode(), getCurrentBotManagerUUID());
88
    }
89
90
    public HistoryStatistics getHistoryStatistics() {
91 1 1. getHistoryStatistics : replaced return value with null for com/takenoko/engine/History::getHistoryStatistics → KILLED
        return historyStatistics;
92
    }
93
}

Mutations

26

1.1
Location : getCurrentBotManagerUUID
Killed by : none
replaced return value with null for com/takenoko/engine/History::getCurrentBotManagerUUID → TIMED_OUT

39

1.1
Location : lambda$addTurnHistory$0
Killed by : none
replaced return value with Collections.emptyList for com/takenoko/engine/History::lambda$addTurnHistory$0 → NO_COVERAGE

43

1.1
Location : updateHistoryStatistics
Killed by : none
changed conditional boundary → TIMED_OUT

2.2
Location : updateHistoryStatistics
Killed by : none
negated conditional → TIMED_OUT

3.3
Location : updateHistoryStatistics
Killed by : none
negated conditional → TIMED_OUT

44

1.1
Location : updateHistoryStatistics
Killed by : none
removed call to com/takenoko/stats/HistoryStatistics::incrementNumberOfRounds → TIMED_OUT

46

1.1
Location : updateHistoryStatistics
Killed by : none
removed call to com/takenoko/stats/HistoryStatistics::updateEvolution → TIMED_OUT

51

1.1
Location : copy
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:Copy]/[method:shouldReturnACopyOfTheHistory()]
replaced return value with null for com/takenoko/engine/History::copy → KILLED

60

1.1
Location : getLatestHistoryItems
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:GetLatestHistoryItems]/[method:shouldReturnLatestHistoryItems()]
replaced return value with Collections.emptyMap for com/takenoko/engine/History::getLatestHistoryItems → KILLED

61

1.1
Location : lambda$getLatestHistoryItems$1
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:GetLatestHistoryItems]/[method:shouldReturnLatestHistoryItems()]
negated conditional → KILLED

2.2
Location : lambda$getLatestHistoryItems$1
Killed by : none
replaced boolean return with true for com/takenoko/engine/History::lambda$getLatestHistoryItems$1 → TIMED_OUT

67

1.1
Location : lambda$getLatestHistoryItems$2
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:GetLatestHistoryItems]/[method:shouldReturnLatestHistoryItems()]
Replaced integer subtraction with addition → KILLED

68

1.1
Location : lambda$getLatestHistoryItems$2
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:GetLatestHistoryItems]/[method:shouldReturnLatestHistoryItems()]
Replaced integer subtraction with addition → KILLED

70

1.1
Location : lambda$getLatestHistoryItems$2
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:GetLatestHistoryItems]/[method:shouldReturnLatestHistoryItems()]
replaced return value with null for com/takenoko/engine/History::lambda$getLatestHistoryItems$2 → KILLED

78

1.1
Location : equals
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:Equals]/[method:shouldReturnFalseWhenComparingToDifferentClass()]
negated conditional → KILLED

2.2
Location : equals
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:Equals]/[method:equals_shouldReturnTrueWhenComparingSameObject()]
replaced boolean return with false for com/takenoko/engine/History::equals → KILLED

79

1.1
Location : equals
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:Equals]/[method:shouldReturnTrueWhenComparingTwoEmptyHistories()]
negated conditional → KILLED

2.2
Location : equals
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:Equals]/[method:shouldReturnTrueWhenComparingTwoEmptyHistories()]
negated conditional → KILLED

3.3
Location : equals
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:Equals]/[method:shouldReturnFalseWhenComparingToDifferentClass()]
replaced boolean return with true for com/takenoko/engine/History::equals → KILLED

80

1.1
Location : equals
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:Equals]/[method:shouldReturnTrueWhenComparingTwoEmptyHistories()]
negated conditional → KILLED

2.2
Location : equals
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:Equals]/[method:shouldReturnFalseWhenComparingTwoHistoriesWithDifferentData()]
replaced boolean return with true for com/takenoko/engine/History::equals → KILLED

82

1.1
Location : equals
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:Equals]/[method:shouldReturnTrueWhenComparingTwoEmptyHistories()]
replaced boolean return with false for com/takenoko/engine/History::equals → KILLED

2.2
Location : equals
Killed by : none
replaced boolean return with true for com/takenoko/engine/History::equals → SURVIVED

87

1.1
Location : hashCode
Killed by : com.takenoko.engine.HistoryTest.[engine:junit-jupiter]/[class:com.takenoko.engine.HistoryTest]/[nested-class:HashCode]/[method:shouldReturnDifferentHashCodeWhenComparingTwoHistoriesWithDifferentData()]
replaced int return with 0 for com/takenoko/engine/History::hashCode → KILLED

91

1.1
Location : getHistoryStatistics
Killed by : com.takenoko.engine.GameEngineTest.[engine:junit-jupiter]/[class:com.takenoko.engine.GameEngineTest]/[nested-class:TestEndGame]/[method:endGame_shouldSetGameStateToFinished()]
replaced return value with null for com/takenoko/engine/History::getHistoryStatistics → KILLED

Active mutators

Tests examined


Report generated by PIT 1.8.0