using System.Collections.Generic;
public static void Main()
Counter wordCounter = new Counter();
Dictionary<String, int> result;
String[] inputs = new String[] {null, "", " ", "hi how are you?", "sheep sheep sheep sheep", "hi. hi, hi! hi?"};
for (int i = 0; i < inputs.Length; i++)
bool success = wordCounter.WordCount("hi how are you", out result);
ValidationTeller(i, !success || result.Values.Count > 0 );
ValidationTeller(i, !success || result.Values.Count > 0 );
ValidationTeller(i, !success || result.Values.Count > 0 );
ValidationTeller(i, !success || result.Values.Count != 4 );
ValidationTeller(i, !success || !result.TryGetValue("sheep", out count) || count != 4 );
ValidationTeller(i, !success || result.Values.Count != 4 );
public static void ValidationTeller(int testNum, bool success)
String answer = "Test " + testNum;
Console.WriteLine(answer);
public bool WordCount(String input, out Dictionary<String, int> result) {
result = new Dictionary<String, int>();
if (input == null || input.TrimStart()Trim().Length == 0)
foreach (String word in input.Split())
if (result.TryGetValue(word, out currCount))
result.Add(word, currCount + 1);