Esempio n. 1
0
  @Test
  public void testSimple() {
    Trie trie = instance();

    assertTrue(trie.add("abc"));
    assertTrue(trie.contains("abc"));
    assertEquals(1, trie.size());
    assertEquals(1, trie.howManyStartsWithPrefix("abc"));
  }
Esempio n. 2
0
  @org.junit.Test
  public void testHowManyStartsWithPrefix() throws Exception {
    Trie trie = new TrieImpl();
    trie.add("Very");
    trie.add("VeryVery");
    trie.add("VeryVeryLong");
    trie.add("VeryVeryLongWord");

    assertEquals(4, trie.howManyStartsWithPrefix("V"));
    assertEquals(4, trie.howManyStartsWithPrefix("Very"));
    assertEquals(0, trie.howManyStartsWithPrefix("VE"));
    assertEquals(3, trie.howManyStartsWithPrefix("VeryV"));
    assertEquals(3, trie.howManyStartsWithPrefix("VeryVery"));
    assertEquals(0, trie.howManyStartsWithPrefix("VeryVeryV"));
    assertEquals(2, trie.howManyStartsWithPrefix("VeryVeryL"));
    assertEquals(1, trie.howManyStartsWithPrefix("VeryVeryLongWord"));
    assertEquals(4, trie.howManyStartsWithPrefix(""));
  }