Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion exercises/practice/luhn/src/test/java/LuhnValidatorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -13,138 +14,160 @@ public void setUp() {
}

@Test
@DisplayName("single digit strings can not be valid")
public void testSingleDigitStringInvalid() {
assertThat(luhnValidator.isValid("1")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("a single zero is invalid")
public void testSingleZeroIsInvalid() {
assertThat(luhnValidator.isValid("0")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("a simple valid SIN that remains valid if reversed")
public void testSimpleValidSINReversedRemainsValid() {
assertThat(luhnValidator.isValid("059")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("a simple valid SIN that becomes invalid if reversed")
public void testSimpleValidSINReversedBecomesInvalid() {
assertThat(luhnValidator.isValid("59")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("a valid Canadian SIN")
public void testValidCanadianSINValid() {
assertThat(luhnValidator.isValid("055 444 285")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("invalid Canadian SIN")
public void testInvalidCanadianSINInvalid() {
assertThat(luhnValidator.isValid("055 444 286")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("invalid credit card")
public void testInvalidCreditCardInvalid() {
assertThat(luhnValidator.isValid("8273 1232 7352 0569")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("invalid long number with an even remainder")
public void testInvalidLongNumberWithAnEvenRemainder() {
assertThat(luhnValidator.isValid("1 2345 6789 1234 5678 9012")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("invalid long number with a remainder divisible by 5")
public void testInvalidLongNumberWithARemainderDivisibleBy5() {
assertThat(luhnValidator.isValid("1 2345 6789 1234 5678 9013")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("valid number with an even number of digits")
public void testValidNumberWithAnEvenNumberOfDigits() {
assertThat(luhnValidator.isValid("095 245 88")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("valid number with an odd number of spaces")
public void testValidNumberWithAnOddNumberOfSpaces() {
assertThat(luhnValidator.isValid("234 567 891 234")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("valid strings with a non-digit added at the end become invalid")
public void testValidStringsWithANonDigitAtEndInvalid() {
assertThat(luhnValidator.isValid("059a")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("valid strings with punctuation included become invalid")
public void testStringContainingPunctuationInvalid() {
assertThat(luhnValidator.isValid("055-444-285")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("valid strings with symbols included become invalid")
public void testStringContainingSymbolsInvalid() {
assertThat(luhnValidator.isValid("055# 444$ 285")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("single zero with space is invalid")
public void testSingleSpaceWithZeroInvalid() {
assertThat(luhnValidator.isValid(" 0")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("more than a single zero is valid")
public void testMoreThanSingleZeroValid() {
assertThat(luhnValidator.isValid("0000 0")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("input digit 9 is correctly converted to output digit 9")
public void testDigitNineConvertedToOutputNine() {
assertThat(luhnValidator.isValid("091")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("very long input is valid")
public void testVeryLongInputIsValid() {
assertThat(luhnValidator.isValid("9999999999 9999999999 9999999999 9999999999")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("valid luhn with an odd number of digits and non zero first digit")
public void testValidLuhnWithOddNumberOfDigitsAndNonZeroFirstDigit() {
assertThat(luhnValidator.isValid("109")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("using ascii value for non-doubled non-digit isn't allowed")
public void testUsingASCIIValueForNonDoubledNonDigitNotAllowed() {
assertThat(luhnValidator.isValid("055b 444 285")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("using ascii value for doubled non-digit isn't allowed")
public void testUsingASCIIValueForDoubledNonDigitNotAllowed() {
assertThat(luhnValidator.isValid(":9")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed")
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
* 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:
* (https://github.com/exercism/java/issues/972).
*/
Comment on lines 169 to 173
Copy link
Member

@jagdish-15 jagdish-15 Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* 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
* 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:
* (https://github.com/exercism/java/issues/972).
*/
/* 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:
* (https://github.com/exercism/java/issues/972).
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, could you add this @DisplayName("string containing symbols is invalid (Java track specific)") tag to the last test (since it’s Java-specific, you wouldn’t have found one for it in the problem-specifications repo), and slightly adjust the method name to testStringContainingSymbolsIsInvalidJavaTrackSpecific()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I’ve reverted as requested. Please check and confirm. I must have added that * accidentally, sorry for the inconvenience.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add the last DisplayName tag for the Java-specific test? I've provided the information above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your guidance and for accepting my changes. This was my first contribution to an open-source project, and I really appreciate the support.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re very welcome! Thanks for making your first contribution here. It’s always great to see new contributors getting involved. Congrats on your first PR, and we hope to see more from you in the future!

Expand Down
9 changes: 9 additions & 0 deletions exercises/practice/matrix/src/test/java/MatrixTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class MatrixTest {

@Test
@DisplayName("extract row from one number matrix")
public void extractRowFromOneNumberMatrixTest() {
String matrixAsString = "1";
int rowIndex = 1;
Expand All @@ -18,6 +20,7 @@ public void extractRowFromOneNumberMatrixTest() {

@Disabled("Remove to run test")
@Test
@DisplayName("can extract row")
public void extractRowFromMatrixTest() {
String matrixAsString = "1 2\n3 4";
int rowIndex = 2;
Expand All @@ -30,6 +33,7 @@ public void extractRowFromMatrixTest() {

@Disabled("Remove to run test")
@Test
@DisplayName("extract row where numbers have different widths")
public void extractRowFromDiffWidthsMatrixTest() {
String matrixAsString = "1 2\n10 20";
int rowIndex = 2;
Expand All @@ -42,6 +46,7 @@ public void extractRowFromDiffWidthsMatrixTest() {

@Disabled("Remove to run test")
@Test
@DisplayName("can extract row from non-square matrix with no corresponding column")
public void extractRowFromNonSquareMatrixTest() {
String matrixAsString = "1 2 3\n4 5 6\n7 8 9\n8 7 6";
int rowIndex = 4;
Expand All @@ -54,6 +59,7 @@ public void extractRowFromNonSquareMatrixTest() {

@Disabled("Remove to run test")
@Test
@DisplayName("extract column from one number matrix")
public void extractColumnFromOneNumberMatrixTest() {
String matrixAsString = "1";
int columnIndex = 1;
Expand All @@ -66,6 +72,7 @@ public void extractColumnFromOneNumberMatrixTest() {

@Disabled("Remove to run test")
@Test
@DisplayName("can extract column")
public void extractColumnMatrixTest() {
String matrixAsString = "1 2 3\n4 5 6\n7 8 9";
int columnIndex = 3;
Expand All @@ -78,6 +85,7 @@ public void extractColumnMatrixTest() {

@Disabled("Remove to run test")
@Test
@DisplayName("can extract column from non-square matrix with no corresponding row")
public void extractColumnFromNonSquareMatrixTest() {
String matrixAsString = "1 2 3 4\n5 6 7 8\n9 8 7 6";
int columnIndex = 4;
Expand All @@ -90,6 +98,7 @@ public void extractColumnFromNonSquareMatrixTest() {

@Disabled("Remove to run test")
@Test
@DisplayName("extract column where numbers have different widths")
public void extractColumnFromDiffWidthsMatrixTest() {
String matrixAsString = "89 1903 3\n18 3 1\n9 4 800";
int columnIndex = 2;
Expand Down
11 changes: 11 additions & 0 deletions exercises/practice/pangram/src/test/java/PangramCheckerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -14,60 +15,70 @@ public void setup() {
}

@Test
@DisplayName("empty sentence")
public void emptySentenceIsNotPangram() {
assertThat(pangramChecker.isPangram("")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("perfect lower case")
public void perfectLowerCasePhraseIsPangram() {
assertThat(pangramChecker.isPangram("abcdefghijklmnopqrstuvwxyz")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("only lower case")
public void phraseWithOnlyLowerCaseIsPangram() {
assertThat(pangramChecker.isPangram("the quick brown fox jumps over the lazy dog")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("missing the letter 'x'")
public void phraseMissingCharacterXIsNotPangram() {
assertThat(pangramChecker.isPangram("a quick movement of the enemy will jeopardize five gunboats")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("missing the letter 'h'")
public void phraseMissingCharacterHIsNotPangram() {
assertThat(pangramChecker.isPangram("five boxing wizards jump quickly at it")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("with underscores")
public void phraseWithUnderscoresIsPangram() {
assertThat(pangramChecker.isPangram("the_quick_brown_fox_jumps_over_the_lazy_dog")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("with numbers")
public void phraseWithNumbersIsPangram() {
assertThat(pangramChecker.isPangram("the 1 quick brown fox jumps over the 2 lazy dogs")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("missing letters replaced by numbers")
public void phraseWithMissingLettersReplacedByNumbersIsNotPangram() {
assertThat(pangramChecker.isPangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog")).isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("mixed case and punctuation")
public void phraseWithMixedCaseAndPunctuationIsPangram() {
assertThat(pangramChecker.isPangram("\"Five quacking Zephyrs jolt my wax bed.\"")).isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("case insensitive")
public void caseInsensitivePhraseIsNotPangram() {
assertThat(pangramChecker.isPangram("abcdefghijklm ABCDEFGHIJKLM")).isFalse();
}
Expand Down