Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathLetterCombinationsOfPhoneNumberTest.java
More file actions
Latest commit
37 lines (30 loc) · 2.29 KB
/
Copy pathLetterCombinationsOfPhoneNumberTest.java
File metadata and controls
37 lines (30 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
packagecom.thealgorithms.strings;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importjava.util.List;
importjava.util.stream.Stream;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
publicclassLetterCombinationsOfPhoneNumberTest {
@ParameterizedTest
@MethodSource("provideTestCases")
publicvoidtestLetterCombinationsOfPhoneNumber(int[] numbers, List<String> expectedOutput) {
assertEquals(expectedOutput, LetterCombinationsOfPhoneNumber.getCombinations(numbers));
}
@ParameterizedTest
@MethodSource("wrongInputs")
voidthrowsForWrongInput(int[] numbers) {
assertThrows(IllegalArgumentException.class, () -> LetterCombinationsOfPhoneNumber.getCombinations(numbers));
}
privatestaticStream<Arguments> provideTestCases() {
returnStream.of(Arguments.of(null, List.of("")), Arguments.of(newint[] {}, List.of("")), Arguments.of(newint[] {2}, List.of("a", "b", "c")), Arguments.of(newint[] {2, 3}, List.of("ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf")),
Arguments.of(newint[] {2, 3, 4}, List.of("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")),
Arguments.of(newint[] {3, 3}, List.of("dd", "de", "df", "ed", "ee", "ef", "fd", "fe", "ff")), Arguments.of(newint[] {8, 4}, List.of("tg", "th", "ti", "ug", "uh", "ui", "vg", "vh", "vi")), Arguments.of(newint[] {2, 0}, List.of("a ", "b ", "c ")),
Arguments.of(newint[] {9, 2}, List.of("wa", "wb", "wc", "xa", "xb", "xc", "ya", "yb", "yc", "za", "zb", "zc")), Arguments.of(newint[] {0}, List.of(" ")), Arguments.of(newint[] {1}, List.of("")), Arguments.of(newint[] {2}, List.of("a", "b", "c")),
Arguments.of(newint[] {1, 2, 0, 4}, List.of("a g", "a h", "a i", "b g", "b h", "b i", "c g", "c h", "c i")));
}
privatestaticStream<Arguments> wrongInputs() {
returnStream.of(Arguments.of(newint[] {-1}), Arguments.of(newint[] {10}), Arguments.of(newint[] {2, 2, -1, 0}), Arguments.of(newint[] {0, 0, 0, 10}));
}
}