Beispiel #1
0
        public void Test37LargeTrie()
        {
            CharsTrie trie = buildLargeTrie(1111);
            Generator gen  = new Generator();

            while (gen.countUniqueFirstChars() < 1111)
            {
                ICharSequence x     = gen.GetString();
                int           value = gen.GetValue();
                int           index;
                if (x.Length == 0)
                {
                    index = 0;
                }
                else
                {
                    if (trie.First(x[0]) == Result.NoMatch)
                    {
                        Errln(String.Format("first(first char U+{0:x4})=BytesTrie.Result.NO_MATCH for string {1}\n",
                                            char.GetNumericValue(x[0]), gen.GetIndex()));
                        break;
                    }
                    index = 1;
                }
                Result result = trie.Next(x, index, x.Length);
                if (!result.HasValue() || result != trie.Current || value != trie.GetValue())
                {
                    Errln(String.Format("next(" + Prettify(x) + ")!=hasValue or " +
                                        "next()!=current() or getValue() wrong " +
                                        "for string " + gen.GetIndex()));
                    break;
                }
                gen.Next();
            }
        }
Beispiel #2
0
        public void Test40GetUniqueValue()
        {
            CharsTrie trie = buildMonthsTrie(TrieBuilderOption.Fast);
            long      uniqueValue;

            if ((uniqueValue = trie.GetUniqueValue()) != 0)
            {
                Errln("unique value at root");
            }
            trie.Next('j');
            trie.Next('a');
            trie.Next('n');
            // getUniqueValue() directly after next()
            if ((uniqueValue = trie.GetUniqueValue()) != ((1 << 1) | 1))
            {
                Errln("not unique value 1 after \"jan\": instead " + uniqueValue);
            }
            trie.First('j');
            trie.Next('u');
            if ((uniqueValue = trie.GetUniqueValue()) != 0)
            {
                Errln("unique value after \"ju\"");
            }
            if (trie.Next('n') != Result.IntermediateValue || 6 != trie.GetValue())
            {
                Errln("not normal value 6 after \"jun\"");
            }
            // getUniqueValue() after getValue()
            if ((uniqueValue = trie.GetUniqueValue()) != ((6 << 1) | 1))
            {
                Errln("not unique value 6 after \"jun\"");
            }
            // getUniqueValue() from within a linear-match node
            trie.First('a');
            trie.Next('u');
            if ((uniqueValue = trie.GetUniqueValue()) != ((8 << 1) | 1))
            {
                Errln("not unique value 8 after \"au\"");
            }
        }
Beispiel #3
0
        private void checkFirst(CharsTrie trie, StringAndValue[] data, int dataLength)
        {
            for (int i = 0; i < dataLength; ++i)
            {
                if (data[i].s.Length == 0)
                {
                    continue;  // skip empty string
                }
                String expectedString = data[i].s;
                int    c           = expectedString[0];
                int    nextCp      = expectedString.Length > 1 ? expectedString[1] : 0;
                Result firstResult = trie.First(c);
                int    firstValue  = firstResult.HasValue() ? trie.GetValue() : -1;
                Result nextResult  = trie.Next(nextCp);
                if (firstResult != trie.Reset().Next(c) ||
                    firstResult != trie.Current ||
                    firstValue != (firstResult.HasValue() ? trie.GetValue() : -1) ||
                    nextResult != trie.Next(nextCp)
                    )
                {
                    Errln(String.Format("trie.first(U+{0:X4})!=trie.Reset().Next(same) for {1}",
                                        c, data[i].s));
                }
                c = expectedString.CodePointAt(0);
                int cLength = Character.CharCount(c);
                nextCp = expectedString.Length > cLength?expectedString.CodePointAt(cLength) : 0;

                firstResult = trie.FirstForCodePoint(c);
                firstValue  = firstResult.HasValue() ? trie.GetValue() : -1;
                nextResult  = trie.NextForCodePoint(nextCp);
                if (firstResult != trie.Reset().NextForCodePoint(c) ||
                    firstResult != trie.Current ||
                    firstValue != (firstResult.HasValue() ? trie.GetValue() : -1) ||
                    nextResult != trie.NextForCodePoint(nextCp)
                    )
                {
                    Errln(String.Format("trie.firstForCodePoint(U+{0:X4})!=trie.Reset().NextForCodePoint(same) for {1}",
                                        c, data[i].s));
                }
            }
            trie.Reset();
        }