|
| 1 | +package com.thealgorithms.strings; |
| 2 | + |
| 3 | +import java.util.*; |
| 4 | +import static org.junit.jupiter.api.Assertions.*; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +public class LetterCombinationsOfPhoneNumberTest { |
| 8 | + |
| 9 | + @Test |
| 10 | + public void letterCombinationsOfPhoneNumber() { |
| 11 | + LetterCombinationsOfPhoneNumber ob = new LetterCombinationsOfPhoneNumber(); |
| 12 | + ob.generateNumberToCharMap(); |
| 13 | + |
| 14 | + // ** Test 1 ** |
| 15 | + // Input: digits = "" |
| 16 | + // Output: [] |
| 17 | + int[] numbers1 = {}; |
| 18 | + List<String> output1 = Arrays.asList(""); |
| 19 | + assertTrue(ob.printWords(numbers1, numbers1.length, 0, "").equals(output1)); |
| 20 | + |
| 21 | + // ** Test 2 ** |
| 22 | + // Input: digits = "2" |
| 23 | + // Output: ["a","b","c"] |
| 24 | + int[] numbers2 = { 2 }; |
| 25 | + List<String> output2 = Arrays.asList("a", "b", "c"); |
| 26 | + assertTrue(ob.printWords(numbers2, numbers2.length, 0, "").equals(output2)); |
| 27 | + |
| 28 | + // ** Test 3 ** |
| 29 | + // Input: digits = "23" |
| 30 | + // Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] |
| 31 | + int[] numbers3 = { 2, 3 }; |
| 32 | + List<String> output3 = Arrays.asList("ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"); |
| 33 | + assertTrue(ob.printWords(numbers3, numbers3.length, 0, "").equals(output3)); |
| 34 | + |
| 35 | + // ** Test 4 ** |
| 36 | + // Input: digits = "234" |
| 37 | + // Output: ["adg", "adh", "adi", "aeg", "aeh", "aei", "afg", "afh", "afi", |
| 38 | + // "bdg", "bdh", "bdi", "beg", "beh", "bei", "bfg", "bfh", "bfi", "cdg", "cdh", |
| 39 | + // "cdi", "ceg", "ceh", "cei", "cfg", "cfh", "cfi"] |
| 40 | + int[] numbers4 = { 2, 3, 4 }; |
| 41 | + List<String> output4 = Arrays.asList("adg", "adh", "adi", "aeg", "aeh", "aei", "afg", "afh", "afi", "bdg", |
| 42 | + "bdh", "bdi", "beg", "beh", "bei", "bfg", "bfh", "bfi", "cdg", "cdh", "cdi", "ceg", "ceh", "cei", "cfg", |
| 43 | + "cfh", "cfi"); |
| 44 | + assertTrue(ob.printWords(numbers4, numbers4.length, 0, "").equals(output4)); |
| 45 | + } |
| 46 | +} |
0 commit comments