static void Main(string[] args) { if (args.Length == 1) { var filePath = args[0]; if (File.Exists(filePath)) { var lines = File.ReadAllText(filePath); var myCounter = new CommonWordCounter(lines); Console.WriteLine("There are " + myCounter.WordDictionary.Count + " unique words in the file " + filePath); var listOfWords = myCounter.WordDictionary.ToList().Select(x => new { Count = x.Value, Word = x.Key }).ToList(); var sortedList = listOfWords.OrderByDescending(x => x.Count).ToList(); } else { Console.WriteLine("File does not exist at path " + filePath); } } else { Console.WriteLine("Not enough arguments, or too many."); } }
static void Main(string[] args) { if (args.Length == 1) { var filePath = args[0]; if (File.Exists(filePath)) { var lines = File.ReadAllText(filePath); var myCounter = new CommonWordCounter(lines); Console.WriteLine("There are " + myCounter.WordDictionary.Count + " unique words in the file " + filePath); var listOfWords = myCounter.WordDictionary.ToList().Select(x => new { Count = x.Value, Word = x.Key }).ToList(); var sortedList = listOfWords.OrderByDescending(x => x.Count).ToList(); } else { Console.WriteLine("File does not exist at path " + filePath); } } else { Console.WriteLine("Not enough arguments, or too many."); } }
public void Prop_WordDictionary_ReturnsCorrectCount() { var target = new CommonWordCounter(FiveWordsAllSame); Assert.AreEqual(1, target.WordDictionary.Count); Assert.AreEqual(5, target.WordDictionary["the"]); target = new CommonWordCounter(FiveWordsAllDifferent); Assert.AreEqual(5, target.WordDictionary.Count); Assert.AreEqual(1, target.WordDictionary["test"]); Assert.AreEqual(1, target.WordDictionary["apple"]); Assert.AreEqual(1, target.WordDictionary["board"]); Assert.AreEqual(1, target.WordDictionary["maybe"]); Assert.AreEqual(1, target.WordDictionary["hello"]); target = new CommonWordCounter(SimplePunctuationTest); Assert.AreEqual(1, target.WordDictionary.Count); Assert.AreEqual(5, target.WordDictionary["test"]); target = new CommonWordCounter(FullTest); }
public void Ctor_NullArgumentFails() { var target = new CommonWordCounter(null); }