Skip to content

Commit 3dc5f8e

Browse files
Fixed some errors according to build format
1 parent 1488417 commit 3dc5f8e

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private TowerofHanoi() {
3838
*/
3939
public static List<String> solveTowerOfHanoi(int n, char source, char destination, char auxiliary) {
4040
List<String> moves = new ArrayList<>();
41-
if(n<0){
41+
if(n < 0) {
4242
throw new IllegalArgumentException("Number of disks cannot be negative");
4343
}
4444
moveDisks(n, source, destination, auxiliary, moves);
@@ -64,13 +64,14 @@ private static void moveDisks(int n, char source, char destination, char auxilia
6464
moveDisks(n - 1, auxiliary, destination, source, moves);
6565
}
6666

67-
public static void main(String[] args){
67+
public static void main(String[] args) {
6868
Scanner scanner = new Scanner(System.in);
6969
System.out.print("Enter the number of disks: ");
7070
int n = scanner.nextInt();
7171
List<String> result = solveTowerOfHanoi(n, 'A', 'C', 'B');
7272

73-
for(String move: result){
73+
for(String move : result){
7474
System.out.println(move);
7575
}
76-
}
76+
}
77+
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.thealgorithms.recursion;
22

3-
import org.junit.jupiter.api.Test;
3+
44
import static org.junit.jupiter.api.Assertions.assertEquals;
55
import static org.junit.jupiter.api.Assertions.assertThrows;
6+
67
import java.util.Arrays;
78
import java.util.List;
9+
import org.junit.jupiter.api.Test;
810

911
public class TowerOfHanoiTest {
1012

@@ -36,10 +38,9 @@ public void testSmallRecursion() {
3638
assertEquals(3, result.size());
3739

3840
// Assertion 2: Verify the exact sequence of moves
39-
List<String> expected = Arrays.asList(
40-
"Move disk 1 from rod A to rod B", // Small disk to Aux
41+
List<String> expected = Arrays.asList("Move disk 1 from rod A to rod B", // Small disk to Aux
4142
"Move disk 2 from rod A to rod C", // Big disk to Dest
42-
"Move disk 1 from rod B to rod C" // Small disk to Dest
43+
"Move disk 1 from rod B to rod C" // Small disk to Dest
4344
);
4445

4546
assertEquals(expected, result, "Sequence of moves for 2 disks is incorrect");
@@ -67,8 +68,7 @@ public void testStandardCase() {
6768
*/
6869
@Test
6970
public void testNegativeInput() {
70-
assertThrows(IllegalArgumentException.class, () -> {
71-
TowerOfHanoi.solveTowerOfHanoi(-5, 'A', 'C', 'B');
72-
}, "Should throw exception for negative disks");
71+
assertThrows(IllegalArgumentException.class, () -> { TowerOfHanoi.solveTowerOfHanoi(-5, 'A', 'C', 'B'); },
72+
"Should throw exception for negative disks");
7373
}
7474
}

0 commit comments

Comments
 (0)