Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
29f2d68
Added DisplayName to DnDCharacterTest
manjarekarsudip Nov 17, 2025
cf13ec2
Added DisplayName to SimpleLinkedListTest
manjarekarsudip Nov 17, 2025
1ec5bfa
Added DisplayName to RobotTest
manjarekarsudip Nov 17, 2025
abeab3c
Added DisplayName to PokerTest
manjarekarsudip Nov 17, 2025
240a2d2
Added DisplayName to PiecingItTogetherTest
manjarekarsudip Nov 17, 2025
b78d58c
Added DisplayName to PhoneNumberTest
manjarekarsudip Nov 17, 2025
8947790
Added DisplayName to NaturalNumberTest
manjarekarsudip Nov 17, 2025
d742b56
Added DisplayName to PascalsTriangleGeneratorTest
manjarekarsudip Nov 17, 2025
0911db6
Added DisplayName to ParallelLetterFrequencyTest
manjarekarsudip Nov 17, 2025
3263b85
Added DisplayName to MazeGeneratorTest
manjarekarsudip Nov 17, 2025
b00d461
Added DisplayName to ErrorHandlingTest
manjarekarsudip Nov 17, 2025
4b9f11a
Added DisplayName to BracketCheckerTest
manjarekarsudip Nov 17, 2025
caa9560
Added DisplayName to HangmanTest
manjarekarsudip Nov 17, 2025
d96f651
Added DisplayName to MarkdownTest
manjarekarsudip Nov 17, 2025
991ec6c
Changes done as per canonical-data.json
manjarekarsudip Nov 18, 2025
7b1165b
Merge branch 'main' into issue-2971-display-names
manjarekarsudip Nov 18, 2025
b382016
Merge branch 'main' into issue-2971-display-names
manjarekarsudip Nov 19, 2025
a51cf75
Add suggestion to ErrorHandlingTest
manjarekarsudip Nov 22, 2025
5f39489
Add suggestion to HangmanTest
manjarekarsudip Nov 22, 2025
44618f2
Add suggestion to MazeGeneratorTest
manjarekarsudip Nov 22, 2025
37981c3
Add suggestion to ParallelLetterFrequencyTest
manjarekarsudip Nov 22, 2025
6db2931
Add suggestion to RobotTest
manjarekarsudip Nov 22, 2025
9805fec
Add suggestion to SimpleLinkedListTest
manjarekarsudip Nov 22, 2025
311de45
Merge remote-tracking branch 'origin/issue-2971-display-names' into i…
manjarekarsudip Nov 22, 2025
40302ea
Changing orders of tests to keep similar tests together
jagdish-15 Nov 23, 2025
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 java.util.List;
Expand All @@ -10,150 +11,175 @@ public class DnDCharacterTest {
private DnDCharacter dndCharacter = new DnDCharacter();

@Test
@DisplayName("ability modifier for score 3 is -4")
public void testAbilityModifierForScore3IsNegative4() {
assertThat(dndCharacter.modifier(3)).isEqualTo(-4);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 4 is -3")
public void testAbilityModifierForScore4IsNegative3() {
assertThat(dndCharacter.modifier(4)).isEqualTo(-3);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 5 is -3")
public void testAbilityModifierForScore5IsNegative3() {
assertThat(dndCharacter.modifier(5)).isEqualTo(-3);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 6 is -2")
public void testAbilityModifierForScore6IsNegative2() {
assertThat(dndCharacter.modifier(6)).isEqualTo(-2);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 7 is -2")
public void testAbilityModifierForScore7IsNegative2() {
assertThat(dndCharacter.modifier(7)).isEqualTo(-2);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 8 is -1")
public void testAbilityModifierForScore8IsNegative1() {
assertThat(dndCharacter.modifier(8)).isEqualTo(-1);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 9 is -1")
public void testAbilityModifierForScore9IsNegative1() {
assertThat(dndCharacter.modifier(9)).isEqualTo(-1);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 10 is 0")
public void testAbilityModifierForScore10Is0() {
assertThat(dndCharacter.modifier(10)).isEqualTo(0);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 11 is 0")
public void testAbilityModifierForScore11Is0() {
assertThat(dndCharacter.modifier(11)).isEqualTo(0);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 12 is +1")
public void testAbilityModifierForScore12Is1() {
assertThat(dndCharacter.modifier(12)).isEqualTo(1);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 13 is +1")
public void testAbilityModifierForScore13Is1() {
assertThat(dndCharacter.modifier(13)).isEqualTo(1);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 14 is +2")
public void testAbilityModifierForScore14Is2() {
assertThat(dndCharacter.modifier(14)).isEqualTo(2);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 15 is +2")
public void testAbilityModifierForScore15Is2() {
assertThat(dndCharacter.modifier(15)).isEqualTo(2);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 16 is +3")
public void testAbilityModifierForScore16Is3() {
assertThat(dndCharacter.modifier(16)).isEqualTo(3);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 17 is +3")
public void testAbilityModifierForScore17Is3() {
assertThat(dndCharacter.modifier(17)).isEqualTo(3);
}

@Disabled("Remove to run test")
@Test
@DisplayName("ability modifier for score 18 is +4")
public void testAbilityModifierForScore18Is4() {
assertThat(dndCharacter.modifier(18)).isEqualTo(4);
}

@Disabled("Remove to run test")
@Test
@DisplayName("Rolling uses 4 dice")
public void test4DiceWereUsedForRollingScores() {
assertThat(dndCharacter.rollDice().size()).isEqualTo(4);
}

@Disabled("Remove to run test")
@Test
@DisplayName("Dice values are between 1 and 6 inclusive")
public void testDiceValuesBetween1And6() {
assertThat(dndCharacter.rollDice()).allMatch(d -> d >= 1 && d <= 6);
}

@Disabled("Remove to run test")
@Test
@DisplayName("Ability uses 3 largest numbers from scores in descending order")
public void testAbilityCalculationsUses3LargestNumbersFromScoresInDescendingOrder() {
assertThat(dndCharacter.ability(List.of(4, 3, 2, 1))).isEqualTo(9);
}

@Disabled("Remove to run test")
@Test
@DisplayName("Ability uses 3 largest numbers from scores in ascending order")
public void testAbilityCalculationsUses3LargestNumbersFromFromScoresInAscendingOrder() {
assertThat(dndCharacter.ability(List.of(1, 2, 3, 4))).isEqualTo(9);
}

@Disabled("Remove to run test")
@Test
@DisplayName("Ability uses 3 largest numbers from scores in random order")
public void testAbilityCalculationsUses3LargestNumbersFromScoresInRandomOrder() {
assertThat(dndCharacter.ability(List.of(2, 4, 3, 1))).isEqualTo(9);
}

@Disabled("Remove to run test")
@Test
@DisplayName("Ability with all lowest equal numbers yields 3")
public void testAbilityCalculationsWithLowestEqualNumbers() {
assertThat(dndCharacter.ability(List.of(1, 1, 1, 1))).isEqualTo(3);
}

@Disabled("Remove to run test")
@Test
@DisplayName("Ability with all highest equal numbers yields 18")
public void testAbilityCalculationsWithHighestEqualNumbers() {
assertThat(dndCharacter.ability(List.of(6, 6, 6, 6))).isEqualTo(18);
}

@Disabled("Remove to run test")
@Test
@DisplayName("Ability calculation with two lowest numbers")
public void testAbilityCalculationsWithTwoLowestNumbers() {
assertThat(dndCharacter.ability(List.of(3, 5, 3, 4))).isEqualTo(12);
}

@Disabled("Remove to run test")
@Test
@DisplayName("Ability calculation does not mutate input scores")
public void testAbilityCalculationDoesNotChangeInputScores() {
List<Integer> scores = List.of(1, 2, 3, 4);
dndCharacter.ability(scores);
Expand All @@ -164,6 +190,7 @@ public void testAbilityCalculationDoesNotChangeInputScores() {

@Disabled("Remove to run test")
@Test
@DisplayName("random character is valid")
public void testRandomCharacterIsValid() {
for (int i = 0; i < 1000; i++) {
DnDCharacter character = new DnDCharacter();
Expand All @@ -179,6 +206,7 @@ public void testRandomCharacterIsValid() {

@Disabled("Remove to run test")
@Test
@DisplayName("each ability is only calculated once")
public void testEachAbilityIsOnlyCalculatedOnce() {
assertThat(dndCharacter.getStrength()).isEqualTo(dndCharacter.getStrength());
assertThat(dndCharacter.getDexterity()).isEqualTo(dndCharacter.getDexterity());
Expand All @@ -190,6 +218,7 @@ public void testEachAbilityIsOnlyCalculatedOnce() {

@Disabled("Remove to run test")
@Test
@DisplayName("Each randomly created character should be unique in attributes")
public void testUniqueCharacterIsCreated() {
DnDCharacter uniqueDnDCharacter = new DnDCharacter();
for (int i = 0; i < 1000; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.Optional;

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

public class ErrorHandlingTest {

private ErrorHandling errorHandling = new ErrorHandling();

@Test
@DisplayName("Throws IllegalArgumentException")
public void testThrowIllegalArgumentException() {
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> errorHandling.handleErrorByThrowingIllegalArgumentException());
}

@Disabled("Remove to run test")
@Test
@DisplayName("Throws IllegalArgumentException with provided detail message")
public void testThrowIllegalArgumentExceptionWithDetailMessage() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> errorHandling.handleErrorByThrowingIllegalArgumentExceptionWithDetailMessage(
Expand All @@ -27,6 +30,7 @@ public void testThrowIllegalArgumentExceptionWithDetailMessage() {

@Disabled("Remove to run test")
@Test
@DisplayName("Throws any checked exception")
public void testThrowAnyCheckedException() {
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> errorHandling.handleErrorByThrowingAnyCheckedException())
Expand All @@ -35,6 +39,7 @@ public void testThrowAnyCheckedException() {

@Disabled("Remove to run test")
@Test
@DisplayName("Throws any checked exception with provided detail message")
public void testThrowAnyCheckedExceptionWithDetailMessage() {
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> errorHandling.handleErrorByThrowingAnyCheckedExceptionWithDetailMessage(
Expand All @@ -45,13 +50,15 @@ public void testThrowAnyCheckedExceptionWithDetailMessage() {

@Disabled("Remove to run test")
@Test
@DisplayName("Throws any unchecked exception")
public void testThrowAnyUncheckedException() {
assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> errorHandling.handleErrorByThrowingAnyUncheckedException());
}

@Disabled("Remove to run test")
@Test
@DisplayName("Throws any unchecked exception with provided detail message")
public void testThrowAnyUncheckedExceptionWithDetailMessage() {
assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> errorHandling.handleErrorByThrowingAnyUncheckedExceptionWithDetailMessage(
Expand All @@ -61,13 +68,15 @@ public void testThrowAnyUncheckedExceptionWithDetailMessage() {

@Disabled("Remove to run test")
@Test
@DisplayName("Throws custom checked exception")
public void testThrowCustomCheckedException() {
assertThatExceptionOfType(CustomCheckedException.class)
.isThrownBy(() -> errorHandling.handleErrorByThrowingCustomCheckedException());
}

@Disabled("Remove to run test")
@Test
@DisplayName("Throws custom checked exception with provided detail message")
public void testThrowCustomCheckedExceptionWithDetailMessage() {
assertThatExceptionOfType(CustomCheckedException.class)
.isThrownBy(() -> errorHandling.handleErrorByThrowingCustomCheckedExceptionWithDetailMessage(
Expand All @@ -77,13 +86,15 @@ public void testThrowCustomCheckedExceptionWithDetailMessage() {

@Disabled("Remove to run test")
@Test
@DisplayName("Throws custom unchecked exception")
public void testThrowCustomUncheckedException() {
assertThatExceptionOfType(CustomUncheckedException.class)
.isThrownBy(() -> errorHandling.handleErrorByThrowingCustomUncheckedException());
}

@Disabled("Remove to run test")
@Test
@DisplayName("Throws custom unchecked exception with provided detail message")
public void testThrowCustomUncheckedExceptionWithDetailMessage() {
assertThatExceptionOfType(CustomUncheckedException.class)
.isThrownBy(() -> errorHandling.handleErrorByThrowingCustomUncheckedExceptionWithDetailMessage(
Expand All @@ -93,6 +104,7 @@ public void testThrowCustomUncheckedExceptionWithDetailMessage() {

@Disabled("Remove to run test")
@Test
@DisplayName("Handles error by throwing Optional instance")
public void testReturnOptionalInstance() {
Optional<Integer> successfulResult = errorHandling.handleErrorByReturningOptionalInstance("1");
assertThat(successfulResult).isPresent().hasValue(1);
Expand Down
11 changes: 11 additions & 0 deletions exercises/practice/hangman/src/test/java/HangmanTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.disposables.Disposable;

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 java.util.ArrayList;
Expand All @@ -22,6 +24,7 @@ public void init() {
}

@Test
@DisplayName("Initial game state is set correctly")
public void initialization() {
Observable<Output> result = hangman.play(
Observable.fromArray("secret"),
Expand All @@ -39,6 +42,7 @@ public void initialization() {

@Disabled("Remove to run test")
@Test
@DisplayName("First correct guess updates discovered and guess lists")
public void firstGuess() {
Observable<Output> result = hangman.play(
Observable.fromArray("secret"),
Expand All @@ -54,6 +58,7 @@ public void firstGuess() {

@Disabled("Remove to run test")
@Test
@DisplayName("First incorrect guess registers a miss and adds a part")
public void firstMiss() {
Observable<Output> result = hangman.play(
Observable.fromArray("secret"),
Expand All @@ -69,6 +74,7 @@ public void firstMiss() {

@Disabled("Remove to run test")
@Test
@DisplayName("Game in progress accumulates guesses, misses and parts correctly")
public void gameInProgress() {
Observable<Output> result = hangman.play(
Observable.fromArray("secret"),
Expand All @@ -84,6 +90,7 @@ public void gameInProgress() {

@Disabled("Remove to run test")
@Test
@DisplayName("Winning the game results in WIN status")
public void wonGame() {
Observable<Output> result = hangman.play(
Observable.fromArray("secret"),
Expand All @@ -97,6 +104,7 @@ public void wonGame() {

@Disabled("Remove to run test")
@Test
@DisplayName("Losing the game results in LOSS status")
public void lostGame() {
Observable<Output> result = hangman.play(
Observable.fromArray("secret"),
Expand All @@ -118,6 +126,7 @@ public void lostGame() {

@Disabled("Remove to run test")
@Test
@DisplayName("Handles consecutive games correctly with ordered emissions")
public void consecutiveGames() {
// This test setup is more complex because we have to order the emission of values in the
// different observers.
Expand Down Expand Up @@ -189,6 +198,7 @@ Observable createLetterObservable(ObservableEmitter[] emitters, Runnable emit) {

@Disabled("Remove to run test")
@Test
@DisplayName("Cannot play the same guess twice")
public void cannotPlayAGuessTwice() {
Observable<Output> result = hangman.play(
Observable.fromArray("secret"),
Expand All @@ -201,6 +211,7 @@ public void cannotPlayAGuessTwice() {

@Disabled("Remove to run test")
@Test
@DisplayName("Cannot play the same miss twice")
public void cannotPlayAMissTwice() {
Observable<Output> result = hangman.play(
Observable.fromArray("secret"),
Expand Down
Loading