Created
December 29, 2011 19:13
-
-
Save MrTrick/1535708 to your computer and use it in GitHub Desktop.
DAWG collapsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testDawgDictionaryCollapse() { | |
Dictionary dictionary = Dictionary.buildDefaultDictionary(); | |
Trie trie = new Trie(dictionary); | |
Dawg dawg = new Dawg(dictionary); | |
assertEquals(395184, trie.countNodes()); | |
int i=0; | |
//Despite the merged nodes, a dawg should look structurally the same as a trie. | |
TrieIterator t = trie.iterator(), d = dawg.iterator(); | |
while(t.hasNext() && d.hasNext()) { | |
Trie.Node tn = t.next(), dn = d.next(); | |
for(char letter='A';letter<='Z';letter++) | |
assertEquals( tn.getChild(letter)!=null, dn.getChild(letter)!=null ); | |
i++; | |
} | |
assertFalse(t.hasNext()); | |
assertFalse(d.hasNext()); | |
assertEquals(395184, i); | |
assertTrue( trie.countNodes() > dawg.countNodes() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment