Exemple #1
0
        public void CanAddItemToHashTable()
        {
            HashTbl <int> table = new HashTbl <int>(16);

            table.Add("Josie", 9);
            Assert.NotNull(table);
        }
Exemple #2
0
        public void FindsContainedValue()
        {
            HashTbl <int> table = new HashTbl <int>(16);

            table.Add("Josie", 9);
            table.Add("Dog", 10);
            table.Add("Cupcake", 5);

            var contains = table.Contains("Cupcake");

            Assert.True(contains);
        }
        public void CanReturnNullIfKeyDoesntExist()
        {
            HashTbl <int> table = new HashTbl <int>(16);

            table.Add("Josie", 9);
            table.Add("Dog", 10);
            table.Add("Cupcake", 5);

            var contains = table.Contains("Mango");

            Assert.False(contains);
        }
Exemple #4
0
        public void GetValue()
        {
            // arrange
            HashTbl <int> table = new HashTbl <int>(16);

            table.Add("Josie", 9);
            table.Add("Dog", 10);
            table.Add("Cupcake", 5);

            var result = table.Get("Dog");

            Assert.Equal(10, result);
        }
        public void CanHandleACollision()
        {
            // Arrange
            HashTbl <int> table = new HashTbl <int>(16);

            table.Add("Josie", 9);
            table.Add("Josie", 5);

            //  Act
            var result = table.Get("Josie");

            // Assert
            Assert.Equal(9, result);
        }
        public void CanRetrieveFromABucketWithACollision()
        {
            // Arrange
            HashTbl <int> table = new HashTbl <int>(16);

            table.Add("Josie", 9);
            table.Add("Dog", 10);
            table.Add("Josie", 5);

            //  Act
            var result = table.Get("Josie");

            // Assert
            Assert.Equal(9, result);
        }
        public void HashTblMustWork()
        {
            int n = 1000;
            RandomStringGenerator rnd = new RandomStringGenerator(true, true, true, false);

            HashTbl <int, string>    table = new HashTbl <int, string>(n);
            Dictionary <int, string> dic   = new Dictionary <int, string>();

            for (int i = 0; i < n; i++)
            {
                int    key  = i;
                string item = rnd.Generate(10);
                table.Add(key, item);
                dic.Add(key, item);
            }


            Assert.AreEqual(table.GetItem(100), dic[100]);
        }