Actor.java

1
package com.takenoko.actors;
2
3
import com.takenoko.engine.Board;
4
import com.takenoko.layers.bamboo.LayerBambooStack;
5
import com.takenoko.vector.PositionVector;
6
import java.util.List;
7
import java.util.Map;
8
import java.util.Objects;
9
10
public abstract class Actor {
11
    PositionVector position;
12
13
    protected Actor(PositionVector position) {
14
        this.position = position;
15
    }
16
17
    /**
18
     * @return the position of the actor
19
     */
20
    public PositionVector getPosition() {
21 1 1. getPosition : replaced return value with null for com/takenoko/actors/Actor::getPosition → KILLED
        return position;
22
    }
23
24
    /**
25
     * Check if the move is possible. The actor can only move in a straight line on the board tiles.
26
     *
27
     * @param vector the vector to move the actor
28
     * @return true if the move is possible, false otherwise
29
     */
30
    protected boolean isMovePossible(PositionVector vector, Board board) {
31
        // check if the actor is moving in a straight line
32 3 1. isMovePossible : negated conditional → KILLED
2. isMovePossible : negated conditional → KILLED
3. isMovePossible : negated conditional → KILLED
        if (!(vector.r() == 0 || vector.q() == 0 || vector.s() == 0)) {
33 1 1. isMovePossible : replaced boolean return with true for com/takenoko/actors/Actor::isMovePossible → KILLED
            return false;
34
        }
35
36
        // check if the actor is moving on a tile
37 3 1. isMovePossible : changed conditional boundary → KILLED
2. isMovePossible : Replaced double addition with subtraction → KILLED
3. isMovePossible : negated conditional → KILLED
        for (int i = 0; i < vector.length() + 1; i++) {
38
            PositionVector ray =
39
                    this.position.add(vector.normalize().multiply(i)).toPositionVector();
40
41 1 1. isMovePossible : negated conditional → KILLED
            if (!board.isTile(ray)) {
42 1 1. isMovePossible : replaced boolean return with true for com/takenoko/actors/Actor::isMovePossible → KILLED
                return false;
43
            }
44
        }
45 1 1. isMovePossible : replaced boolean return with false for com/takenoko/actors/Actor::isMovePossible → KILLED
        return true;
46
    }
47
48
    /**
49
     * Returns possible moves for the actor.
50
     *
51
     * @return the possible moves
52
     */
53
    public List<PositionVector> getPossibleMoves(Board board) {
54 1 1. getPossibleMoves : replaced return value with Collections.emptyList for com/takenoko/actors/Actor::getPossibleMoves → KILLED
        return board.getTiles().keySet().stream()
55 1 1. lambda$getPossibleMoves$0 : replaced return value with null for com/takenoko/actors/Actor::lambda$getPossibleMoves$0 → KILLED
                .map(v -> v.sub(position).toPositionVector())
56 2 1. lambda$getPossibleMoves$1 : replaced boolean return with false for com/takenoko/actors/Actor::lambda$getPossibleMoves$1 → KILLED
2. lambda$getPossibleMoves$1 : replaced boolean return with true for com/takenoko/actors/Actor::lambda$getPossibleMoves$1 → KILLED
                .filter(v -> isMovePossible(v, board))
57 2 1. lambda$getPossibleMoves$2 : negated conditional → KILLED
2. lambda$getPossibleMoves$2 : replaced boolean return with true for com/takenoko/actors/Actor::lambda$getPossibleMoves$2 → KILLED
                .filter(v -> !v.equals(new PositionVector(0, 0, 0)))
58
                .toList();
59
    }
60
61
    /**
62
     * Move the panda with a vector and try to eat bamboo.
63
     *
64
     * @param vector the vector to move the panda
65
     */
66
    public Map<PositionVector, LayerBambooStack> move(PositionVector vector, Board board) {
67 1 1. move : negated conditional → KILLED
        if (!isMovePossible(vector, board)) {
68
            throw new IllegalArgumentException("This move is not possible");
69
        }
70
        position = position.add(vector).toPositionVector();
71 1 1. move : replaced return value with Collections.emptyMap for com/takenoko/actors/Actor::move → KILLED
        return this.afterMove(board);
72
    }
73
74
    public abstract Map<PositionVector, LayerBambooStack> afterMove(Board board);
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/actors/Actor::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/actors/Actor::equals → KILLED
        if (o == null || getClass() != o.getClass()) return false;
80
        Actor actor = (Actor) o;
81 2 1. equals : replaced boolean return with false for com/takenoko/actors/Actor::equals → KILLED
2. equals : replaced boolean return with true for com/takenoko/actors/Actor::equals → KILLED
        return getPosition().equals(actor.getPosition());
82
    }
83
84
    @Override
85
    public int hashCode() {
86 1 1. hashCode : replaced int return with 0 for com/takenoko/actors/Actor::hashCode → KILLED
        return Objects.hash(getPosition());
87
    }
88
89
    public PositionVector getPositionVector() {
90 1 1. getPositionVector : replaced return value with null for com/takenoko/actors/Actor::getPositionVector → KILLED
        return position;
91
    }
92
}

Mutations

21

1.1
Location : getPosition
Killed by : com.takenoko.actors.GardenerTest.[engine:junit-jupiter]/[class:com.takenoko.actors.GardenerTest]/[nested-class:TestCopy]/[method:shouldMakeACopyOfTheGardener()]
replaced return value with null for com/takenoko/actors/Actor::getPosition → KILLED

