Beispiel #1
0
        public void DicDrivenTrieSet_AddReadOnlyExceptionTest()
        {
            var target = new DicDrivenTrieSet <char, string>(
                new[] { string.Empty },
                true,
                this.dicFactory);

            target.Add(string.Empty);
        }
Beispiel #2
0
        public void DicDrivenTrieSet_AddTest()
        {
            var values = this.GetTestValues();
            var target = new DicDrivenTrieSet <char, string>(
                values,
                false,
                this.dicFactory);

            // Tenta adicionar um item que já existe
            var additionResult = target.Add("amordaçar");

            Assert.IsFalse(additionResult);
            Assert.AreEqual(values.Length, target.Count);

            // Adiciona um novo elemento
            additionResult = target.Add("ambivalentes");
            Assert.IsTrue(additionResult);
            Assert.AreEqual(values.Length + 1, target.Count);
        }
Beispiel #3
0
        public void DicDrivenTrieSet_IteratorTest()
        {
            var target = new DicDrivenTrieSet <char, string>();

            target.Add("Isto");
            target.Add("um");
            target.Add("teste");
            target.Add("iterador");
            target.Add("associativa");

            var text     = "Isto constitui um teste ao iterador da árvore associativa.";
            var expected = new[] {
                true,
                false,
                true,
                true,
                false,
                true,
                false,
                false,
                true
            };

            #region Verifica Existência

            var iterator = target.GetIterator();
            var length   = text.Length;
            var actual   = new List <bool>();
            var state    = 0;
            var i        = -1;
            while (state != -1)
            {
                ++i;
                if (state == 0)
                {
                    if (i < length)
                    {
                        var current = text[i];
                        if (current != ' ' && current != '.')
                        {
                            iterator.Reset();
                            if (iterator.GoForward(current))
                            {
                                state = 1;
                            }
                            else
                            {
                                // Ignora a palavra.
                                actual.Add(false);
                                iterator.Reset();
                                state = 2;
                            }
                        }
                    }
                    else
                    {
                        state = -1;
                    }
                }
                else if (state == 1)
                {
                    if (i < length)
                    {
                        var current = text[i];
                        if (current == ' ' || current == '.')
                        {
                            actual.Add(true);
                            iterator.Reset();
                            state = 0;
                        }
                        else
                        {
                            if (!iterator.GoForward(current))
                            {
                                // Ignora a palavra.
                                actual.Add(false);
                                iterator.Reset();
                                state = 2;
                            }
                        }
                    }
                    else
                    {
                        actual.Add(true);
                        state = -1;
                    }
                }
                else
                {
                    if (i < length)
                    {
                        var current = text[i];
                        if (current == ' ' || current == '.')
                        {
                            state = 0;
                        }
                    }
                    else
                    {
                        state = -1;
                    }
                }
            }

            #endregion Verifica Existência

            CollectionAssert.AreEquivalent(expected, actual);
        }