File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
algorithm-exercises-java/src
main/java/ae/hackerrank/projecteuler
test/java/ae/hackerrank/projecteuler Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ private Euler003() {}
11
11
12
12
private static Long primeFactor (Long n ) {
13
13
if (n < 2 ) {
14
- return null ;
14
+ throw new IllegalArgumentException ( "n must be greater than 2" ) ;
15
15
}
16
16
17
17
Long divisor = n ;
Original file line number Diff line number Diff line change 1
1
package ae .hackerrank .projecteuler ;
2
2
3
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
5
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
4
6
5
7
import java .io .IOException ;
6
8
import java .util .List ;
7
9
import org .junit .jupiter .api .BeforeAll ;
8
10
import org .junit .jupiter .api .Test ;
9
11
import org .junit .jupiter .api .TestInstance ;
10
12
import org .junit .jupiter .api .TestInstance .Lifecycle ;
13
+ import org .junit .jupiter .params .ParameterizedTest ;
14
+ import org .junit .jupiter .params .provider .CsvSource ;
11
15
import util .JsonLoader ;
12
16
13
17
@@ -45,4 +49,22 @@ public void setup() throws IOException {
45
49
);
46
50
}
47
51
}
52
+
53
+ @ ParameterizedTest
54
+ @ CsvSource ({
55
+ "0" ,
56
+ "1"
57
+ }) void euler003edgecases (long input ) {
58
+
59
+ Exception exception ;
60
+
61
+ exception = assertThrows (IllegalArgumentException .class , () ->
62
+ Euler003 .euler003 (input )
63
+ );
64
+
65
+ String expectedMessage = "n must be greater than 2" ;
66
+
67
+ assertTrue (exception .getMessage ().contains (expectedMessage ));
68
+
69
+ }
48
70
}
You can’t perform that action at this time.
0 commit comments