public void TestOfAddingDuplicicKey()
        {
            MinMaxHashTable<int, string> table = new MinMaxHashTable<int, string>();

            table.Add(1, "one");
            table.Add(1, "two");
            // Exception should be thrown at previous line
        }
        public void TestOfNotEmptyHashTableMinMaxValues()
        {
            MinMaxHashTable<int, string> table = new MinMaxHashTable<int, string>();

            table.Add(-1, "one");
            table.Add(2, "two");
            table.Add(-3, "three");

            Assert.AreEqual(-3, table.Minimum);
            Assert.AreEqual(2, table.Maximum);
        }
        public void TestOfRemovingNonExistentElementFromHashTable()
        {
            MinMaxHashTable<int, string> table = new MinMaxHashTable<int, string>();

            table.Add(1, "one");
            table.Add(2, "two");
            table.Add(3, "three");


            var value = table.Remove(20);
            // Exception should be thrown at previous line
        }
        public void TestSimpleNumericRangeUsingIndexer()
        {
            MinMaxHashTable<int, string> table = new MinMaxHashTable<int, string>();

            const int elements = 10;
            for (int i = 0; i < elements; i++)
            {
                table.Add(i, i.ToString());
            }


            var range = table[2, 4];


            int[] remaining = new int[] { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 };

            foreach (var item in range)
            {
                if (remaining[item.Key] <= 0)
                {
                    Assert.Fail("Unexpected element in range query");
                }

                remaining[item.Key]--;
            }

            foreach (var item in remaining)
            {
                if (item > 0)
                {
                    Assert.Fail("Some elements weren't read from range");
                }
            }
        }
        public void TestOfAddingMultipleDistinctElementToHashTable()
        {
            MinMaxHashTable<int, string> table = new MinMaxHashTable<int, string>();

            table.Add(1, "one");
            table.Add(2, "two");
            table.Add(3, "three");

            Assert.IsTrue(table.Contains(1));
            Assert.AreEqual("one", table.Get(1));

            Assert.IsTrue(table.Contains(2));
            Assert.AreEqual("two", table.Get(2));

            Assert.IsTrue(table.Contains(3));
            Assert.AreEqual("three", table.Get(3));

            Assert.AreEqual(3, table.Count);
        }
        public void TestOfAddingSingleElementToHashTable()
        {
            MinMaxHashTable<int, string> table = new MinMaxHashTable<int, string>();

            table.Add(1, "one");

            Assert.IsTrue(table.Contains(1));
            Assert.AreEqual("one", table.Get(1));
            Assert.AreEqual(1, table.Count);
        }
        public void TestOfRemovingElementFromHashTable()
        {
            MinMaxHashTable<int, string> table = new MinMaxHashTable<int, string>();

            table.Add(1, "one");
            table.Add(2, "two");
            table.Add(3, "three");


            var value = table.Remove(2);


            Assert.AreEqual("two", value);

            Assert.IsTrue(table.Contains(1));
            Assert.AreEqual("one", table.Get(1));

            Assert.IsFalse(table.Contains(2));

            Assert.IsTrue(table.Contains(3));
            Assert.AreEqual("three", table.Get(3));

            Assert.AreEqual(2, table.Count);
        }
        public void TestSimpleNumericSortedRange()
        {
            MinMaxHashTable<int, string> table = new MinMaxHashTable<int, string>();

            const int elements = 100;
            for (int i = 0; i < elements; i++)
            {
                int keyvalue = i - 50;
                table.Add(keyvalue, keyvalue.ToString());
            }


            var range = table.SortedRange(13, 17).Select(kv => kv.Key);


            CollectionAssert.AreEqual(
                new List<int>() { 13, 14, 15, 16, 17 },
                range.ToList());
        }
        public void TestOfAddingManyDistinctElementToHashTable()
        {
            MinMaxHashTable<int, string> table = new MinMaxHashTable<int, string>(capacity: 16384);

            const int elements = 1000000;
            for (int i = 0; i < elements; i++)
            {
                table.Add(i, i.ToString());
            }

            Assert.AreEqual(elements, table.Count);

            for (int i = 0; i < elements; i++)
            {
                Assert.IsTrue(table.Contains(i));
                Assert.AreEqual(i.ToString(), table.Get(i));
            }

            Assert.IsFalse(table.Contains(-1));
            Assert.IsFalse(table.Contains(elements));
        }