コード例 #1
0
        public void Contains()
        {
            string validFile   = @"..\..\Data\ValidWords.txt";
            string invalidFile = @"..\..\Data\SuggestionTest.txt";

            // open file
            FileStream   fs = new FileStream(validFile, FileMode.Open, FileAccess.Read, FileShare.Read);
            StreamReader sr = new StreamReader(fs, Encoding.UTF7);

            _timer.StartTimer();

            // read line by line
            while (sr.Peek() >= 0)
            {
                string tempLine = sr.ReadLine().Trim();
                if (tempLine.Length > 0)
                {
                    if (tempLine.IndexOf(' ') > 0)
                    {
                        tempLine = tempLine.Substring(0, tempLine.IndexOf(' '));
                    }

                    if (!_WordDictionary.Contains(tempLine))
                    {
                        Assertion.Fail(string.Format("Did not find word: {0}", tempLine));
                    }
                }
            }
            float checkTime = _timer.StopTimer();

            Console.WriteLine("Valid words check time:" + checkTime.ToString());

            sr.Close();
            fs.Close();


            // open file
            fs = new FileStream(invalidFile, FileMode.Open, FileAccess.Read, FileShare.Read);
            sr = new StreamReader(fs, Encoding.UTF7);

            _timer.StartTimer();
            // read line by line
            while (sr.Peek() >= 0)
            {
                string tempLine = sr.ReadLine().Trim();
                if (tempLine.Length > 0)
                {
                    if (tempLine.IndexOf(' ') > 0)
                    {
                        tempLine = tempLine.Substring(0, tempLine.IndexOf(' '));
                    }

                    if (_WordDictionary.Contains(tempLine))
                    {
                        Assertion.Fail(string.Format("Word found that should not be: {0}", tempLine));
                    }
                }
            }
            float invalidTime = _timer.StopTimer();

            Console.WriteLine("Invalid words check time:" + invalidTime.ToString());

            sr.Close();
            fs.Close();
        }
コード例 #2
0
ファイル: DictionaryTest.cs プロジェクト: AiimiLtd/NetSpell
        public void Contains()
        {
            var validFile = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Data", "ValidWords.txt");
            var invalidFile = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Data", "SuggestionTest.txt");

            // open file
            FileStream   fs = new FileStream(validFile, FileMode.Open, FileAccess.Read, FileShare.Read);
            StreamReader sr = new StreamReader(fs, Encoding.UTF7);

            _timer.StartTimer();

            // read line by line
            while (sr.Peek() >= 0)
            {
                string tempLine = sr.ReadLine().Trim();
                if (tempLine.Length > 0)
                {
                    if (tempLine.IndexOf(' ') > 0)
                    {
                        tempLine = tempLine.Substring(0, tempLine.IndexOf(' '));
                    }

                    if (!_WordDictionary.Contains(tempLine))
                    {
                        Console.WriteLine(string.Format("Did not find word: {0}", tempLine));
                    }
                }
            }
            float checkTime = _timer.StopTimer();

            Console.WriteLine("Valid words check time:" + checkTime.ToString());

            sr.Close();
            fs.Close();


            // open file
            fs = new FileStream(invalidFile, FileMode.Open, FileAccess.Read, FileShare.Read);
            sr = new StreamReader(fs, Encoding.UTF7);

            _timer.StartTimer();
            // read line by line
            while (sr.Peek() >= 0)
            {
                string tempLine = sr.ReadLine().Trim();
                if (tempLine.Length > 0)
                {
                    if (tempLine.IndexOf(' ') > 0)
                    {
                        tempLine = tempLine.Substring(0, tempLine.IndexOf(' '));
                    }

                    if (_WordDictionary.Contains(tempLine))
                    {
                        Console.WriteLine(string.Format("Word found that should not be: {0}", tempLine));
                    }
                }
            }
            float invalidTime = _timer.StopTimer();

            Console.WriteLine("Invalid words check time:" + invalidTime.ToString());

            sr.Close();
            fs.Close();
        }