diff --git a/SpellChecker.Console/Program.cs b/SpellChecker.Console/Program.cs index f076301..3114147 100644 --- a/SpellChecker.Console/Program.cs +++ b/SpellChecker.Console/Program.cs @@ -3,6 +3,8 @@ namespace SpellChecker.Console { + using System.Collections.Generic; + using System.Linq; /// /// The following are the "requirements" for this project: @@ -45,13 +47,37 @@ public static void Main(string[] args) // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled + if (sentence == null) + { + return; + } + + var distinctListOfWords = sentence.Split(' ').Distinct().ToList(); // use this spellChecker to evaluate the words - var spellChecker = new Core.SpellChecker(new ISpellChecker[] + var spellChecker = new Core.SpellChecker( + new ISpellChecker[] + { + new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), + }); + + var incorrectlySpelledWords = new List(); + foreach (var word in distinctListOfWords) + { + if (spellChecker.Check(word) == false) + { + incorrectlySpelledWords.Add(word); + } + } + + if (incorrectlySpelledWords.Any()) + { + System.Console.Write("The following words are misspelled: " + string.Join(", ", incorrectlySpelledWords)); + } + else { - new MnemonicSpellCheckerIBeforeE(), - new DictionaryDotComSpellChecker(), - }); + System.Console.WriteLine("Congratulations, there were no misspellings!"); + } } }