@Test public void testGetChildren() { Trie trie = new Trie(); trie.add("aa"); trie.add("ab"); trie.add("bb"); Node rootNode = trie.getRoot(); assertEquals(2, rootNode.getChildren().length); assertEquals(2, rootNode.getChildren()[0].getChildren().length); assertEquals(1, rootNode.getChildren()[1].getChildren().length); }
@Test public void testSinglePath() { Trie trie = new Trie(); assertTrue(trie.getRoot().hasSinglePath()); trie.add("abcdef"); assertTrue(trie.getRoot().hasSinglePath()); trie.add("abdfg"); Node rootNode = trie.getRoot(); assertEquals(2, rootNode.getChildren()[0].getChildren()[0].getChildren().length); assertTrue(rootNode.getChildren()[0].getChildren()[0].getChildren()[0].hasSinglePath()); assertTrue(rootNode.getChildren()[0].getChildren()[0].getChildren()[1].hasSinglePath()); }
public static void main(String[] args) { Trie trie = new Trie(); trie.add("Causal"); trie.add("absurd"); trie.add("crappy"); trie.add("spooky"); trie.add("bullcrap"); trie.add("bullshit"); trie.add("Africa"); trie.add("Asia"); trie.add("Osiris"); trie.add("Heman"); trie.add("OhMyGod"); trie.printAll(); }
public static void main(String[] args) { String[] ss = {"ayb", "aye", "ayberk", "cbbb"}; Trie trie = new Trie(); for (String s : ss) { trie.add(s); } System.out.println(trie.isPrefix("ay")); System.out.println(trie.isPrefix("xay")); System.out.println(trie.includes("ay")); System.out.println(trie.includes("ayb")); trie.printAllWords(); }