static void Main() { string[] input = { "Apple", "Orange", "Pear", "Apple" }; ItemCounter itemCounter = new ItemCounter(input); foreach (var item in itemCounter.distinctItems) { Console.WriteLine("{0}:{1}", item.Key, item.Value); } Console.WriteLine("Total distinct items: {0}", itemCounter.DistinctItems); Console.WriteLine("\"Apple\" instances: {0}", itemCounter.GetCount("Apple")); Console.WriteLine("\"Orange\" instances: {0}", itemCounter.GetCount("Orange")); Console.WriteLine("\"Blank\" instances: {0}", itemCounter.GetCount("Blank")); Console.WriteLine("\"null\" instances: {0}", itemCounter.GetCount(null)); Console.WriteLine("Contains key \"Lemon\": {0}", itemCounter.HasItem("Lemon")); Console.WriteLine("Contains key \"null\": {0}", itemCounter.HasItem(null)); Console.ReadLine(); }
public void GetCount_WhenSpecifyingNullItem_ThrowsException() { // ARRANGE var items = new[] { "Apple", "Apple" }; var counter = new ItemCounter <string>(items); // ACT TestDelegate testDelegate = delegate { counter.GetCount(null); }; // ASSERT Assert.Throws <ArgumentNullException>(testDelegate); }
public void GetCount_WhenSpecifyingNonExistingItem_ThrowsException() { // ARRANGE var items = new[] { "Apple", "Apple" }; var counter = new ItemCounter <string>(items); // ACT TestDelegate testDelegate = delegate { counter.GetCount("Pear"); }; // ASSERT Assert.Throws <InvalidOperationException>(testDelegate); }
public void GetCount_AfterConstructionWithTwoDifferentItemsArray_IsOne() { // ARRANGE var item1 = "Apple"; var item2 = "Banana"; var items = new[] { item1, item2 }; var counter = new ItemCounter <string>(items); // ACT var actualCount = counter.GetCount(item1); // ASSERT Assert.AreEqual(1, actualCount); }
public void GetCount_AfterConstructionWithTwoSameItemsArray_IsTwo() { // ARRANGE var item1 = "Apple"; var item2 = item1; var items = new[] { item1, item2 }; var counter = new ItemCounter <string>(items); // ACT var actualCount = counter.GetCount(item1); // ASSERT Assert.AreEqual(2, actualCount); }