Day1.java

1
package com.roxoft.aoc.y2015;
2
3
import com.roxoft.aoc.UnexpectedSolutionException;
4
5
import java.util.Arrays;
6
import java.util.List;
7
8
public final class Day1 {
9
    /** Compiled department store directions for Santa. */
10
    private final List<Integer> numericalDirections;
11
12
    private Day1(final String directionsForSanta) {
13
        this.numericalDirections = Arrays.stream(directionsForSanta.split("")).map(i -> switch (i) {
14
            case "(" -> 1;
15
            case ")" -> -1;
16
            default -> 0;
17
        }).toList();
18
    }
19
20
    /**
21
     * @param directions for Santa to follow
22
     * @return a {@link Day1} solutions class for the given directions.
23
     */
24
    public static Day1 of(final String directions) {
25 1 1. of : replaced return value with null for com/roxoft/aoc/y2015/Day1::of → KILLED
        return new Day1(directions);
26
    }
27
28
    /**
29
     * @return Santas final location after following all instructions.
30
     */
31
    public int finalLocation() {
32 2 1. lambda$finalLocation$1 : replaced int return with 0 for com/roxoft/aoc/y2015/Day1::lambda$finalLocation$1 → KILLED
2. finalLocation : replaced int return with 0 for com/roxoft/aoc/y2015/Day1::finalLocation → KILLED
        return numericalDirections.stream().mapToInt(i -> i).sum();
33
    }
34
35
    /**
36
     * @return the step in the given directions where Santa first enters the basement.
37
     */
38
    public int firstBasementVisit() {
39 2 1. firstBasementVisit : negated conditional → KILLED
2. firstBasementVisit : changed conditional boundary → KILLED
        for (int step = 0, location = 0; step < numericalDirections.size(); step++) {
40 1 1. firstBasementVisit : Replaced integer addition with subtraction → KILLED
            location += numericalDirections.get(step);
41 1 1. firstBasementVisit : negated conditional → KILLED
            if (location == -1) {
42 2 1. firstBasementVisit : replaced int return with 0 for com/roxoft/aoc/y2015/Day1::firstBasementVisit → KILLED
2. firstBasementVisit : Replaced integer addition with subtraction → KILLED
                return (step + 1);
43
            }
44
        }
45
46
        throw new UnexpectedSolutionException("Basement never reached!");
47
    }
48
}

Mutations

25

1.1
Location : of
Killed by : com.roxoft.aoc.y2015.Day1Test.[engine:junit-jupiter]/[class:com.roxoft.aoc.y2015.Day1Test]/[method:requirement_startLocation()]
replaced return value with null for com/roxoft/aoc/y2015/Day1::of → KILLED

32

1.1
Location : lambda$finalLocation$1
Killed by : com.roxoft.aoc.y2015.Day1Test.[engine:junit-jupiter]/[class:com.roxoft.aoc.y2015.Day1Test]/[method:requirement_downfloor()]
replaced int return with 0 for com/roxoft/aoc/y2015/Day1::lambda$finalLocation$1 → KILLED

2.2
Location : finalLocation
Killed by : com.roxoft.aoc.y2015.Day1Test.[engine:junit-jupiter]/[class:com.roxoft.aoc.y2015.Day1Test]/[method:requirement_downfloor()]
replaced int return with 0 for com/roxoft/aoc/y2015/Day1::finalLocation → KILLED

39

1.1
Location : firstBasementVisit
Killed by : com.roxoft.aoc.y2015.Day1Test.[engine:junit-jupiter]/[class:com.roxoft.aoc.y2015.Day1Test]/[method:example_B2()]
negated conditional → KILLED

2.2
Location : firstBasementVisit
Killed by : com.roxoft.aoc.y2015.Day1Test.[engine:junit-jupiter]/[class:com.roxoft.aoc.y2015.Day1Test]/[method:assumption_invalidResultForSolutionB()]
changed conditional boundary → KILLED

40

1.1
Location : firstBasementVisit
Killed by : com.roxoft.aoc.y2015.Day1Test.[engine:junit-jupiter]/[class:com.roxoft.aoc.y2015.Day1Test]/[method:example_B2()]
Replaced integer addition with subtraction → KILLED

41

1.1
Location : firstBasementVisit
Killed by : com.roxoft.aoc.y2015.Day1Test.[engine:junit-jupiter]/[class:com.roxoft.aoc.y2015.Day1Test]/[method:example_B2()]
negated conditional → KILLED

42

1.1
Location : firstBasementVisit
Killed by : com.roxoft.aoc.y2015.Day1Test.[engine:junit-jupiter]/[class:com.roxoft.aoc.y2015.Day1Test]/[method:example_B2()]
replaced int return with 0 for com/roxoft/aoc/y2015/Day1::firstBasementVisit → KILLED

2.2
Location : firstBasementVisit
Killed by : com.roxoft.aoc.y2015.Day1Test.[engine:junit-jupiter]/[class:com.roxoft.aoc.y2015.Day1Test]/[method:example_B2()]
Replaced integer addition with subtraction → KILLED

Active mutators

Tests examined


Report generated by PIT 1.14.4