Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync tests for practice exercise luhn
Browse files Browse the repository at this point in the history
sanderploegsma committed Nov 21, 2023
1 parent e4177aa commit c14afa7
Showing 3 changed files with 47 additions and 6 deletions.
25 changes: 22 additions & 3 deletions exercises/practice/luhn/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

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

[7e7c9fc1-d994-457c-811e-d390d52fba5e]
description = "invalid long number with a remainder divisible by 5"

[ad2a0c5f-84ed-4e5b-95da-6011d6f4f0aa]
description = "valid number with an even number of digits"

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

[b9887ee8-8337-46c5-bc45-3bcab51bc36f]
description = "very long input is valid"

[8a7c0e24-85ea-4154-9cf1-c2db90eabc08]
description = "valid luhn with an odd number of digits and non zero first digit"

[39a06a5a-5bad-4e0f-b215-b042d46209b1]
description = "using ascii value for non-doubled non-digit isn't allowed"

[f94cf191-a62f-4868-bc72-7253114aa157]
description = "using ascii value for doubled non-digit isn't allowed"

[8b72ad26-c8be-49a2-b99c-bcc3bf631b33]
description = "non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed"
1 change: 0 additions & 1 deletion exercises/practice/luhn/.meta/version

This file was deleted.

27 changes: 25 additions & 2 deletions exercises/practice/luhn/src/test/java/LuhnValidatorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import org.junit.Ignore;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

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

@Ignore("Remove to run test")
@Test
public void testInvalidLongNumberWithARemainderDivisibleBy5() {
assertThat(luhnValidator.isValid("1 2345 6789 1234 5678 9013")).isFalse();
}

@Ignore("Remove to run test")
@Test
public void testValidNumberWithAnEvenNumberOfDigits() {
@@ -107,6 +113,17 @@ public void testDigitNineConvertedToOutputNine() {
assertThat(luhnValidator.isValid("091")).isTrue();
}

@Ignore("Remove to run test")
@Test
public void testVeryLongInputIsValid() {
assertThat(luhnValidator.isValid("9999999999 9999999999 9999999999 9999999999")).isTrue();
}

@Ignore("Remove to run test")
@Test
public void testValidLuhnWithOddNumberOfDigitsAndNonZeroFirstDigit() {
assertThat(luhnValidator.isValid("109")).isTrue();
}

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

@Ignore("Remove to run test")
@Test
public void testNonNumericNonSpaceCharInMiddleWithSumDivisibleBy10IsNotAllowed() {
assertThat(luhnValidator.isValid("59%59")).isFalse();
}

/* The following test diverges from the canonical test data. This is because the corresponding canonical test does
* not account for Java specific functions (such as Character.getNumericValue()), which can be part of incorrect yet
* passing implementations. For more detail, check out issue #972 here:
@@ -128,6 +151,6 @@ public void testUsingASCIIValueForDoubledNonDigitNotAllowed() {
@Ignore("Remove to run test")
@Test
public void testStringContainingSymbolsInvalidJavaTrackSpecific() {
assertThat(luhnValidator.isValid("85&"));
assertThat(luhnValidator.isValid("85&")).isFalse();
}
}

0 comments on commit c14afa7

Please sign in to comment.