コード例 #1
0
        public void VerifyPartialRandomInvalidWords()
        {
            SuffixTree tree = new SuffixTree(theString);

            tree.BuildTree();

            Random random = new Random((int)DateTime.Now.Ticks);

            foreach (string individualString in individualStrings)
            {
                StringBuilder builder = new StringBuilder(individualString);
                //this will inject random characters into valid words
                for (int j = random.Next(individualString.Length - 2); j < random.Next(individualString.Length); j++)
                {
                    builder.Insert(j, random.Next('a', 'z'));
                }
                string builtString = builder.ToString();
                string message     = "Corrupting: " + individualString + " as " + builtString;
                //I originally checked to see if builder is in individualStrings, however with such a large
                //data set it took way too long to execute. There is a risk that a random string of 5 to 15
                //characters IS in the word list!
                if (!individualStrings.Contains(builtString))
                {
                    Assert.IsTrue(!tree.Search(builtString), message);
                }
            }
        }
コード例 #2
0
        public void VerifyValidWords()
        {
            int        count = 0;
            SuffixTree tree  = new SuffixTree(theString);

            tree.BuildTree();
            Stopwatch timer = Stopwatch.StartNew();

            foreach (string individualString in individualStrings)
            {
                Assert.IsTrue(tree.Search(individualString));
                count++;
            }
            timer.Stop();
            Console.WriteLine(count + " words processed in " + timer.ElapsedMilliseconds + " miliseconds.");
        }
コード例 #3
0
        private void TextBox_TextChanged(object sender, EventArgs e)
        {
            var count = 0;

            if (this._suffixTree is null)
            {
                return;
            }
            _searchResults.Clear();
            this._resultTextBox.Text = "";

            if (!string.IsNullOrWhiteSpace(_textBox.Text))
            {
                this._searchResults = _suffixTree.Search(_textBox.Text);
            }

            foreach (var searchResult in _searchResults)
            {
                this._resultTextBox.Text += $"[{++count}] {searchResult}\r\n";
            }
        }
コード例 #4
0
        public void VerifyRandomInvalidWords()
        {
            SuffixTree tree = new SuffixTree(theString);

            tree.BuildTree();

            Random random = new Random((int)DateTime.Now.Ticks);

            for (int i = 0; i < individualStrings.Count; i++)
            {
                StringBuilder builder = new StringBuilder();
                for (int j = 5; j < random.Next(15); j++)
                {
                    builder.Append(random.Next('a', 'z'));
                }
                string builtString = builder.ToString();
                string message     = "Random String " + builtString + " was found!";

                //I originally checked to see if builder is in individualStrings, however with such a large
                //data set it took way too long to execute. There is a risk that a random string of 5 to 15
                //characters IS in the word list!
                Assert.IsTrue(!tree.Search(builtString));
            }
        }