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() {}
1111
1212 private static Long primeFactor (Long n ) {
1313 if (n < 2 ) {
14- return null ;
14+ throw new IllegalArgumentException ( "n must be greater than 2" ) ;
1515 }
1616
1717 Long divisor = n ;
Original file line number Diff line number Diff line change 11package ae .hackerrank .projecteuler ;
22
33import 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 ;
46
57import java .io .IOException ;
68import java .util .List ;
79import org .junit .jupiter .api .BeforeAll ;
810import org .junit .jupiter .api .Test ;
911import org .junit .jupiter .api .TestInstance ;
1012import org .junit .jupiter .api .TestInstance .Lifecycle ;
13+ import org .junit .jupiter .params .ParameterizedTest ;
14+ import org .junit .jupiter .params .provider .CsvSource ;
1115import util .JsonLoader ;
1216
1317
@@ -45,4 +49,22 @@ public void setup() throws IOException {
4549 );
4650 }
4751 }
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+ }
4870}
You can’t perform that action at this time.
0 commit comments