1
|
|
package com.adventofcode.day09 |
2
|
|
|
3
|
|
import java.util.* |
4
|
|
|
5
|
|
typealias Code = Long |
6
|
|
|
7
|
|
class XmasCipherDecoder(private val preambleAndCodes: Collection<Code>, private val preambleSize: Int) { |
8
|
|
|
9
|
|
private val initialPreamble = preambleAndCodes.toMutableList().subList(0, preambleSize) |
10
|
|
private val codes = preambleAndCodes.toList().subList(preambleSize, preambleAndCodes.size) |
11
|
|
|
12
|
1
1. getPreamble : replaced return value with Collections.emptyList for com/adventofcode/day09/XmasCipherDecoder::getPreamble → KILLED
|
var preamble = initialPreamble |
13
|
|
|
14
|
|
constructor(preamble: Collection<Code>, codes: Collection<Code> = mutableListOf()) : |
15
|
|
this(preamble + codes, preamble.size) |
16
|
|
|
17
|
|
|
18
|
|
constructor(preambleAsInts: List<Int>) : this(preambleAsInts.map { it.toLong() }.toList()) |
19
|
|
|
20
|
|
companion object { |
21
|
|
|
22
|
|
fun readFrom(input: String, preambleLength: Int): XmasCipherDecoder { |
23
|
2
1. readFrom : negated conditional → KILLED
2. readFrom : negated conditional → KILLED
|
val data = input.split('\n').filterNot { it.isEmpty() }.map { it.toLong() } |
24
|
|
val preamble = data.subList(0, preambleLength) |
25
|
|
val codes = data.subList(preambleLength, data.size) |
26
|
|
return XmasCipherDecoder(preamble, codes) |
27
|
|
} |
28
|
|
} |
29
|
|
|
30
|
|
fun validate(expected: Int): Boolean { |
31
|
2
1. validate : replaced boolean return with false for com/adventofcode/day09/XmasCipherDecoder::validate → KILLED
2. validate : replaced boolean return with true for com/adventofcode/day09/XmasCipherDecoder::validate → KILLED
|
return validate(expected.toLong()) |
32
|
|
} |
33
|
|
|
34
|
|
|
35
|
|
private fun validate(expected: Code): Boolean { |
36
|
|
return preamble |
37
|
3
1. validate : Replaced long multiplication with division → KILLED
2. validate : negated conditional → KILLED
3. validate : negated conditional → KILLED
|
.filterNot { it * 2 == expected } |
38
|
4
1. validate : Replaced long subtraction with addition → SURVIVED
2. validate : Replaced long subtraction with addition → KILLED
3. validate : Replaced bitwise OR with AND → KILLED
4. validate : negated conditional → KILLED
|
.any { (expected - it in preamble) or (it - expected in preamble) } |
39
|
|
} |
40
|
|
|
41
|
|
fun read(code: Code) { |
42
|
|
preamble = (preamble - listOf(preamble.first()) + listOf(code)).toMutableList() |
43
|
|
} |
44
|
|
|
45
|
|
fun findFirstInvalidCode(): Code? { |
46
|
|
preamble = initialPreamble |
47
|
|
codes.forEach { |
48
|
|
val validity = validate(it) |
49
|
2
1. findFirstInvalidCode : replaced Long return value with 0L for com/adventofcode/day09/XmasCipherDecoder::findFirstInvalidCode → KILLED
2. findFirstInvalidCode : negated conditional → KILLED
|
if (!validity) return it |
50
|
2
1. findFirstInvalidCode : negated conditional → KILLED
2. findFirstInvalidCode : removed call to com/adventofcode/day09/XmasCipherDecoder::read → KILLED
|
if (validity) read(it) |
51
|
|
} |
52
|
1
1. findFirstInvalidCode : replaced Long return value with 0L for com/adventofcode/day09/XmasCipherDecoder::findFirstInvalidCode → KILLED
|
return null |
53
|
|
} |
54
|
|
|
55
|
|
fun findEncryptionWeakness(): Long { |
56
|
|
val invalidCode = findFirstInvalidCode() |
57
|
|
|
58
|
|
val values = preambleAndCodes |
59
|
|
.map { generateAllSequencesForCode(it) } |
60
|
2
1. findEncryptionWeakness : negated conditional → KILLED
2. findEncryptionWeakness : negated conditional → KILLED
|
.first { it.containsKey(invalidCode) }[invalidCode] |
61
|
|
|
62
|
|
return values!!.first!! + values.second!!.toLong() |
63
|
|
} |
64
|
|
|
65
|
|
private fun generateAllSequencesForCode(departureCode: Code): Map<Long, Pair<Code?, Code?>> { |
66
|
|
val maxsize = preambleAndCodes.size |
67
|
|
val fromIndex = preambleAndCodes.indexOf(departureCode) |
68
|
|
return (preambleAndCodes as ArrayList).subList(fromIndex, maxsize) |
69
|
1
1. generateAllSequencesForCode : Replaced integer subtraction with addition → KILLED
|
.mapIndexed { index, _ -> preambleAndCodes.subList(fromIndex, maxsize - index) } |
70
|
3
1. generateAllSequencesForCode : changed conditional boundary → SURVIVED
2. generateAllSequencesForCode : negated conditional → KILLED
3. generateAllSequencesForCode : negated conditional → KILLED
|
.filter { it.size > 1 } |
71
|
|
.map { it.sum() to Pair(it.min(), it.max()) } |
72
|
1
1. generateAllSequencesForCode : replaced return value with null for com/adventofcode/day09/XmasCipherDecoder::generateAllSequencesForCode → KILLED
|
.toMap() |
73
|
|
} |
74
|
|
|
75
|
|
|
76
|
|
} |
| | Mutations |
12 |
|
1.1 Location : getPreamble Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldProcessInputContainingPreamble()] replaced return value with Collections.emptyList for com/adventofcode/day09/XmasCipherDecoder::getPreamble → KILLED
|
23 |
|
1.1 Location : readFrom Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] negated conditional → KILLED 2.2 Location : readFrom Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] negated conditional → KILLED
|
31 |
|
1.1 Location : validate Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldValidateNumberWhenFindingTwoDistinctValuesInto25PreviousNumbers()] replaced boolean return with false for com/adventofcode/day09/XmasCipherDecoder::validate → KILLED 2.2 Location : validate Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldValidateNumberWhenFindingTwoDistinctValuesInto25PreviousNumbers()] replaced boolean return with true for com/adventofcode/day09/XmasCipherDecoder::validate → KILLED
|
37 |
|
1.1 Location : validate Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldValidateNumberWhenFindingTwoDistinctValuesInto25PreviousNumbers()] Replaced long multiplication with division → KILLED 2.2 Location : validate Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] negated conditional → KILLED 3.3 Location : validate Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] negated conditional → KILLED
|
38 |
|
1.1 Location : validate Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] Replaced long subtraction with addition → KILLED 2.2 Location : validate Killed by : none Replaced long subtraction with addition → SURVIVED 3.3 Location : validate Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] Replaced bitwise OR with AND → KILLED 4.4 Location : validate Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] negated conditional → KILLED
|
49 |
|
1.1 Location : findFirstInvalidCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] replaced Long return value with 0L for com/adventofcode/day09/XmasCipherDecoder::findFirstInvalidCode → KILLED 2.2 Location : findFirstInvalidCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] negated conditional → KILLED
|
50 |
|
1.1 Location : findFirstInvalidCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindFirstInvalidCodeFromInput()] negated conditional → KILLED 2.2 Location : findFirstInvalidCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindFirstInvalidCodeFromInput()] removed call to com/adventofcode/day09/XmasCipherDecoder::read → KILLED
|
52 |
|
1.1 Location : findFirstInvalidCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] replaced Long return value with 0L for com/adventofcode/day09/XmasCipherDecoder::findFirstInvalidCode → KILLED
|
60 |
|
1.1 Location : findEncryptionWeakness Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindTheEncryptionWeakness()] negated conditional → KILLED 2.2 Location : findEncryptionWeakness Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindTheEncryptionWeakness()] negated conditional → KILLED
|
69 |
|
1.1 Location : generateAllSequencesForCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindTheEncryptionWeakness()] Replaced integer subtraction with addition → KILLED
|
70 |
|
1.1 Location : generateAllSequencesForCode Killed by : none changed conditional boundary → SURVIVED 2.2 Location : generateAllSequencesForCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindTheEncryptionWeakness()] negated conditional → KILLED 3.3 Location : generateAllSequencesForCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindTheEncryptionWeakness()] negated conditional → KILLED
|
72 |
|
1.1 Location : generateAllSequencesForCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindTheEncryptionWeakness()] replaced return value with null for com/adventofcode/day09/XmasCipherDecoder::generateAllSequencesForCode → KILLED
|
81 |
|
1.1 Location : validate Killed by : none negated conditional → SURVIVED 2.2 Location : validate Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] negated conditional → KILLED
|
83 |
|
1.1 Location : validate Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldHandleNonIntegerCodes()] replaced boolean return with true for com/adventofcode/day09/XmasCipherDecoder::validate → KILLED
|
95 |
|
1.1 Location : generateAllSequencesForCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindTheEncryptionWeakness()] changed conditional boundary → KILLED 2.2 Location : generateAllSequencesForCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindTheEncryptionWeakness()] Changed increment from 1 to -1 → KILLED 3.3 Location : generateAllSequencesForCode Killed by : com.adventofcode.day09.XmasCipherDecoderTest.[engine:junit-jupiter]/[class:com.adventofcode.day09.XmasCipherDecoderTest]/[method:shouldFindTheEncryptionWeakness()] negated conditional → KILLED 4.4 Location : generateAllSequencesForCode Killed by : none removed call to kotlin/collections/CollectionsKt::throwIndexOverflow → NO_COVERAGE
|