1
|
|
package com.adventofcode.day07 |
2
|
|
|
3
|
1
1. getRules : replaced return value with Collections.emptyList for com/adventofcode/day07/BagFinder::getRules → KILLED
|
class BagFinder(val rules: List<Rule>) { |
4
|
|
|
5
|
|
constructor(input: String) : this(input.split("\n").map(Rule.Companion::from)) |
6
|
|
constructor() : this(emptyList()) |
7
|
|
|
8
|
|
fun findNumberOfBagColorsThatCanContains(bagToContained: String): Int { |
9
|
1
1. findNumberOfBagColorsThatCanContains : replaced int return with 0 for com/adventofcode/day07/BagFinder::findNumberOfBagColorsThatCanContains → KILLED
|
return findBagColorsThatCanContains(bagToContained).count() |
10
|
|
} |
11
|
|
|
12
|
|
|
13
|
|
fun findBagColorsThatCanContains(bagNameToFind: String): List<Rule> { |
14
|
1
1. findBagColorsThatCanContains : replaced return value with Collections.emptyList for com/adventofcode/day07/BagFinder::findBagColorsThatCanContains → KILLED
|
return findAllBagColorsThatCanContainsDirectlyOrNot(bagNameToFind, rules) |
15
|
|
|
16
|
|
} |
17
|
|
|
18
|
|
private fun findAllBagColorsThatCanContainsDirectlyOrNot(bagNameToFind: String, rules: List<Rule>): List<Rule> { |
19
|
|
val directRules = findBagColorsThatCanContainsDirectly(bagNameToFind, rules).distinct() |
20
|
|
val subRules = directRules.map { it.bagName }.map { findAllBagColorsThatCanContainsDirectlyOrNot(it, rules) }.flatten().distinct() |
21
|
2
1. findAllBagColorsThatCanContainsDirectlyOrNot : replaced return value with Collections.emptyList for com/adventofcode/day07/BagFinder::findAllBagColorsThatCanContainsDirectlyOrNot → KILLED
2. findAllBagColorsThatCanContainsDirectlyOrNot : negated conditional → KILLED
|
if (subRules.isEmpty()) return directRules |
22
|
1
1. findAllBagColorsThatCanContainsDirectlyOrNot : replaced return value with Collections.emptyList for com/adventofcode/day07/BagFinder::findAllBagColorsThatCanContainsDirectlyOrNot → KILLED
|
return directRules.union(subRules).distinct() |
23
|
|
} |
24
|
|
|
25
|
|
fun findBagColorsThatCanContainsDirectly(bagNameToFind: String, rules: List<Rule>): List<Rule> { |
26
|
1
1. findBagColorsThatCanContainsDirectly : negated conditional → KILLED
|
return rules.filter { it.innerBags.containsKey(bagNameToFind) } |
27
|
|
} |
28
|
|
|
29
|
|
override fun toString(): String { |
30
|
4
1. toString : replaced return value with "" for com/adventofcode/day07/BagFinder::toString → KILLED
2. toString : negated conditional → KILLED
3. toString : negated conditional → KILLED
4. invoke : replaced return value with "" for com/adventofcode/day07/BagFinder$toString$1::invoke → KILLED
|
return "Bags Reads: ${rules.joinToString { "$it" }.ifEmpty { "None" }}" |
31
|
|
} |
32
|
|
|
33
|
|
fun findAllNestedBagsThatAreIn(bagThatContains: String): Int { |
34
|
|
val rule = rules.firstOrNull { it.bagName == bagThatContains } ?: return 0 |
35
|
|
val innerBags = rule.innerBags |
36
|
3
1. findAllNestedBagsThatAreIn : negated conditional → KILLED
2. findAllNestedBagsThatAreIn : negated conditional → KILLED
3. findAllNestedBagsThatAreIn : negated conditional → KILLED
|
if (innerBags.isNullOrEmpty()) return 0 |
37
|
|
val rawNumberOfBags = innerBags.map { it.value }.sum() |
38
|
1
1. findAllNestedBagsThatAreIn : Replaced integer multiplication with division → KILLED
|
val nestedBags = innerBags.map { it to it.key }.map { findAllNestedBagsThatAreIn(it.second) * it.first.value }.sum() |
39
|
2
1. findAllNestedBagsThatAreIn : Replaced integer addition with subtraction → KILLED
2. findAllNestedBagsThatAreIn : replaced int return with 0 for com/adventofcode/day07/BagFinder::findAllNestedBagsThatAreIn → KILLED
|
return rawNumberOfBags + nestedBags |
40
|
|
} |
41
|
|
} |
| | Mutations |
3 |
|
1.1 Location : getRules Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldBeAbleToReadMultipleRuleFromInput()] replaced return value with Collections.emptyList for com/adventofcode/day07/BagFinder::getRules → KILLED
|
9 |
|
1.1 Location : findNumberOfBagColorsThatCanContains Killed by : com.adventofcode.day07.Day07Test.[engine:junit-jupiter]/[class:com.adventofcode.day07.Day07Test]/[method:shouldRespondTo4WithThisInput()] replaced int return with 0 for com/adventofcode/day07/BagFinder::findNumberOfBagColorsThatCanContains → KILLED
|
14 |
|
1.1 Location : findBagColorsThatCanContains Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindAllColorBagThatCanIndirectlyFindTheGivenColorBag()] replaced return value with Collections.emptyList for com/adventofcode/day07/BagFinder::findBagColorsThatCanContains → KILLED
|
21 |
|
1.1 Location : findAllBagColorsThatCanContainsDirectlyOrNot Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindAllColorBagThatCanIndirectlyFindTheGivenColorBag()] replaced return value with Collections.emptyList for com/adventofcode/day07/BagFinder::findAllBagColorsThatCanContainsDirectlyOrNot → KILLED 2.2 Location : findAllBagColorsThatCanContainsDirectlyOrNot Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindAllColorBagThatCanIndirectlyFindTheGivenColorBag()] negated conditional → KILLED
|
22 |
|
1.1 Location : findAllBagColorsThatCanContainsDirectlyOrNot Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindAllColorBagThatCanIndirectlyFindTheGivenColorBag()] replaced return value with Collections.emptyList for com/adventofcode/day07/BagFinder::findAllBagColorsThatCanContainsDirectlyOrNot → KILLED
|
26 |
|
1.1 Location : findBagColorsThatCanContainsDirectly Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindBagsThatDirectlyContainsTheGivenColorBag()] negated conditional → KILLED
|
30 |
|
1.1 Location : toString Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldDisplayNicely()] replaced return value with "" for com/adventofcode/day07/BagFinder::toString → KILLED 2.2 Location : toString Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldDisplayNicely()] negated conditional → KILLED 3.3 Location : toString Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldDisplayNicely()] negated conditional → KILLED 4.4 Location : invoke Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldDisplayNicely()] replaced return value with "" for com/adventofcode/day07/BagFinder$toString$1::invoke → KILLED
|
36 |
|
1.1 Location : findAllNestedBagsThatAreIn Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindHowManyBagAreRequiredInAGivenBagColor()] negated conditional → KILLED 2.2 Location : findAllNestedBagsThatAreIn Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindHowManyBagAreRequiredInAGivenBagColor()] negated conditional → KILLED 3.3 Location : findAllNestedBagsThatAreIn Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindHowManyBagAreRequiredInAGivenBagColor()] negated conditional → KILLED
|
38 |
|
1.1 Location : findAllNestedBagsThatAreIn Killed by : com.adventofcode.day07.Day07Test.[engine:junit-jupiter]/[class:com.adventofcode.day07.Day07Test]/[method:shouldFindAllInnerBagsAsExpected()] Replaced integer multiplication with division → KILLED
|
39 |
|
1.1 Location : findAllNestedBagsThatAreIn Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindHowManyBagAreRequiredInAGivenBagColor()] Replaced integer addition with subtraction → KILLED 2.2 Location : findAllNestedBagsThatAreIn Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindHowManyBagAreRequiredInAGivenBagColor()] replaced int return with 0 for com/adventofcode/day07/BagFinder::findAllNestedBagsThatAreIn → KILLED
|
53 |
|
1.1 Location : findBagColorsThatCanContainsDirectly Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindBagsThatDirectlyContainsTheGivenColorBag()] replaced return value with Collections.emptyList for com/adventofcode/day07/BagFinder::findBagColorsThatCanContainsDirectly → KILLED
|
55 |
|
1.1 Location : findAllNestedBagsThatAreIn Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldFindHowManyBagAreRequiredInAGivenBagColor()] negated conditional → KILLED
|