Esempio n. 1
0
        public void ConstructorTest()
        {
            var set = UnsafeHashSet.Allocate <int>(10);

            Assert.AreEqual(0, UnsafeHashSet.GetCount(set));
            // Next expected prime is 17
            Assert.AreEqual(17, UnsafeHashSet.GetCapacity(set));

            UnsafeHashSet.Free(set);
        }
Esempio n. 2
0
        public void AddDuplicateTest()
        {
            var set = UnsafeHashSet.Allocate <int>(3);

            Assert.IsTrue(UnsafeHashSet.Add(set, 5));
            Assert.IsTrue(UnsafeHashSet.Add(set, 8));
            Assert.IsTrue(UnsafeHashSet.Add(set, 9));
            Assert.IsFalse(UnsafeHashSet.Add(set, 5));

            Assert.AreEqual(3, UnsafeHashSet.GetCapacity(set));

            UnsafeHashSet.Free(set);
        }
Esempio n. 3
0
        public void AddHashCollisionTest()
        {
            // Tests linked-list functionality when hash collisions occur.
            var set = UnsafeHashSet.Allocate <DuplicateKey>(3);

            Assert.IsTrue(UnsafeHashSet.Add(set, new DuplicateKey(1)));
            Assert.IsTrue(UnsafeHashSet.Add(set, new DuplicateKey(2)));
            Assert.IsTrue(UnsafeHashSet.Add(set, new DuplicateKey(3)));
            Assert.IsFalse(UnsafeHashSet.Add(set, new DuplicateKey(1)));

            Assert.IsTrue(UnsafeHashSet.Contains(set, new DuplicateKey(2)));

            Assert.AreEqual(3, UnsafeHashSet.GetCapacity(set));

            UnsafeHashSet.Free(set);
        }
Esempio n. 4
0
        public void ExpandFailedTest()
        {
            var initialCapacity = 7;
            var set             = UnsafeHashSet.Allocate <int>(initialCapacity, true);

            // Valid adds
            for (int i = 0; i < initialCapacity; i++)
            {
                UnsafeHashSet.Add(set, i + 1);
            }

            Assert.AreEqual(initialCapacity, UnsafeHashSet.GetCount(set));
            Assert.AreEqual(initialCapacity, UnsafeHashSet.GetCapacity(set));

            Assert.Throws <InvalidOperationException>(() =>
            {
                UnsafeHashSet.Add(set, 42);
            });

            UnsafeHashSet.Free(set);
        }
Esempio n. 5
0
        public void ExpandTest()
        {
            var initialCapacity = 7;
            var set             = UnsafeHashSet.Allocate <int>(initialCapacity, fixedSize: false);

            // Valid adds
            for (int i = 0; i < initialCapacity; i++)
            {
                UnsafeHashSet.Add(set, i + 1);
            }

            Assert.AreEqual(initialCapacity, UnsafeHashSet.GetCount(set));
            Assert.AreEqual(initialCapacity, UnsafeHashSet.GetCapacity(set));

            UnsafeHashSet.Add(set, 42);
            UnsafeHashSet.Add(set, 18);

            var nextCapacity = UnsafeHashCollection.GetNextPrime(initialCapacity + 1);

            Assert.AreEqual(9, UnsafeHashSet.GetCount(set));
            Assert.AreEqual(nextCapacity, UnsafeHashSet.GetCapacity(set));

            UnsafeHashSet.Free(set);
        }