public void OnParsing_GetWords_RemovesSpecialCharacters()
        {
            string input = "\r\n    .,;/?\"'!&*[](){}";

            WordsParser parser = new WordsParser();
            IEnumerable<string> words= parser.GetWords(input);

            Assert.AreEqual(0, words.Count());
        }
        public void OnParsing_GetWords_ConsidersHypenatedAsSingleWord()
        {
            string input = "co-operate";

            WordsParser parser = new WordsParser();
            IEnumerable<string> words = parser.GetWords(input);

            Assert.AreEqual(1, words.Count());
        }
        public void OnParsing_GetWords_RetrievesWordsFromText()
        {
            string input = "Our time in the world is a loan, we must pay it with interest.";

            WordsParser parser = new WordsParser();
            IEnumerable<string> words = parser.GetWords(input);

            Assert.AreEqual(14, words.Count());
            Assert.AreEqual("Ourtimeintheworldisaloanwemustpayitwithinterest", words.Aggregate((a, b) => a + b));
        }
        public void OnParsing_GetWords_DoesNotRemoveHypen()
        {
            string input = "\r\n    .,;/?\"'!&*[](-){}";

            WordsParser parser = new WordsParser();
            IEnumerable<string> words = parser.GetWords(input);

            Assert.AreEqual(1, words.Count());
            Assert.AreEqual(true, words.Contains("-"));
        }
        public void OnParsing_GetWords_IgnoresNewLines()
        {
            string input = @"Our time in the world is
                a loan, we must pay it with interest.
                and
                another line";

            WordsParser parser = new WordsParser();
            IEnumerable<string> words = parser.GetWords(input);

            Assert.AreEqual(17, words.Count());
            Assert.AreEqual("Ourtimeintheworldisaloanwemustpayitwithinterestandanotherline", words.Aggregate((a, b) => a + b));
        }
Example #6
0
        static void ProcessFile(string file)
        {
            Console.WriteLine(string.Format("Processing File: {0}", file));

            try
            {
                string fileContent = File.ReadAllText(file);

                WordsParser parser = new WordsParser();

                IEnumerable<string> words = parser.GetWords(fileContent);

                StandardWordTraverser traverser = new StandardWordTraverser(words);

                // Part 1
                WordsCounter counter = new WordsCounter();
                traverser.AcceptProcessor(counter);
                counter.ReportTo(Console.WriteLine);

                // Part 2
                CompositionMatcher compositonMatcher = new CompositionMatcher(words, 6);
                traverser.AcceptProcessor(compositonMatcher);
                compositonMatcher.ReportTo(Console.WriteLine);
            }
            catch (IOException ex)
            {
                Console.WriteLine("Unable to read the file.");
                Console.WriteLine(string.Format("Message: {0}", ex.Message));
                Console.WriteLine(string.Format("Details: {0}", ex.StackTrace));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Oops... Unexpected error occurred.");
                Console.WriteLine(string.Format("Message: {0}", ex.Message));
                Console.WriteLine(string.Format("Details: {0}", ex.StackTrace));
            }
        }