1
1
package com .thealgorithms .strings ;
2
2
3
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
4
5
5
6
import java .util .Arrays ;
6
7
import java .util .List ;
@@ -17,10 +18,20 @@ public void testLetterCombinationsOfPhoneNumber(int[] numbers, List<String> expe
17
18
assertEquals (expectedOutput , LetterCombinationsOfPhoneNumber .getCombinations (numbers ));
18
19
}
19
20
21
+ @ ParameterizedTest
22
+ @ MethodSource ("wrongInputs" )
23
+ void throwsForWrongInput (int [] numbers ) {
24
+ assertThrows (IllegalArgumentException .class , () -> LetterCombinationsOfPhoneNumber .getCombinations (numbers ));
25
+ }
26
+
20
27
private static Stream <Arguments > provideTestCases () {
21
28
return Stream .of (Arguments .of (null , List .of ("" )), Arguments .of (new int [] {}, List .of ("" )), Arguments .of (new int [] {2 }, Arrays .asList ("a" , "b" , "c" )), Arguments .of (new int [] {2 , 3 }, Arrays .asList ("ad" , "ae" , "af" , "bd" , "be" , "bf" , "cd" , "ce" , "cf" )),
22
29
Arguments .of (new int [] {2 , 3 , 4 }, Arrays .asList ("adg" , "adh" , "adi" , "aeg" , "aeh" , "aei" , "afg" , "afh" , "afi" , "bdg" , "bdh" , "bdi" , "beg" , "beh" , "bei" , "bfg" , "bfh" , "bfi" , "cdg" , "cdh" , "cdi" , "ceg" , "ceh" , "cei" , "cfg" , "cfh" , "cfi" )),
23
30
Arguments .of (new int [] {3 , 3 }, Arrays .asList ("dd" , "de" , "df" , "ed" , "ee" , "ef" , "fd" , "fe" , "ff" )), Arguments .of (new int [] {8 , 4 }, Arrays .asList ("tg" , "th" , "ti" , "ug" , "uh" , "ui" , "vg" , "vh" , "vi" )), Arguments .of (new int [] {2 , 0 }, Arrays .asList ("a " , "b " , "c " )),
24
31
Arguments .of (new int [] {9 , 2 }, Arrays .asList ("wa" , "wb" , "wc" , "xa" , "xb" , "xc" , "ya" , "yb" , "yc" , "za" , "zb" , "zc" )));
25
32
}
33
+
34
+ private static Stream <Arguments > wrongInputs () {
35
+ return Stream .of (Arguments .of (new int [] {-1 }), Arguments .of (new int [] {10 }), Arguments .of (new int [] {2 , 2 , -1 , 0 }), Arguments .of (new int [] {0 , 0 , 0 , 10 }));
36
+ }
26
37
}
0 commit comments