Exemplo n.º 1
0
        public void Should_Throw_ArgumentNullException_With_Null_Argument()
        {
            // Arrange
            string[] arrayOfWords = null;
            var wordFilter = new WordFilter();

            // Act
            var results = wordFilter.FilterWords(arrayOfWords);

            // Assert
            // should throw
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                if (string.IsNullOrEmpty(_fileInputPath.Trim()))
                {
                    throw new ConfigurationErrorsException("Please specify the path to the file input using the FileInputPath in the configuration file.");
                }

                if (!File.Exists(_fileInputPath))
                {
                    throw new FileNotFoundException(string.Format("Could not find file at path '{0}'", _fileInputPath));
                }

                // StreamReader.ReadToEnd is possibly more efficient, but this is only a small text file
                string fileText = File.ReadAllText(_fileInputPath);

                // Split the words from the file into a new string array,
                var wordSplitter = new WordSplitter();
                string[] allWords = wordSplitter.SplitWordsAndSort(fileText);

                // Get the counted words
                var wordCounter = new WordCounter();
                List<WordCountResult> countedWords = wordCounter.CountWords(allWords);

                // show the report on screen
                ShowWordCountReport(countedWords);

                Console.WriteLine();

                // Apply the step-two filter

                // we only need the unique words and the count, so map them
                // using a linq Select() projection
                string[] uniqueWords = countedWords.Select(s => s.Word).ToArray();

                // Get a string of words that match the filter
                var wordFilter = new WordFilter();
                string filteredWords = wordFilter.FilterWords(uniqueWords);

                Console.WriteLine("Words matching the filter:");
                Console.WriteLine(filteredWords);
            }
            catch (Exception ex)
            {
                LogErrorToConsole(ex.Message);
            }

            Console.Write("\nFinished. Press any key to quit...");
            Console.Read();
        }
Exemplo n.º 3
0
        public void Should_Filter_Words()
        {
            // Arrange
            var arrayOfWords = new[] { "al", "albums", "aver", "bar", "barely", "be", "befoul", "bums", "by", "cat", "con", "convex", "ely", "foul", "here", "hereby", "jig", "jigsaw", "or", "saw", "tail", "tailor", "vex", "we", "weaver" };
            var wordFilter = new WordFilter();

            var expectedResult = "albums, barely, befoul, convex, hereby, jigsaw, tailor, weaver";

            // Act
            var result = wordFilter.FilterWords(arrayOfWords);

            // Assert
            Assert.AreEqual(expectedResult, result);
        }