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(); }
public void Should_Split_Words_Ignoring_Punctuation() { // Arrange var text = ". , ( ) ! : ; ' ` ... ,,,, \n\n \r\n ? "; var wordSplitter = new WordSplitter(); var expectedLength = 0; // Act var results = wordSplitter.SplitWordsAndSort(text); // Assert Assert.AreEqual(expectedLength, results.Length); }
public void Should_Split_Words() { // Arrange var text = "This is some text, with punctuation!\n It also has new lines etc. it also has this twice in different case."; var wordSplitter = new WordSplitter(); var expectedLength = 20; // Act var results = wordSplitter.SplitWordsAndSort(text); // Assert Assert.AreEqual(expectedLength, results.Length); }