コード例 #1
0
        public void Does_Not_Find_Nonexistant_Key_In_Bucket()
        {
            var ht = new SimpleHashTable();

            ht.Add(1, 1);

            Assert.IsFalse(ht.ContainsKey(2));
        }
コード例 #2
0
        public void Finds_Key_In_Bucket()
        {
            var ht = new SimpleHashTable();

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

            Assert.IsTrue(ht.ContainsKey(1));
        }
コード例 #3
0
        public void Does_Not_Find_Nonexistant_Key_In_Overloaded_Bucket()
        {
            //all go into same bucket
            var ht = new SimpleHashTable(1);

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

            Assert.IsFalse(ht.ContainsKey(3));
        }
コード例 #4
0
        public void Finds_Key_In_Overloaded_Bucket()
        {
            //all go into same bucket
            var ht = new SimpleHashTable(1);

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

            Assert.IsTrue(ht.ContainsKey(1));
        }
コード例 #5
0
        public static void HashTable()
        {
            SimpleHashTable <string, int> simpleHash = new SimpleHashTable <string, int>();

            simpleHash.Add("hello", 1);
            simpleHash.Add("world", 2);
            simpleHash.Add("this", 3);
            simpleHash.Add("is", 4);

            Assert.That(simpleHash.ContainsKey("world") == true);
            Assert.That(simpleHash.ContainsKey("nohash") == false);

            Assert.That(simpleHash["is"] == 4);
            Assert.That(simpleHash["hello"] == 1);
            simpleHash["hello"] = 10;

            Assert.That(simpleHash["hello"] == 10);
            simpleHash.Remove("this");
            Assert.That(simpleHash.ContainsKey("this") == false);
        }
コード例 #6
0
        public void Rejects_Null_Key()
        {
            var ht    = new SimpleHashTable();
            var valid = true;

            try
            {
                ht.ContainsKey(null);
            }
            catch (ArgumentNullException)
            {
                valid = false;
            }

            Assert.IsFalse(valid);
        }