Rule.kt

1
package com.adventofcode.day07
2
3
typealias Bags = Map<Bag, Int>
4
typealias Bag = String
5
6 1 1. getBagName : replaced return value with "" for com/adventofcode/day07/Rule::getBagName → KILLED
class Rule(val bagName: Bag) {
7
8
    var innerBags: Bags = mutableMapOf()
9
10
    constructor(bagName: Bag, vararg innerBagsAsString: Bag) : this(bagName) {
11
        innerBags = innerBagsAsString
12
                .map { it.split(" ") }
13 3 1. <init> : negated conditional → KILLED
2. <init> : negated conditional → KILLED
3. <init> : negated conditional → KILLED
                .filterNot { it.isNullOrEmpty() }
14 2 1. <init> : negated conditional → KILLED
2. <init> : negated conditional → KILLED
                .filterNot { it.size == 1 }
15
                .map { it.subList(1, it.size).joinToString(" ", "", "") to it[0].toInt() }
16
                .toMap()
17
    }
18
19
    override fun toString(): Bag {
20
        if (innerBags.isNullOrEmpty()) return Bag.format("[%s] contains no other bag", bagName)
21
        return Bag.format("[%s] contains %s", bagName, innerBags)
22
    }
23
24
    companion object {
25
        fun from(input: Bag): Rule {
26
            val values = input
27
                    .split(" bags contain | bag(s){0,1}, | bag(s){0,1}\\.".toRegex())
28
            if(values.isNotEmpty() && values[1] != "no other") return  Rule(values[0], *values.subList(1, values.size).toTypedArray())
29
            return Rule(values[0])
30
        }
31
    }
32
33
    override fun equals(other: Any?): Boolean {
34 2 1. equals : replaced boolean return with true for com/adventofcode/day07/Rule::equals → KILLED
2. equals : negated conditional → KILLED
        if (other !is Rule) return false
35
        return bagName == other.bagName && innerBags == other.innerBags
36
    }
37
38
}

Mutations

6

1.1
Location : getBagName
Killed by : com.adventofcode.day07.Day07Test.[engine:junit-jupiter]/[class:com.adventofcode.day07.Day07Test]/[method:shouldRespondTo4WithThisInput()]
replaced return value with "" for com/adventofcode/day07/Rule::getBagName → KILLED

13

1.1
Location : <init>
Killed by : com.adventofcode.day07.RuleTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.RuleTest]/[method:shouldCompareTwoRules()]
negated conditional → KILLED

2.2
Location : <init>
Killed by : com.adventofcode.day07.RuleTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.RuleTest]/[method:shouldCompareTwoRules()]
negated conditional → KILLED

3.3
Location : <init>
Killed by : com.adventofcode.day07.RuleTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.RuleTest]/[method:shouldCompareTwoRules()]
negated conditional → KILLED

14

1.1
Location : <init>
Killed by : com.adventofcode.day07.RuleTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.RuleTest]/[method:shouldCompareTwoRules()]
negated conditional → KILLED

2.2
Location : <init>
Killed by : com.adventofcode.day07.RuleTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.RuleTest]/[method:shouldCompareTwoRules()]
negated conditional → KILLED

34

1.1
Location : equals
Killed by : com.adventofcode.day07.RuleTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.RuleTest]/[method:shouldCompareTwoRules()]
replaced boolean return with true for com/adventofcode/day07/Rule::equals → KILLED

2.2
Location : equals
Killed by : com.adventofcode.day07.RuleTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.RuleTest]/[method:shouldCompareTwoRules()]
negated conditional → KILLED

40

1.1
Location : from
Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldBeAbleToReadMultipleRuleFromInput()]
negated conditional → KILLED

41

1.1
Location : from
Killed by : com.adventofcode.day07.BagFinderTest.[engine:junit-jupiter]/[class:com.adventofcode.day07.BagFinderTest]/[method:shouldBeAbleToReadMultipleRuleFromInput()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.6.1