Console.kt

1
package com.adventofcode.day08
2
3
4
typealias  Instruction = String
5
typealias  Program = List<Instruction>
6
7
class Console(vararg inputInstructions: Instruction) {
8
9
    constructor() : this("")
10
    constructor(inputInstructions: List<Instruction>) : this(*inputInstructions.toTypedArray())
11
12 1 1. getAccumulator : replaced int return with 0 for com/adventofcode/day08/Console::getAccumulator → KILLED
    var accumulator: Int = 0
13 1 1. getInstructions : replaced return value with Collections.emptyList for com/adventofcode/day08/Console::getInstructions → KILLED
    var instructions: MutableList<Instruction> = inputInstructions.toMutableList()
14 1 1. getVisitedInstructions : replaced return value with Collections.emptyList for com/adventofcode/day08/Console::getVisitedInstructions → KILLED
    var visitedInstructions: List<Int> = mutableListOf()
15
16
    fun boot(): Console {
17
        var index = 0
18 3 1. boot : negated conditional → KILLED
2. boot : negated conditional → KILLED
3. boot : negated conditional → KILLED
        if (instructions.isNullOrEmpty()) return this
19 2 1. boot : changed conditional boundary → SURVIVED
2. boot : negated conditional → KILLED
        while (index < instructions.size) {
20
            val currentInstruction = instructions.getOrNull(index)
21
22 2 1. boot : negated conditional → KILLED
2. boot : negated conditional → KILLED
            if (currentInstruction == null || visitedInstructions.contains(index)) {
23
                break
24
            }
25
26
            visitedInstructions += listOf(index)
27
28
            val value = currentInstruction.split(" ").last().toIntOrNull()
29
30 1 1. boot : negated conditional → KILLED
            if (currentInstruction.startsWith("acc")) {
31 2 1. boot : Replaced integer addition with subtraction → KILLED
2. boot : negated conditional → KILLED
                if (value != null) accumulator += value
32 1 1. boot : Replaced integer addition with subtraction → KILLED
                index += 1
33
            }
34 1 1. boot : negated conditional → KILLED
            if (currentInstruction.startsWith("nop")) {
35 1 1. boot : Replaced integer addition with subtraction → KILLED
                index += 1
36
            }
37 1 1. boot : negated conditional → KILLED
            if (currentInstruction.startsWith("jmp")) {
38 2 1. boot : Replaced integer addition with subtraction → KILLED
2. boot : negated conditional → KILLED
                if (value != null) index += value; continue
39
            }
40
        }
41
        return this
42
    }
43
44
45
    fun smartBoot(): Console {
46
        boot()
47 1 1. smartBoot : negated conditional → KILLED
        if (lastInstructionHasBeenVisited()) return this
48
49
        val mutatedInstructions = generatedMutatedInstructions()
50
51
        mutatedInstructions.forEach {
52 1 1. smartBoot : negated conditional → KILLED
            if (!lastInstructionHasBeenVisited()) {
53
                instructions = it as MutableList<Instruction>
54
                accumulator = 0
55
                visitedInstructions = mutableListOf()
56
                boot()
57
            }
58
        }
59
60
        return this
61
    }
62
63
    private fun generatedMutatedInstructions(): List<Program> {
64
        return instructions
65
                .mapIndexed { index, instruction -> instruction to index }
66 1 1. generatedMutatedInstructions : negated conditional → KILLED
                .filter { it.first.startsWith("jmp") }
67
                .map {
68 1 1. generatedMutatedInstructions : Replaced integer addition with subtraction → KILLED
                    instructions.subList(0, it.second) + listOf(it.first.replace("jmp", "nop")) + instructions.subList(it.second + 1, instructions.size)
69
                }
70 1 1. generatedMutatedInstructions : replaced return value with Collections.emptyList for com/adventofcode/day08/Console::generatedMutatedInstructions → KILLED
                .toList()
71
72
    }
73
74 3 1. lastInstructionHasBeenVisited : replaced boolean return with false for com/adventofcode/day08/Console::lastInstructionHasBeenVisited → KILLED
2. lastInstructionHasBeenVisited : replaced boolean return with true for com/adventofcode/day08/Console::lastInstructionHasBeenVisited → KILLED
3. lastInstructionHasBeenVisited : Replaced integer subtraction with addition → KILLED
    fun lastInstructionHasBeenVisited(): Boolean = visitedInstructions.contains(instructions.size - 1)
75
76
77
}

Mutations

12

1.1
Location : getAccumulator
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldIncreasesWhenInstructionIsACCWithPositiveValue()]
replaced int return with 0 for com/adventofcode/day08/Console::getAccumulator → KILLED

13

