Sha256: f478179540cbb264223971cece68a5c02c267ad7e17ac53f26d5f345075d358a

Contents?: true

Size: 1.68 KB

Versions: 89

Compression:

Stored size: 1.68 KB

Contents

import org.junit.Test
import kotlin.test.assertEquals

class LuhnTest {

    @Test
    fun checkDigitIsRightMostDigit() {
        val expectedOutput = 7

        assertEquals(expectedOutput, Luhn(34567).checkDigit)
    }

    @Test
    fun addendsDoublesEveryOtherNumberFromRight() {
        val expectedOutput = listOf(1, 4, 1, 4, 1)

        assertEquals(expectedOutput, Luhn(12121).addends)
    }

    @Test
    fun addendsSubtracts9WhenDoubledNumberIsMoreThan9() {
        val expectedOutput = listOf(7, 6, 6, 1)

        assertEquals(expectedOutput, Luhn(8631).addends)
    }

    @Test
    fun checkSumAddsAddendsTogether1() {
        val expectedOutput = 22

        assertEquals(expectedOutput, Luhn(4913).checksum)
    }

    @Test
    fun checkSumAddsAddendsTogether2() {
        val expectedOutput = 21

        assertEquals(expectedOutput, Luhn(201773).checksum)
    }

    @Test
    fun numberIsValidWhenChecksumMod10IsZero1() {
        val expectedOutput = false

        assertEquals(expectedOutput, Luhn(738).isValid)
    }

    @Test
    fun numberIsValidWhenChecksumMod10IsZero2() {
        val expectedOutput = true

        assertEquals(expectedOutput, Luhn(8739567).isValid)
    }

    @Test
    fun luhnCanCreateSimpleNumbersWithValidCheckDigit() {
        val expectedOutput = 1230L

        assertEquals(expectedOutput, Luhn(123).create)
    }

    @Test
    fun luhnCanCreateLargeNumbersWithValidCheckDigit() {
        val expectedOutput = 8739567L

        assertEquals(expectedOutput, Luhn(873956).create)
    }

    @Test
    fun luhnCanCreateHugeNumbersWithValidCheckDigit() {
        val expectedOutput = 8372637564L

        assertEquals(expectedOutput, Luhn(837263756).create)
    }
}

Version data entries

89 entries across 89 versions & 1 rubygems

Version Path
trackler-2.0.6.33 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.32 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.31 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.30 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.29 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.28 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.27 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.26 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.25 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.24 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.23 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.22 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.21 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.20 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.19 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.18 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.17 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.16 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.15 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt
trackler-2.0.6.14 tracks/kotlin/exercises/luhn/src/test/kotlin/LuhnTest.kt