Exemplo n.º 1
0
    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();
    }
Exemplo n.º 2
0
        public void HasItem_WhenItemExists_ReturnsTrue()
        {
            // ARRANGE
            var item    = "Apple";
            var items   = new[] { item };
            var counter = new ItemCounter <string>(items);

            // ACT
            var actual = counter.HasItem(item);

            // ASSERT
            Assert.IsTrue(actual);
        }
Exemplo n.º 3
0
        public void HasItem_WhenItemDoesNotExist_ReturnsFalse()
        {
            // ARRANGE
            var item1   = "Apple";
            var item2   = "Pear";
            var items   = new[] { item1 };
            var counter = new ItemCounter <string>(items);

            // ACT
            var actual = counter.HasItem(item2);

            // ASSERT
            Assert.IsFalse(actual);
        }