Beispiel #1
0
        public void CopyToTest()
        {
            var set = UnsafeSortedDictionary.Allocate <int, bool>(10);

            // Fill set
            for (int i = 10; i >= 0; i--)
            {
                UnsafeSortedDictionary.Add(set, i, i % 2 == 0);
            }

            var count = UnsafeSortedDictionary.GetCount(set);
            var arr   = new KeyValuePair <int, bool> [count];

            UnsafeSortedDictionary.CopyTo(set, arr, 0);

            // Check
            int num = 0;

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(i, arr[num++].Key);
            }

            UnsafeSortedDictionary.Free(set);
        }
Beispiel #2
0
        public void AddRandomTest()
        {
            var set = UnsafeSortedDictionary.Allocate <int, double>(10);

            Random r = new Random();

            for (int i = 0; i < 10; i++)
            {
                UnsafeSortedDictionary.Add(set, r.Next(), r.NextDouble());
            }

            var arr = new KeyValuePair <int, double> [10];

            UnsafeSortedDictionary.CopyTo(set, arr, 0);

            // Validate values are from low to high
            var last = arr[0];

            for (int i = 1; i < 10; i++)
            {
                Assert.IsTrue(last.Key <= arr[i].Key);
                last = arr[i++];
            }

            UnsafeSortedDictionary.Free(set);
        }
Beispiel #3
0
        public void ClearTest()
        {
            var set = UnsafeSortedDictionary.Allocate <int, float>(16, fixedSize: false);

            // Add some random data
            Random r = new Random();

            for (int i = 0; i < 10; i++)
            {
                UnsafeSortedDictionary.Add <int, float>(set, r.Next(), (float)r.NextDouble());
            }

            // Verify data has been added
            Assert.AreEqual(10, UnsafeSortedDictionary.GetCount(set));
            Assert.AreEqual(16, UnsafeSortedDictionary.GetCapacity(set));

            // Clear set and verify it's cleared
            UnsafeSortedDictionary.Clear(set);

            Assert.AreEqual(0, UnsafeSortedDictionary.GetCount(set));
            Assert.AreEqual(16, UnsafeSortedDictionary.GetCapacity(set));


            // Validate we can still add data and have it be valid
            // Add data to cleared set
            for (int i = 10; i >= 0; i--)
            {
                UnsafeSortedDictionary.Add(set, i, 41f);
            }

            var count = UnsafeSortedDictionary.GetCount(set);
            var arr   = new KeyValuePair <int, float> [count];

            UnsafeSortedDictionary.CopyTo(set, arr, 0);

            // Validate data has been written
            int num = 0;

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(i, arr[num++].Key);
            }

            Assert.AreEqual(count, UnsafeSortedDictionary.GetCount(set));
            Assert.AreEqual(16, UnsafeSortedDictionary.GetCapacity(set));

            UnsafeSortedDictionary.Free(set);
        }