File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
main/kotlin/de/ronny_h/aoc/extensions
test/kotlin/de/ronny_h/aoc/extensions Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 11package de.ronny_h.aoc.extensions
22
3+ import kotlin.math.abs
4+
35/* *
46 * Counts the number of digits of the given Long number.
57 */
@@ -14,3 +16,8 @@ fun Long.digitCount(): Int {
1416 }
1517 return count
1618}
19+
20+ /* *
21+ * Returns the ones digit (the rightmost digit) of the given Long number.
22+ */
23+ fun Long.onesDigit (): Int = abs(this % 10 ).toInt()
Original file line number Diff line number Diff line change @@ -13,4 +13,20 @@ class DigitsTest : StringSpec({
1313 number.digitCount() shouldBe digits
1414 }
1515 }
16+
17+ " The ones digit is returned" {
18+ forAll(
19+ row(0, 0),
20+ row(123L, 3),
21+ row(15887950, 0),
22+ row(16495136, 6),
23+ row(527345, 5),
24+ row(-123L, 3),
25+ row(-15887950, 0),
26+ row(-16495136, 6),
27+ row(-527345, 5),
28+ ) { number, ones ->
29+ number.onesDigit() shouldBe ones
30+ }
31+ }
1632})
You can’t perform that action at this time.
0 commit comments