Example #1
0
        public void Test54TruncatingIteratorFromLinearMatchLong()
        {
            StringAndValue[] data =
            {
                new StringAndValue("abcdef",   10),
                new StringAndValue("abcdepq", 200),
                new StringAndValue("abcdeyz", 3000)
            };
            BytesTrie trie = buildTrie(data, data.Length, TrieBuilderOption.Fast);

            // Go into a linear-match node.
            trie.Next('a');
            trie.Next('b');
            trie.Next('c');
            // Truncate after the linear-match node.
            BytesTrieEnumerator iter = trie.GetEnumerator(3);

            StringAndValue[] expected =
            {
                new StringAndValue("def", 10),
                new StringAndValue("dep", -1),
                new StringAndValue("dey", -1)
            };
            checkIterator(iter, expected);
            // Reset, and we should get the same result.
            Logln("after iter.Reset()");
            checkIterator(iter.Reset(), expected);
        }
Example #2
0
        public void Test50IteratorFromBranch()
        {
            BytesTrie trie = buildMonthsTrie(TrieBuilderOption.Fast);

            // Go to a branch node.
            trie.Next('j');
            trie.Next('a');
            trie.Next('n');
            BytesTrieEnumerator iter = (BytesTrieEnumerator)trie.GetEnumerator();

            // Expected data: Same as in buildMonthsTrie(), except only the suffixes
            // following "jan".
            StringAndValue[] data =
            {
                new StringAndValue("",                             1),
                new StringAndValue(".",                            1),
                new StringAndValue("a",                            1),
                new StringAndValue("bb",                           1),
                new StringAndValue("c",                            1),
                new StringAndValue("ddd",                          1),
                new StringAndValue("ee",                           1),
                new StringAndValue("ef",                           1),
                new StringAndValue("f",                            1),
                new StringAndValue("gg",                           1),
                new StringAndValue("h",                            1),
                new StringAndValue("iiii",                         1),
                new StringAndValue("j",                            1),
                new StringAndValue("kk",                           1),
                new StringAndValue("kl",                           1),
                new StringAndValue("kmm",                          1),
                new StringAndValue("l",                            1),
                new StringAndValue("m",                            1),
                new StringAndValue("nnnnnnnnnnnnnnnnnnnnnnnnnnnn", 1),
                new StringAndValue("o",                            1),
                new StringAndValue("pp",                           1),
                new StringAndValue("qqq",                          1),
                new StringAndValue("r",                            1),
                new StringAndValue("uar",                          1),
                new StringAndValue("uary", 1)
            };
            checkIterator(iter, data);
            // Reset, and we should get the same result.
            Logln("after iter.Reset()");
            checkIterator(iter.Reset(), data);
        }
Example #3
0
 private void checkIterator(BytesTrieEnumerator iter, StringAndValue[] data, int dataLength)
 {
     for (int i = 0; i < dataLength; ++i)
     {
         if (!iter.MoveNext())
         {
             Errln("trie iterator MoveNext()=false for item " + i + ": " + data[i].s);
             break;
         }
         BytesTrieEntry entry       = iter.Current;
         StringBuilder  bytesString = new StringBuilder();
         for (int j = 0; j < entry.BytesLength; ++j)
         {
             bytesString.Append((char)(entry[j] & 0xff));
         }
         if (!data[i].s.ContentEquals(bytesString))
         {
             Errln(String.Format("trie iterator next().getString()={0} but expected {1} for item {2:d}",
                                 bytesString, data[i].s, i));
         }
         if (entry.value != data[i].value)
         {
             Errln(String.Format("trie iterator next().GetValue()={0:d}=0x{1:x} but expected {2:d}=0x{3:x} for item {4:d}: {5}",
                                 entry.value, entry.value,
                                 data[i].value, data[i].value,
                                 i, data[i].s));
         }
     }
     if (iter.MoveNext())
     {
         Errln("trie iterator MoveNext()=true after all items");
     }
     // ICU4N specific - this test doesn't apply in .NET
     //try
     //{
     //    iter.Next();
     //    Errln("trie iterator next() did not throw NoSuchElementException after all items");
     //}
     //catch (NoSuchElementException e)
     //{
     //    // good
     //}
 }
Example #4
0
        public void Test52TruncatingIteratorFromRoot()
        {
            BytesTrie           trie = buildMonthsTrie(TrieBuilderOption.Fast);
            BytesTrieEnumerator iter = trie.GetEnumerator(4);

            // Expected data: Same as in buildMonthsTrie(), except only the first 4 characters
            // of each string, and no string duplicates from the truncation.
            StringAndValue[] data =
            {
                new StringAndValue("augu", -1),
                new StringAndValue("jan",   1),
                new StringAndValue("jan.",  1),
                new StringAndValue("jana",  1),
                new StringAndValue("janb", -1),
                new StringAndValue("janc",  1),
                new StringAndValue("jand", -1),
                new StringAndValue("jane", -1),
                new StringAndValue("janf",  1),
                new StringAndValue("jang", -1),
                new StringAndValue("janh",  1),
                new StringAndValue("jani", -1),
                new StringAndValue("janj",  1),
                new StringAndValue("jank", -1),
                new StringAndValue("janl",  1),
                new StringAndValue("janm",  1),
                new StringAndValue("jann", -1),
                new StringAndValue("jano",  1),
                new StringAndValue("janp", -1),
                new StringAndValue("janq", -1),
                new StringAndValue("janr",  1),
                new StringAndValue("janu", -1),
                new StringAndValue("july",  7),
                new StringAndValue("jun",   6),
                new StringAndValue("jun.",  6),
                new StringAndValue("june", 6)
            };
            checkIterator(iter, data);
            // Reset, and we should get the same result.
            Logln("after iter.Reset()");
            checkIterator(iter.Reset(), data);
        }
Example #5
0
        public void Test51IteratorFromLinearMatch()
        {
            BytesTrie trie = buildMonthsTrie(TrieBuilderOption.Small);

            // Go into a linear-match node.
            trie.Next('j');
            trie.Next('a');
            trie.Next('n');
            trie.Next('u');
            trie.Next('a');
            BytesTrieEnumerator iter = trie.GetEnumerator();

            // Expected data: Same as in buildMonthsTrie(), except only the suffixes
            // following "janua".
            StringAndValue[] data =
            {
                new StringAndValue("r",  1),
                new StringAndValue("ry", 1)
            };
            checkIterator(iter, data);
            // Reset, and we should get the same result.
            Logln("after iter.Reset()");
            checkIterator(iter.Reset(), data);
        }
Example #6
0
 private void checkIterator(BytesTrieEnumerator iter, StringAndValue[] data)
 {
     checkIterator(iter, data, data.Length);
 }