Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static java.util.Map.entry;
Expand All @@ -8,6 +9,7 @@
public class AlphameticsTest {

@Test
@DisplayName("puzzle with three letters")
public void testThreeLetters() throws UnsolvablePuzzleException {
assertThat(new Alphametics("I + BB == ILL").solve())
.containsOnly(
Expand All @@ -18,6 +20,7 @@ public void testThreeLetters() throws UnsolvablePuzzleException {

@Disabled("Remove to run test")
@Test
@DisplayName("solution must have unique value for each letter")
public void testUniqueValue() {
Alphametics alphametics = new Alphametics("A == B");

Expand All @@ -27,6 +30,7 @@ public void testUniqueValue() {

@Disabled("Remove to run test")
@Test
@DisplayName("leading zero solution is invalid")
public void testLeadingZero() {
Alphametics alphametics = new Alphametics("ACA + DD == BD");

Expand All @@ -36,6 +40,7 @@ public void testLeadingZero() {

@Disabled("Remove to run test")
@Test
@DisplayName("puzzle with two digits final carry")
public void testTwoDigitsFinalCarry() throws UnsolvablePuzzleException {
assertThat(new Alphametics("A + A + A + A + A + A + A + A + A + A + A + B == BCC").solve())
.containsOnly(
Expand All @@ -46,6 +51,7 @@ public void testTwoDigitsFinalCarry() throws UnsolvablePuzzleException {

@Disabled("Remove to run test")
@Test
@DisplayName("puzzle with four letters")
public void testFourLetters() throws UnsolvablePuzzleException {
assertThat(new Alphametics("AS + A == MOM").solve())
.containsOnly(
Expand All @@ -57,6 +63,7 @@ public void testFourLetters() throws UnsolvablePuzzleException {

@Disabled("Remove to run test")
@Test
@DisplayName("puzzle with six letters")
public void testSixLetters() throws UnsolvablePuzzleException {
assertThat(new Alphametics("NO + NO + TOO == LATE").solve())
.containsOnly(
Expand All @@ -70,6 +77,7 @@ public void testSixLetters() throws UnsolvablePuzzleException {

@Disabled("Remove to run test")
@Test
@DisplayName("puzzle with seven letters")
public void testSevenLetters() throws UnsolvablePuzzleException {
assertThat(new Alphametics("HE + SEES + THE == LIGHT").solve())
.containsOnly(
Expand All @@ -84,6 +92,7 @@ public void testSevenLetters() throws UnsolvablePuzzleException {

@Disabled("Remove to run test")
@Test
@DisplayName("puzzle with eight letters")
public void testEightLetters() throws UnsolvablePuzzleException {
assertThat(new Alphametics("SEND + MORE == MONEY").solve())
.containsOnly(
Expand All @@ -99,6 +108,7 @@ public void testEightLetters() throws UnsolvablePuzzleException {

@Disabled("Remove to run test")
@Test
@DisplayName("puzzle with ten letters")
public void testTenLetters() throws UnsolvablePuzzleException {
assertThat(new Alphametics("AND + A + STRONG + OFFENSE + AS + A + GOOD == DEFENSE").solve())
.containsOnly(
Expand All @@ -116,7 +126,8 @@ public void testTenLetters() throws UnsolvablePuzzleException {

@Disabled("Remove to run test")
@Test
public void testTenLetters41Addends() throws UnsolvablePuzzleException {
@DisplayName("puzzle with ten letters and 199 addends")
public void testTenLetters199Addends() throws UnsolvablePuzzleException {
assertThat(new Alphametics("THIS + A + FIRE + THEREFORE + FOR + ALL + HISTORIES + I + TELL + A + " +
"TALE + THAT + FALSIFIES + ITS + TITLE + TIS + A + LIE + THE + TALE + OF + THE + LAST + FIRE + " +
"HORSES + LATE + AFTER + THE + FIRST + FATHERS + FORESEE + THE + HORRORS + THE + LAST + FREE + " +
Expand Down
19 changes: 19 additions & 0 deletions exercises/practice/anagram/src/test/java/AnagramTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
Expand All @@ -9,6 +10,7 @@
public class AnagramTest {

@Test
@DisplayName("no matches")
public void testNoMatches() {
Anagram detector = new Anagram("diaper");

Expand All @@ -20,6 +22,7 @@ public void testNoMatches() {

@Disabled("Remove to run test")
@Test
@DisplayName("detects two anagrams")
public void testDetectsTwoAnagrams() {
Anagram detector = new Anagram("solemn");

Expand All @@ -29,6 +32,7 @@ public void testDetectsTwoAnagrams() {

@Disabled("Remove to run test")
@Test
@DisplayName("does not detect anagram subsets")
public void testEliminateAnagramSubsets() {
Anagram detector = new Anagram("good");

Expand All @@ -37,6 +41,7 @@ public void testEliminateAnagramSubsets() {

@Disabled("Remove to run test")
@Test
@DisplayName("detects anagram")
public void testDetectLongerAnagram() {
Anagram detector = new Anagram("listen");

Expand All @@ -48,6 +53,7 @@ public void testDetectLongerAnagram() {

@Disabled("Remove to run test")
@Test
@DisplayName("detects three anagrams")
public void testDetectMultipleAnagramsForLongerWord() {
Anagram detector = new Anagram("allergy");
assertThat(
Expand All @@ -64,6 +70,7 @@ public void testDetectMultipleAnagramsForLongerWord() {

@Disabled("Remove to run test")
@Test
@DisplayName("detects multiple anagrams with different case")
public void testDetectsMultipleAnagramsWithDifferentCase() {
Anagram detector = new Anagram("nose");

Expand All @@ -73,6 +80,7 @@ public void testDetectsMultipleAnagramsWithDifferentCase() {

@Disabled("Remove to run test")
@Test
@DisplayName("does not detect non-anagrams with identical checksum")
public void testEliminateAnagramsWithSameChecksum() {
Anagram detector = new Anagram("mass");

Expand All @@ -82,6 +90,7 @@ public void testEliminateAnagramsWithSameChecksum() {

@Disabled("Remove to run test")
@Test
@DisplayName("detects anagrams case-insensitively")
public void testCaseInsensitiveWhenBothAnagramAndSubjectStartWithUpperCaseLetter() {
Anagram detector = new Anagram("Orchestra");

Expand All @@ -93,6 +102,7 @@ public void testCaseInsensitiveWhenBothAnagramAndSubjectStartWithUpperCaseLetter

@Disabled("Remove to run test")
@Test
@DisplayName("detects anagrams using case-insensitive subject")
public void testCaseInsensitiveWhenSubjectStartsWithUpperCaseLetter() {
Anagram detector = new Anagram("Orchestra");

Expand All @@ -104,6 +114,7 @@ public void testCaseInsensitiveWhenSubjectStartsWithUpperCaseLetter() {

@Disabled("Remove to run test")
@Test
@DisplayName("detects anagrams using case-insensitive possible matches")
public void testCaseInsensitiveWhenAnagramStartsWithUpperCaseLetter() {
Anagram detector = new Anagram("orchestra");

Expand All @@ -115,6 +126,7 @@ public void testCaseInsensitiveWhenAnagramStartsWithUpperCaseLetter() {

@Disabled("Remove to run test")
@Test
@DisplayName("does not detect an anagram if the original word is repeated")
public void testIdenticalWordRepeatedIsNotAnagram() {
Anagram detector = new Anagram("go");

Expand All @@ -124,6 +136,7 @@ public void testIdenticalWordRepeatedIsNotAnagram() {

@Disabled("Remove to run test")
@Test
@DisplayName("anagrams must use all letters exactly once")
public void testAnagramMustUseAllLettersExactlyOnce() {
Anagram detector = new Anagram("tapper");

Expand All @@ -133,6 +146,7 @@ public void testAnagramMustUseAllLettersExactlyOnce() {

@Disabled("Remove to run test")
@Test
@DisplayName("words are not anagrams of themselves")
public void testWordsAreNotAnagramsOfThemselvesCaseInsensitive() {
Anagram detector = new Anagram("BANANA");

Expand All @@ -142,6 +156,7 @@ public void testWordsAreNotAnagramsOfThemselvesCaseInsensitive() {

@Disabled("Remove to run test")
@Test
@DisplayName("words are not anagrams of themselves even if letter case is partially different")
public void testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsPartiallyDifferent() {
Anagram detector = new Anagram("BANANA");

Expand All @@ -151,6 +166,7 @@ public void testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsPartiallyDiffer

@Disabled("Remove to run test")
@Test
@DisplayName("words are not anagrams of themselves even if letter case is completely different")
public void testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsCompletelyDifferent() {
Anagram detector = new Anagram("BANANA");

Expand All @@ -160,6 +176,7 @@ public void testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsCompletelyDiffe

@Disabled("Remove to run test")
@Test
@DisplayName("words other than themselves can be anagrams")
public void testWordsOtherThanThemselvesCanBeAnagrams() {
Anagram detector = new Anagram("LISTEN");

Expand All @@ -169,6 +186,7 @@ public void testWordsOtherThanThemselvesCanBeAnagrams() {

@Disabled("Remove to run test")
@Test
@DisplayName("handles case of greek letters")
public void testHandlesCaseOfGreekLetters() {
Anagram detector = new Anagram("ΑΒΓ");

Expand All @@ -178,6 +196,7 @@ public void testHandlesCaseOfGreekLetters() {

@Disabled("Remove to run test")
@Test
@DisplayName("different characters may have the same bytes")
public void testDifferentCharactersWithSameBytes() {
Anagram detector = new Anagram("a⬂");

Expand Down
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,62 +15,71 @@ public void setup() {
}

@Test
@DisplayName("Zero is an Armstrong number")
public void zeroIsArmstrongNumber() {
assertThat(armstrongNumbers.isArmstrongNumber(0))
.isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("Single-digit numbers are Armstrong numbers")
public void singleDigitsAreArmstrongNumbers() {
assertThat(armstrongNumbers.isArmstrongNumber(5))
.isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("There are no two-digit Armstrong numbers")
public void noTwoDigitArmstrongNumbers() {
assertThat(armstrongNumbers.isArmstrongNumber(10))
.isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("Three-digit number that is an Armstrong number")
public void threeDigitNumberIsArmstrongNumber() {
assertThat(armstrongNumbers.isArmstrongNumber(153))
.isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("Three-digit number that is not an Armstrong number")
public void threeDigitNumberIsNotArmstrongNumber() {
assertThat(armstrongNumbers.isArmstrongNumber(100))
.isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("Four-digit number that is an Armstrong number")
public void fourDigitNumberIsArmstrongNumber() {
assertThat(armstrongNumbers.isArmstrongNumber(9474))
.isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("Four-digit number that is not an Armstrong number")
public void fourDigitNumberIsNotArmstrongNumber() {
assertThat(armstrongNumbers.isArmstrongNumber(9475))
.isFalse();
}

@Disabled("Remove to run test")
@Test
@DisplayName("Seven-digit number that is an Armstrong number")
public void sevenDigitNumberIsArmstrongNumber() {
assertThat(armstrongNumbers.isArmstrongNumber(9926315))
.isTrue();
}

@Disabled("Remove to run test")
@Test
@DisplayName("Seven-digit number that is not an Armstrong number")
public void sevenDigitNumberIsNotArmstrongNumber() {
assertThat(armstrongNumbers.isArmstrongNumber(9926314))
.isFalse();
Expand Down
Loading