@Test public void randomTest() throws IOException { Set<String> dict = new HashSet<>(); FileReader fileReader = new FileReader(new File("src\\part2\\week4\\" + "trie\\extracredit\\dictionary-twl06.txt")); BufferedReader bufferedReader = new BufferedReader(fileReader); while (true) { String word = bufferedReader.readLine(); if (word == null) break; if (word.length() > 0) dict.add(word.toLowerCase()); } T9Texting t9Texting = new T9Texting(new ArrayList<>(dict)); int N = 2; for (int i = 0; i < 1000; i++) { if (i % 100 == 99) N++; String input = RandomStringBuilder.randomString(N, "23456789"); List<String> testResult = t9Texting.query(input); if (testResult.isEmpty()) continue; System.out.println("input : " + input); System.out.println("query result :"); for (String word : testResult) { System.out.println(word); StringBuilder sb = new StringBuilder(); for (char c : word.toCharArray()) { sb.append(map[c - 'a']); } Assert.assertEquals(input, sb.toString()); } } }
public List<String> query(String input) { char[] cs = input.toCharArray(); List<String> result = new ArrayList<>(); dfs(cs, 0, result, root); return result; }
T9Texting { public List<String> query(String input) { char[] cs = input.toCharArray(); List<String> result = new ArrayList<>(); dfs(cs, 0, result, root); return result; } }
T9Texting { public List<String> query(String input) { char[] cs = input.toCharArray(); List<String> result = new ArrayList<>(); dfs(cs, 0, result, root); return result; } T9Texting(List<String> dict); }
T9Texting { public List<String> query(String input) { char[] cs = input.toCharArray(); List<String> result = new ArrayList<>(); dfs(cs, 0, result, root); return result; } T9Texting(List<String> dict); List<String> query(String input); }
T9Texting { public List<String> query(String input) { char[] cs = input.toCharArray(); List<String> result = new ArrayList<>(); dfs(cs, 0, result, root); return result; } T9Texting(List<String> dict); List<String> query(String input);  }