32

1.1
Location : isMovePossible
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestHashCode]/[method:shouldReturnADifferentHashcodeIfTheTwoObjectsAreNotTheSame()]
negated conditional → KILLED

2.2
Location : isMovePossible
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAListOfPossibleMoves()]
negated conditional → KILLED

3.3
Location : isMovePossible
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAListOfPossibleMoves()]
negated conditional → KILLED

33

1.1
Location : isMovePossible
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestMove]/[method:shouldThrowAnExceptionIfThePandaIsNotMovingWithAValidVector()]
replaced boolean return with true for com/takenoko/actors/Actor::isMovePossible → KILLED

37

1.1
Location : isMovePossible
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestHashCode]/[method:shouldReturnADifferentHashcodeIfTheTwoObjectsAreNotTheSame()]
changed conditional boundary → KILLED

2.2
Location : isMovePossible
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAListOfPossibleMoves()]
Replaced double addition with subtraction → KILLED

3.3
Location : isMovePossible
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAListOfPossibleMoves()]
negated conditional → KILLED

41

1.1
Location : isMovePossible
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestHashCode]/[method:shouldReturnADifferentHashcodeIfTheTwoObjectsAreNotTheSame()]
negated conditional → KILLED

42

1.1
Location : isMovePossible
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAListOfPossibleMoves()]
replaced boolean return with true for com/takenoko/actors/Actor::isMovePossible → KILLED

45

1.1
Location : isMovePossible
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestHashCode]/[method:shouldReturnADifferentHashcodeIfTheTwoObjectsAreNotTheSame()]
replaced boolean return with false for com/takenoko/actors/Actor::isMovePossible → KILLED

54

1.1
Location : getPossibleMoves
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAllPositionIfWeatherIsStorm()]
replaced return value with Collections.emptyList for com/takenoko/actors/Actor::getPossibleMoves → KILLED

55

1.1
Location : lambda$getPossibleMoves$0
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAllPositionIfWeatherIsStorm()]
replaced return value with null for com/takenoko/actors/Actor::lambda$getPossibleMoves$0 → KILLED

56

1.1
Location : lambda$getPossibleMoves$1
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAllPositionIfWeatherIsStorm()]
replaced boolean return with false for com/takenoko/actors/Actor::lambda$getPossibleMoves$1 → KILLED

2.2
Location : lambda$getPossibleMoves$1
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAListOfPossibleMoves()]
replaced boolean return with true for com/takenoko/actors/Actor::lambda$getPossibleMoves$1 → KILLED

57

1.1
Location : lambda$getPossibleMoves$2
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAllPositionIfWeatherIsStorm()]
negated conditional → KILLED

2.2
Location : lambda$getPossibleMoves$2
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestGetPossibleMoves]/[method:shouldReturnAllPositionIfWeatherIsStorm()]
replaced boolean return with true for com/takenoko/actors/Actor::lambda$getPossibleMoves$2 → KILLED

67

1.1
Location : move
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestMove]/[method:shouldThrowAnExceptionIfThePandaIsNotMovingWithAValidVector()]
negated conditional → KILLED

71

1.1
Location : move
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestAfterMove]/[method:shouldEatABambooIfThereIsOne()]
replaced return value with Collections.emptyMap for com/takenoko/actors/Actor::move → KILLED

78

1.1
Location : equals
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestEquals]/[method:shouldReturnFalseIfTheTwoObjectsAreOfDifferentClasses()]
negated conditional → KILLED

2.2
Location : equals
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestEquals]/[method:equals_shouldReturnTrueIfTheTwoObjectsAreTheSame()]
replaced boolean return with false for com/takenoko/actors/Actor::equals → KILLED

79

1.1
Location : equals
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestEquals]/[method:shouldReturnTrueIfTheTwoObjectsAreEqual()]
negated conditional → KILLED

2.2
Location : equals
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestEquals]/[method:shouldReturnFalseIfTheTwoObjectsAreOfDifferentClasses()]
negated conditional → KILLED

3.3
Location : equals
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestEquals]/[method:shouldReturnFalseIfTheTwoObjectsAreOfDifferentClasses()]
replaced boolean return with true for com/takenoko/actors/Actor::equals → KILLED

81

1.1
Location : equals
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestEquals]/[method:shouldReturnTrueIfTheTwoObjectsAreEqual()]
replaced boolean return with false for com/takenoko/actors/Actor::equals → KILLED

2.2
Location : equals
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestEquals]/[method:shouldReturnFalseIfTheTwoObjectsAreNotTheSame()]
replaced boolean return with true for com/takenoko/actors/Actor::equals → KILLED

86

1.1
Location : hashCode
Killed by : com.takenoko.actors.PandaTest.[engine:junit-jupiter]/[class:com.takenoko.actors.PandaTest]/[nested-class:TestHashCode]/[method:shouldReturnADifferentHashcodeIfTheTwoObjectsAreNotTheSame()]
replaced int return with 0 for com/takenoko/actors/Actor::hashCode → KILLED

90

1.1
Location : getPositionVector
Killed by : com.takenoko.actors.GardenerTest.[engine:junit-jupiter]/[class:com.takenoko.actors.GardenerTest]/[nested-class:TestConstructor]/[method:shouldInstantiateTheGardenerAtTheOrigin()]
replaced return value with null for com/takenoko/actors/Actor::getPositionVector → KILLED

Active mutators

Tests examined


Report generated by PIT 1.8.0