BoardStatistics.java

1
package com.takenoko.stats;
2
3
import com.takenoko.engine.Board;
4
import com.takenoko.layers.tile.ImprovementType;
5
import com.takenoko.layers.tile.Tile;
6
import com.takenoko.layers.tile.TileColor;
7
import com.takenoko.vector.PositionVector;
8
import java.util.*;
9
10
public class BoardStatistics {
11
    public final Map<TileColor, Integer> tilesPlaced;
12
    public final Map<ImprovementType, Integer> improvements;
13
14
    public float percentageOfIrrigation;
15
    public float totalNbOfTiles;
16
17
    public BoardStatistics(
18
            Map<TileColor, Integer> tilesPlaced,
19
            Map<ImprovementType, Integer> improvements,
20
            float percentageOfIrrigation,
21
            float totalNbOfTiles) {
22
        this.tilesPlaced = tilesPlaced;
23
        this.improvements = improvements;
24
        this.percentageOfIrrigation = percentageOfIrrigation;
25
        this.totalNbOfTiles = totalNbOfTiles;
26
    }
27
28
    public BoardStatistics(BoardStatistics boardStatistics) {
29
        this.tilesPlaced = boardStatistics.tilesPlaced;
30
        this.percentageOfIrrigation = boardStatistics.percentageOfIrrigation;
31
        this.improvements = boardStatistics.improvements;
32
        this.totalNbOfTiles = boardStatistics.totalNbOfTiles;
33
    }
34
35
    public BoardStatistics() {
36
        this(new HashMap<>(), new HashMap<>(), 0, 0);
37
    }
38
39
    public void updateImprovements(ImprovementType improvementType) {
40 1 1. updateImprovements : negated conditional → KILLED
        if (improvementType == null) {
41
            throw new IllegalArgumentException();
42
        }
43 1 1. updateImprovements : negated conditional → KILLED
        if (improvements.containsKey(improvementType)) {
44 1 1. updateImprovements : Replaced integer addition with subtraction → KILLED
            improvements.replace(improvementType, improvements.get(improvementType) + 1);
45
        } else {
46
            improvements.put(improvementType, 1);
47
        }
48
    }
49
50
    public void updateTilesPlaced(TileColor tileColor) {
51 1 1. updateTilesPlaced : negated conditional → KILLED
        if (tileColor == null) {
52
            throw new IllegalArgumentException();
53
        }
54 1 1. updateTilesPlaced : negated conditional → KILLED
        if (tilesPlaced.containsKey(tileColor)) {
55 1 1. updateTilesPlaced : Replaced integer addition with subtraction → TIMED_OUT
            tilesPlaced.put(tileColor, tilesPlaced.get(tileColor) + 1);
56
        } else {
57
            tilesPlaced.put(tileColor, 1);
58
        }
59
    }
60
61
    public void analyzeBoard(Board board) {
62 1 1. analyzeBoard : negated conditional → KILLED
        if (board == null) {
63
            throw new IllegalArgumentException();
64
        }
65
        totalNbOfTiles = board.getTilesWithoutPond().size();
66
        float irrigatedTiles = 0;
67
        for (Map.Entry<PositionVector, Tile> entry : board.getTilesWithoutPond().entrySet()) {
68
            Optional<ImprovementType> improvementType = entry.getValue().getImprovement();
69 2 1. analyzeBoard : negated conditional → TIMED_OUT
2. analyzeBoard : Replaced float addition with subtraction → KILLED
            if (board.isIrrigatedAt(entry.getKey())) irrigatedTiles++;
70 1 1. analyzeBoard : removed call to java/util/Optional::ifPresent → KILLED
            improvementType.ifPresent(this::updateImprovements);
71 1 1. analyzeBoard : removed call to com/takenoko/stats/BoardStatistics::updateTilesPlaced → KILLED
            updateTilesPlaced(entry.getValue().getColor());
72
        }
73 2 1. analyzeBoard : Replaced float division with multiplication → KILLED
2. analyzeBoard : Replaced float multiplication with division → KILLED
        percentageOfIrrigation = irrigatedTiles / totalNbOfTiles * 100;
74
    }
75
76
    @Override
77
    public String toString() {
78
        StringBuilder statistics = new StringBuilder();
79
        String lineJump = "\n \t \t \t";
80
        String indentation = "\t\t* ";
81
        statistics.append("=========== Board Related Metrics ===========");
82
        statistics
83
                .append(lineJump)
84
                .append("\t -Total number of tiles placed : ")
85
                .append(totalNbOfTiles)
86
                .append(lineJump)
87
                .append("\t -Percentage of irrigated tiles : ")
88
                .append(percentageOfIrrigation)
89
                .append("%");
90
        TreeMap<TileColor, Integer> sortedTilesPlaced = new TreeMap<>(tilesPlaced);
91
        statistics.append(lineJump).append("\t -Tiles placed :");
92
        for (TileColor tileColor : sortedTilesPlaced.keySet()) {
93
            statistics
94
                    .append(lineJump)
95
                    .append(indentation)
96
                    .append(tileColor)
97
                    .append(" : ")
98
                    .append(tilesPlaced.get(tileColor));
99
        }
100 1 1. toString : replaced return value with "" for com/takenoko/stats/BoardStatistics::toString → TIMED_OUT
        return statistics.toString();
101
    }
102
103
    public BoardStatistics copy() {
104 1 1. copy : replaced return value with null for com/takenoko/stats/BoardStatistics::copy → NO_COVERAGE
        return new BoardStatistics(this);
105
    }
106
107
    @Override
108
    public boolean equals(Object o) {
109 2 1. equals : negated conditional → NO_COVERAGE
2. equals : replaced boolean return with false for com/takenoko/stats/BoardStatistics::equals → NO_COVERAGE
        if (this == o) return true;
110 3 1. equals : negated conditional → NO_COVERAGE
2. equals : negated conditional → NO_COVERAGE
3. equals : replaced boolean return with true for com/takenoko/stats/BoardStatistics::equals → NO_COVERAGE
        if (o == null || getClass() != o.getClass()) return false;
111
        BoardStatistics that = (BoardStatistics) o;
112 2 1. equals : negated conditional → NO_COVERAGE
2. equals : replaced boolean return with true for com/takenoko/stats/BoardStatistics::equals → NO_COVERAGE
        return Float.compare(that.percentageOfIrrigation, percentageOfIrrigation) == 0
113 1 1. equals : negated conditional → NO_COVERAGE
                && tilesPlaced.equals(that.tilesPlaced)
114 1 1. equals : negated conditional → NO_COVERAGE
                && improvements.equals(that.improvements);
115
    }
116
117
    @Override
118
    public int hashCode() {
119 1 1. hashCode : replaced int return with 0 for com/takenoko/stats/BoardStatistics::hashCode → TIMED_OUT
        return Objects.hash(tilesPlaced, improvements, percentageOfIrrigation);
120
    }
121
122
    public Map<ImprovementType, Integer> getImprovements() {
123 1 1. getImprovements : replaced return value with Collections.emptyMap for com/takenoko/stats/BoardStatistics::getImprovements → KILLED
        return improvements;
124
    }
125
126
    public float getPercentageOfIrrigation() {
127 1 1. getPercentageOfIrrigation : replaced float return with 0.0f for com/takenoko/stats/BoardStatistics::getPercentageOfIrrigation → KILLED
        return percentageOfIrrigation;
128
    }
129
130
    public float getTotalNbOfTiles() {
131 1 1. getTotalNbOfTiles : replaced float return with 0.0f for com/takenoko/stats/BoardStatistics::getTotalNbOfTiles → KILLED
        return totalNbOfTiles;
132
    }
133
}

