Skip to content

Commit b18dd27

Browse files
Sync tests for practice exercise luhn (exercism#2579)
1 parent 66d26e2 commit b18dd27

3 files changed

Lines changed: 47 additions & 6 deletions

File tree

exercises/practice/luhn/.meta/tests.toml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[792a7082-feb7-48c7-b88b-bbfec160865e]
613
description = "single digit strings can not be valid"
@@ -26,6 +33,9 @@ description = "invalid credit card"
2633
[20e67fad-2121-43ed-99a8-14b5b856adb9]
2734
description = "invalid long number with an even remainder"
2835

36+
[7e7c9fc1-d994-457c-811e-d390d52fba5e]
37+
description = "invalid long number with a remainder divisible by 5"
38+
2939
[ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa]
3040
description = "valid number with an even number of digits"
3141

@@ -50,8 +60,17 @@ description = "more than a single zero is valid"
5060
[ab56fa80-5de8-4735-8a4a-14dae588663e]
5161
description = "input digit 9 is correctly converted to output digit 9"
5262

63+
[b9887ee8-8337-46c5-bc45-3bcab51bc36f]
64+
description = "very long input is valid"
65+
66+
[8a7c0e24-85ea-4154-9cf1-c2db90eabc08]
67+
description = "valid luhn with an odd number of digits and non zero first digit"
68+
5369
[39a06a5a-5bad-4e0f-b215-b042d46209b1]
5470
description = "using ascii value for non-doubled non-digit isn't allowed"
5571

5672
[f94cf191-a62f-4868-bc72-7253114aa157]
5773
description = "using ascii value for doubled non-digit isn't allowed"
74+
75+
[8b72ad26-c8be-49a2-b99c-bcc3bf631b33]
76+
description = "non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed"

exercises/practice/luhn/.meta/version

Lines changed: 0 additions & 1 deletion
This file was deleted.

exercises/practice/luhn/src/test/java/LuhnValidatorTest.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import org.junit.Ignore;
21
import org.junit.Before;
2+
import org.junit.Ignore;
33
import org.junit.Test;
44

55
import static org.assertj.core.api.Assertions.assertThat;
@@ -59,6 +59,12 @@ public void testInvalidLongNumberWithAnEvenRemainder() {
5959
assertThat(luhnValidator.isValid("1 2345 6789 1234 5678 9012")).isFalse();
6060
}
6161

62+
@Ignore("Remove to run test")
63+
@Test
64+
public void testInvalidLongNumberWithARemainderDivisibleBy5() {
65+
assertThat(luhnValidator.isValid("1 2345 6789 1234 5678 9013")).isFalse();
66+
}
67+
6268
@Ignore("Remove to run test")
6369
@Test
6470
public void testValidNumberWithAnEvenNumberOfDigits() {
@@ -107,6 +113,17 @@ public void testDigitNineConvertedToOutputNine() {
107113
assertThat(luhnValidator.isValid("091")).isTrue();
108114
}
109115

116+
@Ignore("Remove to run test")
117+
@Test
118+
public void testVeryLongInputIsValid() {
119+
assertThat(luhnValidator.isValid("9999999999 9999999999 9999999999 9999999999")).isTrue();
120+
}
121+
122+
@Ignore("Remove to run test")
123+
@Test
124+
public void testValidLuhnWithOddNumberOfDigitsAndNonZeroFirstDigit() {
125+
assertThat(luhnValidator.isValid("109")).isTrue();
126+
}
110127

111128
@Ignore("Remove to run test")
112129
@Test
@@ -120,6 +137,12 @@ public void testUsingASCIIValueForDoubledNonDigitNotAllowed() {
120137
assertThat(luhnValidator.isValid(":9")).isFalse();
121138
}
122139

140+
@Ignore("Remove to run test")
141+
@Test
142+
public void testNonNumericNonSpaceCharInMiddleWithSumDivisibleBy10IsNotAllowed() {
143+
assertThat(luhnValidator.isValid("59%59")).isFalse();
144+
}
145+
123146
/* The following test diverges from the canonical test data. This is because the corresponding canonical test does
124147
* not account for Java specific functions (such as Character.getNumericValue()), which can be part of incorrect yet
125148
* passing implementations. For more detail, check out issue #972 here:
@@ -128,6 +151,6 @@ public void testUsingASCIIValueForDoubledNonDigitNotAllowed() {
128151
@Ignore("Remove to run test")
129152
@Test
130153
public void testStringContainingSymbolsInvalidJavaTrackSpecific() {
131-
assertThat(luhnValidator.isValid("85&"));
154+
assertThat(luhnValidator.isValid("85&")).isFalse();
132155
}
133156
}

0 commit comments

Comments
 (0)