Skip to content

Commit 426e0f3

Browse files
Fix formatting issue
1 parent 73c938d commit 426e0f3

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/main/java/com/thealgorithms/recursion/TowerOfHanoi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ private TowerOfHanoi() {
3535
* @return list of moves as strings
3636
*/
3737
public static List<String> solveTowerOfHanoi(int n, char source, char destination, char auxiliary) {
38+
List<String> moves = new ArrayList<>();
3839
if (n < 0) {
3940
throw new IllegalArgumentException("Number of disks cannot be negative");
4041
}
41-
List<String> moves = new ArrayList<>();
4242
moveDisks(n, source, destination, auxiliary, moves);
4343
return moves;
4444
}
@@ -61,4 +61,4 @@ private static void moveDisks(int n, char source, char destination, char auxilia
6161
moves.add("Move disk " + n + " from rod " + source + " to rod " + destination);
6262
moveDisks(n - 1, auxiliary, destination, source, moves);
6363
}
64-
}
64+
}

src/test/java/com/thealgorithms/recursion/TowerOfHanoiTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ public void testBaseCase() {
2020
public void testSmallRecursion() {
2121
List<String> result = TowerOfHanoi.solveTowerOfHanoi(2, 'A', 'C', 'B');
2222
assertEquals(3, result.size());
23-
List<String> expected = Arrays.asList(
24-
"Move disk 1 from rod A to rod B",
25-
"Move disk 2 from rod A to rod C",
26-
"Move disk 1 from rod B to rod C"
27-
);
23+
List<String> expected = Arrays.asList("Move disk 1 from rod A to rod B", "Move disk 2 from rod A to rod C", "Move disk 1 from rod B to rod C");
2824
assertEquals(expected, result, "Sequence of moves for 2 disks is incorrect");
2925
}
3026

@@ -38,6 +34,6 @@ public void testStandardCase() {
3834

3935
@Test
4036
public void testNegativeInput() {
41-
assertThrows(IllegalArgumentException.class, () -> TowerOfHanoi.solveTowerOfHanoi(-5, 'A', 'C', 'B'), "Should throw exception for negative disks");
37+
assertThrows(IllegalArgumentException.class, () -> { TowerOfHanoi.solveTowerOfHanoi(-5, 'A', 'C', 'B'); }, "Should throw exception for negative disks");
4238
}
4339
}

0 commit comments

Comments
 (0)