public void Handles_Collisions_Expand()
        {
            var ht = new ComplexHashTable(3);

            ht.Add(0, 1);
            ht.Add(0f, 2);
        }
        public void Clear_Removes_Items()
        {
            var valid = false;
            var ht    = new ComplexHashTable(1);

            ht.Add(1, 1);
            ht.Add(2, 2);
            ht.Clear();

            try
            {
                ht.Get(1);
            }
            catch (ArgumentException)
            {
                valid = true;
            }

            Assert.IsTrue(valid);

            valid = false;
            try
            {
                ht.Get(2);
            }
            catch (ArgumentException)
            {
                valid = true;
            }

            Assert.IsTrue(valid);
        }
        public void Finds_Key_In_Bucket()
        {
            var ht = new ComplexHashTable();

            ht.Add(1, 1);
            ht.Add(2, 2);

            Assert.IsTrue(ht.ContainsKey(1));
        }
        public void Does_Expand()
        {
            var ht = new ComplexHashTable(3);

            ht.Add(1, 1);
            ht.Add(2, 1);
            ht.Add(3, 1);
            ht.Add(4, 1);
        }
Exemplo n.º 5
0
        public void Finds_Correct_Value_In_Collision()
        {
            var ht = new ComplexHashTable();

            ht.Add(0, 1);
            ht.Add(0f, 2);

            Assert.AreEqual(ht.Get(0f), 2);
        }
Exemplo n.º 6
0
        public void Finds_Correct_Value()
        {
            var ht = new ComplexHashTable();

            ht.Add(1, 1);
            ht.Add(50, 50);

            Assert.AreEqual(ht.Get(1), 1);
        }
        public void Does_Not_Find_Nonexistant_Key_In_Overloaded_Bucket()
        {
            //all go into same bucket
            var ht = new ComplexHashTable(1);

            ht.Add(0, 1);
            ht.Add(0f, 2);

            Assert.IsFalse(ht.ContainsKey(0m));
        }
        public void Finds_Key_In_Overloaded_Bucket()
        {
            //all go into same bucket
            var ht = new ComplexHashTable(1);

            ht.Add(1, 1);
            ht.Add(2, 2);

            Assert.IsTrue(ht.ContainsKey(1));
        }
        public void Leaves_Correct_Value_In_Bucket_After_Remove()
        {
            var ht = new ComplexHashTable();

            ht.Add(1, 1);
            ht.Add(50, 50);
            ht.Remove(50);

            Assert.AreEqual(ht.Get(1), 1);
        }
        public void Leaves_Correct_Value_In_Overloaded_Bucket_After_Remove()
        {
            var ht = new ComplexHashTable(1);

            ht.Add(1, 1);
            ht.Add(2, 2);
            ht.Remove(1);

            Assert.AreEqual(ht.Get(2), 2);
        }
        public void Does_Not_Find_Nonexistant_Key_In_Bucket()
        {
            var ht = new ComplexHashTable();

            ht.Add(1, 1);

            Assert.IsFalse(ht.ContainsKey(2));
        }
        public void Rejects_Duplicate_Keys()
        {
            var ht = new ComplexHashTable();

            ht.Add(1, 1);

            var valid = true;

            try
            {
                ht.Add(1, 1);
            }
            catch (ArgumentException)
            {
                valid = false;
            }

            Assert.IsFalse(valid);
        }
        public void Removes_Correct_Value_In_Bucket()
        {
            var valid = false;
            var ht    = new ComplexHashTable();

            ht.Add(1, 1);
            ht.Add(50, 50);
            ht.Remove(50);

            try
            {
                ht.Get(50);
            }
            catch (ArgumentException)
            {
                valid = true;
            }
            Assert.IsTrue(valid);
        }
        public void Rejects_Missing_Key_In_Overloaded_Bucket()
        {
            //all go into same bucket
            var ht = new ComplexHashTable(1);

            ht.Add(1, 1);
            var valid = true;

            try
            {
                ht.Remove(2);
            }
            catch (ArgumentException)
            {
                valid = false;
            }

            Assert.IsFalse(valid);
        }
Exemplo n.º 15
0
        public void Rejects_Missing_Key_In_Collision()
        {
            //all go into same bucket
            var ht = new ComplexHashTable(1);

            ht.Add(0, 1);
            var valid = true;

            try
            {
                ht.Get(0f);
            }
            catch (ArgumentException)
            {
                valid = false;
            }

            Assert.IsFalse(valid);
        }