Mutations

40

1.1
Location : updateImprovements
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestUpdateObjectivesRedeemed]/[method:ifParameterIsNull_shouldThrowException()]
negated conditional → KILLED

43

1.1
Location : updateImprovements
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestUpdateObjectivesRedeemed]/[method:whenTheUpdatedImprovementIsNew_shouldAddNewEntry()]
negated conditional → KILLED

44

1.1
Location : updateImprovements
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestUpdateObjectivesRedeemed]/[method:shouldIncrementNumberOfImprovementForTheRightType()]
Replaced integer addition with subtraction → KILLED

51

1.1
Location : updateTilesPlaced
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestAnalyzeBoard]/[method:GeneralTests()]
negated conditional → KILLED

54

1.1
Location : updateTilesPlaced
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestAnalyzeBoard]/[method:GeneralTests()]
negated conditional → KILLED

55

1.1
Location : updateTilesPlaced
Killed by : none
Replaced integer addition with subtraction → TIMED_OUT

62

1.1
Location : analyzeBoard
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestAnalyzeBoard]/[method:shouldThrowExceptionIfArgumentIsNull()]
negated conditional → KILLED

69

1.1
Location : analyzeBoard
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestAnalyzeBoard]/[method:GeneralTests()]
Replaced float addition with subtraction → KILLED

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

