public void QuadraticHashTableOverloadingContainsTest()
        {
            IHashTable hashTable = new QuadraticHashTable(2);

            Assert.IsTrue(hashTable.Add(3));
            Assert.IsTrue(hashTable.Add(3));
            Assert.IsFalse(hashTable.Add(6),
                           "quadritic hash table should not be able to add element");

            Assert.IsFalse(hashTable.Contains(6),
                           "quadritic hash table should not contains not added element");
        }
        public void QuadraticHashTableOverloadingAddingTest()
        {
            IHashTable hashTable = new QuadraticHashTable(2);

            Assert.IsTrue(hashTable.Add(3));
            Assert.IsTrue(hashTable.Add(3));
            Assert.IsFalse(hashTable.Add(3),
                           "quadritic hash table should not be able to add element");

            Assert.IsTrue(hashTable.Count() == 2,
                          "quadritic hash table count should be 2 after not-successfull adding");
        }
Exemple #3
0
        public void Container_QuadraticHashTable()
        {
            // Arrange
            QuadraticHashTable <int, string> quadraticHashTable = new QuadraticHashTable <int, string>();

            // Act
            for (int i = 0; i < 100; i++)
            {
                quadraticHashTable.Add(i, i.ToString());
            }
            Container <int, string> container = new Container <int, string>(quadraticHashTable);

            container.RemoveByKey(20);
            container.RemoveByKey(80);
            // Assert
            for (int i = 0; i < 100; i++)
            {
                if (i != 20 && i != 80)
                {
                    Assert.AreEqual(container.GetValue(i), i.ToString());
                }
                else
                {
                    Assert.AreEqual(container.GetValue(i), default);
                }
            }
        }
Exemple #4
0
        public void QuadraticHashTable_GetAddRemove()
        {
            // Arrange
            var hashTable = new QuadraticHashTable <int, string>();

            // Act
            for (int i = 0; i < 100; i++)
            {
                hashTable.Add(i, i.ToString());
            }
            hashTable.Remove(50);
            hashTable.Remove(40);
            // Assert
            for (int i = 0; i < 100; i++)
            {
                if (i != 40 && i != 50)
                {
                    Assert.AreEqual(i.ToString(), hashTable.Get(i));
                }
                else
                {
                    Assert.AreEqual(null, hashTable.Get(i));
                }
            }
        }
        public void QuadraticHashTableOverloadingRemoveTest()
        {
            IHashTable hashTable = new QuadraticHashTable(2);

            Assert.IsTrue(hashTable.Add(3));
            Assert.IsTrue(hashTable.Add(3));
            Assert.IsFalse(hashTable.Add(6),
                           "quadritic hash table should not be able to add element");

            Assert.IsFalse(hashTable.Remove(6),
                           "quadritic hash table should not be able to remove not-added element");

            Assert.IsTrue(hashTable.Remove(3),
                          "quadritic hash table should be able to remove existed element");

            Assert.IsTrue(hashTable.Add(3),
                          "quadritic hash table should be able to add element again");

            Assert.IsTrue(hashTable.Count() == 2,
                          "quadritic hash table has 2 elements after testing");
        }