Beispiel #1
0
        public void Container_SeparateChaining2ChoiceHashTable()
        {
            // Arrange
            SeparateChaining2ChoiceHashTable <int, string> chaining2ChoiceHashTable = new SeparateChaining2ChoiceHashTable <int, string>();

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

            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);
                }
            }
        }
Beispiel #2
0
        public void SeparateChaining2ChoiceHashTable_GetAddRemove()
        {
            // Arrange
            var hashTable = new SeparateChaining2ChoiceHashTable <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));
                }
            }
        }
Beispiel #3
0
        public void Container_GetSortedValuesNumber()
        {
            // Arrange
            SeparateChaining2ChoiceHashTable <int, int> chaining2ChoiceHashTable = new SeparateChaining2ChoiceHashTable <int, int>();
            // Act
            Random random = new Random();

            for (int i = 0; i < 1000; i++)
            {
                var number = random.Next(0, 10000);
                chaining2ChoiceHashTable.Add(number, number);
            }
            Container <int, int> container = new Container <int, int>(chaining2ChoiceHashTable);

            // Assert
            int[] sorted  = container.GetSortedValuesNumber(50);
            int   prevNum = -10001;

            foreach (var num in sorted)
            {
                Assert.IsTrue(num >= prevNum);
            }
        }