70

1.1
Location : analyzeBoard
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestAnalyzeBoard]/[method:GeneralTests()]
removed call to java/util/Optional::ifPresent → KILLED

71

1.1
Location : analyzeBoard
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestAnalyzeBoard]/[method:GeneralTests()]
removed call to com/takenoko/stats/BoardStatistics::updateTilesPlaced → KILLED

73

1.1
Location : analyzeBoard
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestAnalyzeBoard]/[method:GeneralTests()]
Replaced float division with multiplication → KILLED

2.2
Location : analyzeBoard
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestAnalyzeBoard]/[method:GeneralTests()]
Replaced float multiplication with division → KILLED

100

1.1
Location : toString
Killed by : none
replaced return value with "" for com/takenoko/stats/BoardStatistics::toString → TIMED_OUT

104

1.1
Location : copy
Killed by : none
replaced return value with null for com/takenoko/stats/BoardStatistics::copy → NO_COVERAGE

109

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : equals
Killed by : none
replaced boolean return with false for com/takenoko/stats/BoardStatistics::equals → NO_COVERAGE

110

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : equals
Killed by : none
replaced boolean return with true for com/takenoko/stats/BoardStatistics::equals → NO_COVERAGE

112

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : equals
Killed by : none
replaced boolean return with true for com/takenoko/stats/BoardStatistics::equals → NO_COVERAGE

113

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

114

1.1
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

119

1.1
Location : hashCode
Killed by : none
replaced int return with 0 for com/takenoko/stats/BoardStatistics::hashCode → TIMED_OUT

123

1.1
Location : getImprovements
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestUpdateObjectivesRedeemed]/[method:whenTheUpdatedImprovementIsNew_shouldAddNewEntry()]
replaced return value with Collections.emptyMap for com/takenoko/stats/BoardStatistics::getImprovements → KILLED

127

1.1
Location : getPercentageOfIrrigation
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestAnalyzeBoard]/[method:GeneralTests()]
replaced float return with 0.0f for com/takenoko/stats/BoardStatistics::getPercentageOfIrrigation → KILLED

131

1.1
Location : getTotalNbOfTiles
Killed by : com.takenoko.engine.BoardStatisticsTest.[engine:junit-jupiter]/[class:com.takenoko.engine.BoardStatisticsTest]/[nested-class:TestAnalyzeBoard]/[method:GeneralTests()]
replaced float return with 0.0f for com/takenoko/stats/BoardStatistics::getTotalNbOfTiles → KILLED

Active mutators

Tests examined


Report generated by PIT 1.8.0