1.1
Location : getInstructions
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldMarkInstructionAsVisited()]
replaced return value with Collections.emptyList for com/adventofcode/day08/Console::getInstructions → KILLED

14

1.1
Location : getVisitedInstructions
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldMarkInstructionAsVisited()]
replaced return value with Collections.emptyList for com/adventofcode/day08/Console::getVisitedInstructions → KILLED

18

1.1
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldIncreasesWhenInstructionIsACCWithPositiveValue()]
negated conditional → KILLED

2.2
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldIncreasesWhenInstructionIsACCWithPositiveValue()]
negated conditional → KILLED

3.3
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldIncreasesWhenInstructionIsACCWithPositiveValue()]
negated conditional → KILLED

19

1.1
Location : boot
Killed by : none
changed conditional boundary → SURVIVED

2.2
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldIncreasesWhenInstructionIsACCWithPositiveValue()]
negated conditional → KILLED

22

1.1
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldIncreasesWhenInstructionIsACCWithPositiveValue()]
negated conditional → KILLED

2.2
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldIncreasesWhenInstructionIsACCWithPositiveValue()]
negated conditional → KILLED

30

1.1
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldIncreasesWhenInstructionIsACCWithPositiveValue()]
negated conditional → KILLED

31

1.1
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldIncreasesWhenInstructionIsACCWithPositiveValue()]
Replaced integer addition with subtraction → KILLED

2.2
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldIncreasesWhenInstructionIsACCWithPositiveValue()]
negated conditional → KILLED

32

1.1
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldStopWhenHittingAnInfiniteLoop()]
Replaced integer addition with subtraction → KILLED

34

1.1
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldStopWhenHittingAnInfiniteLoop()]
negated conditional → KILLED

35

1.1
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldStopWhenHittingAnInfiniteLoop()]
Replaced integer addition with subtraction → KILLED

37

1.1
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldStopWhenHittingAnInfiniteLoop()]
negated conditional → KILLED

38

1.1
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldStopWhenHittingAnInfiniteLoop()]
Replaced integer addition with subtraction → KILLED

2.2
Location : boot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldStopWhenHittingAnInfiniteLoop()]
negated conditional → KILLED

47

1.1
Location : smartBoot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldFoundMutatedInstructionsThatComputeNormallyChangingJmpToNop()]
negated conditional → KILLED

52

1.1
Location : smartBoot
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldFoundMutatedInstructionsThatComputeNormallyChangingJmpToNop()]
negated conditional → KILLED

66

1.1
Location : generatedMutatedInstructions
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldFoundMutatedInstructionsThatComputeNormallyChangingJmpToNop()]
negated conditional → KILLED

68

1.1
Location : generatedMutatedInstructions
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldFoundMutatedInstructionsThatComputeNormallyChangingJmpToNop()]
Replaced integer addition with subtraction → KILLED

70

1.1
Location : generatedMutatedInstructions
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldFoundMutatedInstructionsThatComputeNormallyChangingJmpToNop()]
replaced return value with Collections.emptyList for com/adventofcode/day08/Console::generatedMutatedInstructions → KILLED

74

1.1
Location : lastInstructionHasBeenVisited
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldMarkInstructionAsVisited()]
replaced boolean return with false for com/adventofcode/day08/Console::lastInstructionHasBeenVisited → KILLED

2.2
Location : lastInstructionHasBeenVisited
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldFoundMutatedInstructionsThatComputeNormallyChangingJmpToNop()]
replaced boolean return with true for com/adventofcode/day08/Console::lastInstructionHasBeenVisited → KILLED

3.3
Location : lastInstructionHasBeenVisited
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldMarkInstructionAsVisited()]
Replaced integer subtraction with addition → KILLED

83

1.1
Location : generatedMutatedInstructions
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldFoundMutatedInstructionsThatComputeNormallyChangingJmpToNop()]
changed conditional boundary → KILLED

2.2
Location : generatedMutatedInstructions
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldFoundMutatedInstructionsThatComputeNormallyChangingJmpToNop()]
Changed increment from 1 to -1 → KILLED

3.3
Location : generatedMutatedInstructions
Killed by : com.adventofcode.day08.ConsoleTest.[engine:junit-jupiter]/[class:com.adventofcode.day08.ConsoleTest]/[method:shouldFoundMutatedInstructionsThatComputeNormallyChangingJmpToNop()]
negated conditional → KILLED

4.4
Location : generatedMutatedInstructions
Killed by : none
removed call to kotlin/collections/CollectionsKt::throwIndexOverflow → NO_COVERAGE

93

1.1
Location : <init>
Killed by : none
negated conditional → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.6.1