@Test(timeout = 500L) public void testFindAllAnagramsByNonExistentDictionaryWord() throws InvalidWordException { Set<String> anagrams = classUnderTest.findAllAnagramsForTheWord("nonExistentWord"); assertEquals(0, anagrams.size()); logger.info( "Searching for anagrams of 'nonExistentWord' returned " + anagrams.size() + " results."); }
@Test(timeout = 500L) public void testFindAllAnagramsByDictionaryWord() throws InvalidWordException { Set<String> anagrams = classUnderTest.findAllAnagramsForTheWord("leaps"); assertEquals(6, anagrams.size()); assertTrue( anagrams.containsAll( Arrays.asList(new String[] {"lapse", "leaps", "pales", "peals", "pleas", "sepal"}))); logger.info("Searching for anagrams of 'leaps' returned: " + anagrams); }
/** * <b>Note</b> the timeout is quite long for this. The loadDictionary method normally takes about * 3 seconds when logging output to a file, but if logging to the console takes significantly * longer i.e. > 10 seconds! * * @throws IOException * @throws InvalidWordException * @throws MalformedInputException */ @Test(timeout = 20000L) public void testLoadDictionary() throws IOException, InvalidWordException, MalformedInputException { classUnderTest.loadDictionary(); }
@Test(timeout = 500L) public void testAnagramCountByKey() { assertEquals(2, classUnderTest.getAnagramsMap().get("adef").size()); assertEquals(6, classUnderTest.getAnagramsMap().get("aelps").size()); }
/** * Creates a new {@link DictionaryWord} and adds it to the {@link AnagramCalculator#anagramMap} * field. * * @param word new word * @throws InvalidWordException if the word contains illegal characters or is of bad format @see * {@link DictionaryWord#pattern}. */ private void createNewDictionaryWord(String word) throws InvalidWordException { DictionaryWord newWord = new DictionaryWord(word); classUnderTest.addWordToAnagramSet(newWord); }