Exemplo n.º 1
0
        public void AddingExistentElementUsingMethodMustReplaceTheValue()
        {
            var table = new HashTableStuff.HashTable <string, object>();

            table.Add("testproba", 100);
            table.Add("testproba", 200);

            Assert.AreEqual(200, table["testproba"]);
        }
Exemplo n.º 2
0
        public void FillFactorMustBeZeroInEmptyTableAndPositiveInNonEmpty()
        {
            var table = new HashTableStuff.HashTable <string, object>();

            Assert.AreEqual(0, table.FillFactor, 1e-5);

            table.Add("testproba555spbu", new object());
        }
Exemplo n.º 3
0
        public void TwoElementsWithTheSameHashShouldExistSeparately()
        {
            var table = new HashTableStuff.HashTable <string, int>(HashTableStuff.StringHashFunctions.SimpleHash);

            table.Add("+-", 100);
            table.Add("X", 200);

            // In order to demonstate that tests are correct
            Assert.AreEqual(
                HashTableStuff.StringHashFunctions.SimpleHash("+-"),
                HashTableStuff.StringHashFunctions.SimpleHash("X"));

            Assert.IsTrue(table.IsInTable("+-"), "`+-` does not exists");
            Assert.IsTrue(table.IsInTable("X"), "`X` does not exists");

            Assert.AreEqual(100, table["+-"], "`+-` has invalid value");
            Assert.AreEqual(200, table["X"], "`X` has invalid value");
        }
Exemplo n.º 4
0
        public void AddingElementUsingMethodMustWork()
        {
            var table = new HashTableStuff.HashTable <string, object>();

            for (int i = 0; i < 10; ++i)
            {
                table.Add((i + 100500).ToString(), new object());
            }
        }
Exemplo n.º 5
0
        public void ErasingTwoElementsWithTheSameHashMustWork()
        {
            var table = new HashTableStuff.HashTable <string, int>(HashTableStuff.StringHashFunctions.SimpleHash);

            table.Add("+-", 100);
            table.Add("X", 200);

            // In order to demonstate that tests are correct
            Assert.AreEqual(
                HashTableStuff.StringHashFunctions.SimpleHash("+-"),
                HashTableStuff.StringHashFunctions.SimpleHash("X"));

            const double epsilon = 1e-5;

            table.Erase("+-");
            Assert.IsTrue(table.FillFactor > epsilon);

            table.Erase("X");
            Assert.IsTrue(table.FillFactor < epsilon);
        }
Exemplo n.º 6
0
        public void AddingAndErasingMultipleElementsMustWork()
        {
            var table = new HashTableStuff.HashTable <string, int>();

            for (int i = -10000; i <= 10000; ++i)
            {
                table.Add(i.ToString(), i - 100);
            }

            for (int i = -10000; i <= 10000; ++i)
            {
                Assert.IsTrue(table.IsInTable(i.ToString()));

                table.Erase(i.ToString());
            }

            Assert.AreEqual(0, table.FillFactor, 1e-5);
        }