-
Notifications
You must be signed in to change notification settings - Fork 20k
refactor: redesign LetterCombinationsOfPhoneNumber
#5221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vil02
merged 29 commits into
TheAlgorithms:master
from
samuelfac:cleanup_LetterCombinationsOfPhoneNumber
Jun 13, 2024
Merged
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
61e2a98
Refactor
93252bf
fix clang
96bdb98
fix clang
8fe553a
Merge branch 'cleanup_LetterCombinationsOfPhoneNumber' of https://git…
bfb4d32
fix clang tests
b228744
fix pattern
b1a6124
add test case null
667403b
Update src/main/java/com/thealgorithms/strings/LetterCombinationsOfPh…
samuelfac 48f23e2
Update src/main/java/com/thealgorithms/strings/LetterCombinationsOfPh…
samuelfac e1a428c
Update src/main/java/com/thealgorithms/strings/LetterCombinationsOfPh…
samuelfac cc069a8
Update src/main/java/com/thealgorithms/strings/LetterCombinationsOfPh…
samuelfac fda621b
Update src/main/java/com/thealgorithms/strings/LetterCombinationsOfPh…
samuelfac d8ace83
Update src/main/java/com/thealgorithms/strings/LetterCombinationsOfPh…
samuelfac b257d14
Update src/test/java/com/thealgorithms/strings/LetterCombinationsOfPh…
samuelfac 575b5e1
rename MAP_OF_CHARS to KEYPAD
909acdb
fix clang
1c100ef
remove main
97e26d3
add tests
910c814
feat: throw for wrong inputs
vil02 06d49ce
change keypad to list
349dedc
Merge branch 'master' into cleanup_LetterCombinationsOfPhoneNumber
41c7007
Update src/main/java/com/thealgorithms/strings/LetterCombinationsOfPh…
samuelfac 3ef428b
Update src/main/java/com/thealgorithms/strings/LetterCombinationsOfPh…
samuelfac d3f8c03
Update src/main/java/com/thealgorithms/strings/LetterCombinationsOfPh…
samuelfac 24697f9
fix with number 1 (empty value), and add tests
5b39d4b
style: avoid concatenation while populating `KEYPAD`
vil02 f83e55c
Merge branch 'master' into cleanup_LetterCombinationsOfPhoneNumber
samuelfac aeb56a9
Merge branch 'master' into cleanup_LetterCombinationsOfPhoneNumber
samuelfac 87aff59
change to assertEquals
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 24 additions & 32 deletions
56
src/test/java/com/thealgorithms/strings/LetterCombinationsOfPhoneNumberTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,37 @@ | ||
package com.thealgorithms.strings; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class LetterCombinationsOfPhoneNumberTest { | ||
|
||
@Test | ||
public void letterCombinationsOfPhoneNumber() { | ||
LetterCombinationsOfPhoneNumber.generateNumberToCharMap(); | ||
|
||
// ** Test 1 ** | ||
// Input: digits = "" | ||
// Output: [] | ||
int[] numbers1 = {}; | ||
List<String> output1 = Arrays.asList(""); | ||
assertTrue(LetterCombinationsOfPhoneNumber.printWords(numbers1, numbers1.length, 0, "").equals(output1)); | ||
@ParameterizedTest | ||
@MethodSource("provideTestCases") | ||
public void testLetterCombinationsOfPhoneNumber(int[] numbers, List<String> expectedOutput) { | ||
assertEquals(expectedOutput, LetterCombinationsOfPhoneNumber.getCombinations(numbers)); | ||
} | ||
|
||
// ** Test 2 ** | ||
// Input: digits = "2" | ||
// Output: ["a","b","c"] | ||
int[] numbers2 = {2}; | ||
List<String> output2 = Arrays.asList("a", "b", "c"); | ||
assertTrue(LetterCombinationsOfPhoneNumber.printWords(numbers2, numbers2.length, 0, "").equals(output2)); | ||
@ParameterizedTest | ||
@MethodSource("wrongInputs") | ||
void throwsForWrongInput(int[] numbers) { | ||
assertThrows(IllegalArgumentException.class, () -> LetterCombinationsOfPhoneNumber.getCombinations(numbers)); | ||
} | ||
|
||
// ** Test 3 ** | ||
// Input: digits = "23" | ||
// Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] | ||
int[] numbers3 = {2, 3}; | ||
List<String> output3 = Arrays.asList("ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"); | ||
assertTrue(LetterCombinationsOfPhoneNumber.printWords(numbers3, numbers3.length, 0, "").equals(output3)); | ||
private static Stream<Arguments> provideTestCases() { | ||
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")), | ||
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")), | ||
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 ")), | ||
Arguments.of(new int[] {9, 2}, Arrays.asList("wa", "wb", "wc", "xa", "xb", "xc", "ya", "yb", "yc", "za", "zb", "zc"))); | ||
} | ||
samuelfac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// ** Test 4 ** | ||
// Input: digits = "234" | ||
// Output: ["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"] | ||
int[] numbers4 = {2, 3, 4}; | ||
List<String> output4 = 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"); | ||
assertTrue(LetterCombinationsOfPhoneNumber.printWords(numbers4, numbers4.length, 0, "").equals(output4)); | ||
private static Stream<Arguments> wrongInputs() { | ||
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})); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.