@Test public void testGetAnyWordStartingWith() { ArrayList<String> words = new ArrayList<>(Arrays.asList(wordsArray)); SimpleDictionary dict = new SimpleDictionary(words, 0); assertNull(dict.getAnyWordStartingWith("notaword")); assertNull(dict.getAnyWordStartingWith("caq")); assertNotNull(dict.getAnyWordStartingWith("")); assertNull(dict.getAnyWordStartingWith("catfishes")); assertEquals("catfishes", dict.getAnyWordStartingWith("catfish")); assertTrue(dict.getAnyWordStartingWith("cat").startsWith("cat")); assertEquals("lives", dict.getAnyWordStartingWith("liv")); assertEquals("apple", dict.getAnyWordStartingWith("a")); assertEquals("apple", dict.getAnyWordStartingWith("ap")); assertEquals("apple", dict.getAnyWordStartingWith("app")); assertEquals("apple", dict.getAnyWordStartingWith("appl")); }
@Override public String getAnyWordStartingWith(String prefix) { if (prefix.equals("")) { return words.get(mRandom.nextInt(words.size())); } else { return findByPrefix(prefix); } }
SimpleDictionary implements GhostDictionary { @Override public String getAnyWordStartingWith(String prefix) { if (prefix.equals("")) { return words.get(mRandom.nextInt(words.size())); } else { return findByPrefix(prefix); } } }
SimpleDictionary implements GhostDictionary { @Override public String getAnyWordStartingWith(String prefix) { if (prefix.equals("")) { return words.get(mRandom.nextInt(words.size())); } else { return findByPrefix(prefix); } } SimpleDictionary(InputStream wordListStream); @VisibleForTesting  SimpleDictionary(ArrayList<String> words, long randomSeed); }
SimpleDictionary implements GhostDictionary { @Override public String getAnyWordStartingWith(String prefix) { if (prefix.equals("")) { return words.get(mRandom.nextInt(words.size())); } else { return findByPrefix(prefix); } } SimpleDictionary(InputStream wordListStream); @VisibleForTesting  SimpleDictionary(ArrayList<String> words, long randomSeed); @Override boolean isWord(String word); @Override String getAnyWordStartingWith(String prefix); @Override String getGoodWordStartingWith(String prefix); }
SimpleDictionary implements GhostDictionary { @Override public String getAnyWordStartingWith(String prefix) { if (prefix.equals("")) { return words.get(mRandom.nextInt(words.size())); } else { return findByPrefix(prefix); } } SimpleDictionary(InputStream wordListStream); @VisibleForTesting  SimpleDictionary(ArrayList<String> words, long randomSeed); @Override boolean isWord(String word); @Override String getAnyWordStartingWith(String prefix); @Override String getGoodWordStartingWith(String prefix);  }