Ejemplo n.º 1
0
        public void TestOfGetOnEmptyHashTable()
        {
            MinMaxHashTable<int, string> table = new MinMaxHashTable<int, string>();

            string value = table.Get(0);
            // Exception should be thrown at previous line
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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));
        }