@Test public void testSpellPossibilityIterator() throws Exception { Map<Token, LinkedHashMap<String, Integer>> suggestions = new LinkedHashMap<Token, LinkedHashMap<String, Integer>>(); suggestions.put(TOKEN_AYE, AYE); suggestions.put(TOKEN_BEE, BEE); suggestions.put(TOKEN_CEE, CEE); PossibilityIterator iter = new PossibilityIterator(suggestions, 1000, 10000, false); int count = 0; while (iter.hasNext()) { PossibilityIterator.RankedSpellPossibility rsp = iter.next(); if (count == 0) { assertTrue("I".equals(rsp.corrections.get(0).getCorrection())); assertTrue("alpha".equals(rsp.corrections.get(1).getCorrection())); assertTrue("one".equals(rsp.corrections.get(2).getCorrection())); } count++; } assertTrue( ("Three maps (8*9*10) should return 720 iterations but instead returned " + count), count == 720); suggestions.remove(TOKEN_CEE); iter = new PossibilityIterator(suggestions, 100, 10000, false); count = 0; while (iter.hasNext()) { iter.next(); count++; } assertTrue( ("Two maps (8*9) should return 72 iterations but instead returned " + count), count == 72); suggestions.remove(TOKEN_BEE); iter = new PossibilityIterator(suggestions, 5, 10000, false); count = 0; while (iter.hasNext()) { iter.next(); count++; } assertTrue(("We requested 5 suggestions but got " + count), count == 5); suggestions.remove(TOKEN_AYE); iter = new PossibilityIterator(suggestions, Integer.MAX_VALUE, 10000, false); count = 0; while (iter.hasNext()) { iter.next(); count++; } assertTrue(("No maps should return 0 iterations but instead returned " + count), count == 0); }
@Test public void testOverlappingTokens() throws Exception { Map<Token, LinkedHashMap<String, Integer>> overlappingSuggestions = new LinkedHashMap<Token, LinkedHashMap<String, Integer>>(); overlappingSuggestions.put(TOKEN_AYE, AYE); overlappingSuggestions.put(TOKEN_BEE, BEE); overlappingSuggestions.put(TOKEN_AYE_BEE, AYE_BEE); overlappingSuggestions.put(TOKEN_CEE, CEE); PossibilityIterator iter = new PossibilityIterator(overlappingSuggestions, Integer.MAX_VALUE, Integer.MAX_VALUE, true); int aCount = 0; int abCount = 0; Set<PossibilityIterator.RankedSpellPossibility> dupChecker = new HashSet<PossibilityIterator.RankedSpellPossibility>(); while (iter.hasNext()) { PossibilityIterator.RankedSpellPossibility rsp = iter.next(); Token a = null; Token b = null; Token ab = null; Token c = null; for (SpellCheckCorrection scc : rsp.corrections) { if (scc.getOriginal().equals(TOKEN_AYE)) { a = scc.getOriginal(); } else if (scc.getOriginal().equals(TOKEN_BEE)) { b = scc.getOriginal(); } else if (scc.getOriginal().equals(TOKEN_AYE_BEE)) { ab = scc.getOriginal(); } else if (scc.getOriginal().equals(TOKEN_CEE)) { c = scc.getOriginal(); } if (ab != null) { abCount++; } else { aCount++; } } assertTrue(c != null); assertTrue(ab != null || (a != null && b != null)); assertTrue(ab == null || (a == null && b == null)); assertTrue(dupChecker.add(rsp)); } assertTrue(aCount == 2160); assertTrue(abCount == 180); }
@Test public void testScalability() throws Exception { Map<Token, LinkedHashMap<String, Integer>> lotsaSuggestions = new LinkedHashMap<Token, LinkedHashMap<String, Integer>>(); lotsaSuggestions.put(TOKEN_AYE, AYE); lotsaSuggestions.put(TOKEN_BEE, BEE); lotsaSuggestions.put(TOKEN_CEE, CEE); lotsaSuggestions.put(new Token("AYE1", 0, 3), AYE); lotsaSuggestions.put(new Token("BEE1", 4, 7), BEE); lotsaSuggestions.put(new Token("CEE1", 8, 11), CEE); lotsaSuggestions.put(new Token("AYE2", 0, 3), AYE); lotsaSuggestions.put(new Token("BEE2", 4, 7), BEE); lotsaSuggestions.put(new Token("CEE2", 8, 11), CEE); lotsaSuggestions.put(new Token("AYE3", 0, 3), AYE); lotsaSuggestions.put(new Token("BEE3", 4, 7), BEE); lotsaSuggestions.put(new Token("CEE3", 8, 11), CEE); lotsaSuggestions.put(new Token("AYE4", 0, 3), AYE); lotsaSuggestions.put(new Token("BEE4", 4, 7), BEE); lotsaSuggestions.put(new Token("CEE4", 8, 11), CEE); PossibilityIterator iter = new PossibilityIterator(lotsaSuggestions, 1000, 10000, false); int count = 0; while (iter.hasNext()) { PossibilityIterator.RankedSpellPossibility rsp = iter.next(); count++; } assertTrue(count == 1000); lotsaSuggestions.put(new Token("AYE_BEE1", 0, 7), AYE_BEE); lotsaSuggestions.put(new Token("AYE_BEE2", 0, 7), AYE_BEE); lotsaSuggestions.put(new Token("AYE_BEE3", 0, 7), AYE_BEE); lotsaSuggestions.put(new Token("AYE_BEE4", 0, 7), AYE_BEE); iter = new PossibilityIterator(lotsaSuggestions, 1000, 10000, true); count = 0; while (iter.hasNext()) { PossibilityIterator.RankedSpellPossibility rsp = iter.next(); count++; } assertTrue(count < 100); }