88import org .junit .jupiter .api .Test ;
99
1010public class FactorialTest {
11-
1211 // --------------------------------------------------------
1312 // SECTION 1: Basic Correctness Tests
1413 // --------------------------------------------------------
@@ -25,7 +24,7 @@ void testFactorialOfZero() {
2524
2625 @ Test
2726 void testNegativeInputThrowsException () {
28- assertThrows (IllegalArgumentException .class , () -> Factorial .factorial (-5 ));
27+ assertThrows (IllegalArgumentException .class , () -> { Factorial .factorial (-5 ); } );
2928 }
3029
3130 // --------------------------------------------------------
@@ -47,18 +46,17 @@ void testLargeInputPerformance() {
4746 // --------------------------------------------------------
4847
4948 /**
50- * Local copy of the original recursive implementation used only for comparing performance inside
51- * the test.
49+ * Local copy of the original recursive implementation
50+ * used only for comparing performance inside the test.
5251 */
5352 private long recursiveFactorial (long n ) {
5453 if (n < 0 ) {
5554 throw new IllegalArgumentException ("Negative input not allowed" );
5655 }
5756 if (n == 0 || n == 1 ) {
5857 return 1 ;
59- } else {
60- return n * recursiveFactorial (n - 1 );
6158 }
59+ return n * recursiveFactorial (n - 1 );
6260 }
6361
6462 @ Test
@@ -74,9 +72,7 @@ void testIterativeFasterThanRecursive() {
7472 long endIter = System .nanoTime ();
7573
7674 assertEquals (recResult , iterResult );
77- assertTrue (
78- endIter - startIter < endRec - startRec ,
79- "Iterative version should outperform recursive version" );
75+ assertTrue (endIter - startIter < endRec - startRec , "Iterative version should outperform recursive version" );
8076 }
8177
8278 @ Test
0 commit comments