Ejemplo n.º 1
0
  @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);
  }
Ejemplo n.º 2
0
 @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());
 }
Ejemplo n.º 3
0
  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();
  }
Ejemplo n.º 4
0
  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();
  }