@Test public void testGetAnagrams() { AnagramDictionary dict = new AnagramDictionary(words); List<String> result = dict.getAnagrams("cat"); assertEquals(2, result.size()); assertTrue(result.contains("cat")); assertTrue(result.contains("act")); assertFalse(result.contains("dog")); assertFalse(result.contains("spots")); assertTrue(dict.getAnagrams("stops").contains("spots")); }
public ArrayList<String> getAnagrams(String targetWord) { if (targetWord == null || targetWord.equals("")) { return null; } String letters = sortLetters(targetWord); if (lettersToWord.containsKey(letters)) { return lettersToWord.get(letters); } return null; }
AnagramDictionary { public ArrayList<String> getAnagrams(String targetWord) { if (targetWord == null || targetWord.equals("")) { return null; } String letters = sortLetters(targetWord); if (lettersToWord.containsKey(letters)) { return lettersToWord.get(letters); } return null; } }
AnagramDictionary { public ArrayList<String> getAnagrams(String targetWord) { if (targetWord == null || targetWord.equals("")) { return null; } String letters = sortLetters(targetWord); if (lettersToWord.containsKey(letters)) { return lettersToWord.get(letters); } return null; } AnagramDictionary(InputStream wordListStream); @VisibleForTesting  AnagramDictionary(String[] words); }
AnagramDictionary { public ArrayList<String> getAnagrams(String targetWord) { if (targetWord == null || targetWord.equals("")) { return null; } String letters = sortLetters(targetWord); if (lettersToWord.containsKey(letters)) { return lettersToWord.get(letters); } return null; } AnagramDictionary(InputStream wordListStream); @VisibleForTesting  AnagramDictionary(String[] words); boolean isGoodWord(String word, String base); ArrayList<String> getAnagrams(String targetWord); ArrayList<String> getAnagramsWithOneMoreLetter(String word); String pickGoodStarterWord(); }
AnagramDictionary { public ArrayList<String> getAnagrams(String targetWord) { if (targetWord == null || targetWord.equals("")) { return null; } String letters = sortLetters(targetWord); if (lettersToWord.containsKey(letters)) { return lettersToWord.get(letters); } return null; } AnagramDictionary(InputStream wordListStream); @VisibleForTesting  AnagramDictionary(String[] words); boolean isGoodWord(String word, String base); ArrayList<String> getAnagrams(String targetWord); ArrayList<String> getAnagramsWithOneMoreLetter(String word); String pickGoodStarterWord();  }