TobogganCorporatePolicy.kt

1
package com.adventofcode.day02
2
3
class TobogganCorporatePolicy(positions: String, private val letter: String) : Policy {
4
5
    private val expectedPositions= positions.split("-").map { it.toInt() }.toList()
6
    private val firstPosition = expectedPositions.first()
7
    private val secondPosition = expectedPositions.last()
8
9
    companion object {
10
        fun fromInput(policyAsString: String): TobogganCorporatePolicy {
11
            val split = policyAsString.split(" ")
12
            return TobogganCorporatePolicy(split.first(), split.last())
13
        }
14
    }
15
16
    override fun toString(): String {
17 1 1. toString : replaced return value with "" for com/adventofcode/day02/TobogganCorporatePolicy::toString → NO_COVERAGE
        return "Toboggan Corporate policy: -letter '$letter' must be at '$firstPosition' and not at '$secondPosition'-"
18
    }
19
20
    override fun checkValidity(password: String): Boolean {
21 1 1. checkValidity : negated conditional → KILLED
        return letterIsAtFirstPositionAndNotAtSecondPosition(password)
22 2 1. checkValidity : replaced boolean return with true for com/adventofcode/day02/TobogganCorporatePolicy::checkValidity → KILLED
2. checkValidity : negated conditional → KILLED
                || letterISAtSecondPositionAndNotAtInFirstPosition(password)
23
            }
24
25
    private fun letterIsAtFirstPositionAndNotAtSecondPosition(password: String) =
26
            (password.getOrNull(firstPosition - 1).toString() == letter
27
                    && password.getOrNull(secondPosition - 1).toString() != letter)
28
29
    private fun letterISAtSecondPositionAndNotAtInFirstPosition(password: String) =
30
            (password.getOrNull(firstPosition - 1).toString() != letter
31
                    && password.getOrNull(secondPosition - 1).toString() == letter)
32
33
}

Mutations

17

1.1
Location : toString
Killed by : none
replaced return value with "" for com/adventofcode/day02/TobogganCorporatePolicy::toString → NO_COVERAGE

21

1.1
Location : checkValidity
Killed by : com.adventofcode.day02.PasswordsWithTobogganCorporatePolicyTest.[engine:junit-jupiter]/[class:com.adventofcode.day02.PasswordsWithTobogganCorporatePolicyTest]/[method:passwordIsInvalidWhenBothPositionsContainTheKeyLetter()]
negated conditional → KILLED

22

1.1
Location : checkValidity
Killed by : com.adventofcode.day02.PasswordsWithTobogganCorporatePolicyTest.[engine:junit-jupiter]/[class:com.adventofcode.day02.PasswordsWithTobogganCorporatePolicyTest]/[method:passwordIsInvalidWhenBothPositionsContainTheKeyLetter()]
replaced boolean return with true for com/adventofcode/day02/TobogganCorporatePolicy::checkValidity → KILLED

2.2
Location : checkValidity
Killed by : com.adventofcode.day02.PasswordsWithTobogganCorporatePolicyTest.[engine:junit-jupiter]/[class:com.adventofcode.day02.PasswordsWithTobogganCorporatePolicyTest]/[method:passwordIsInvalidWhenBothPositionsContainTheKeyLetter()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.6.1