Exemple #1
0
        public void ClearDictionary()
        {
            var map = UnsafeDictionary.Allocate <int, int>(16, fixedSize: false);

            for (int i = 0; i < 3; i++)
            {
                UnsafeDictionary.Add(map, i, 3);
            }

            Assert.IsTrue(UnsafeDictionary.ContainsKey(map, 2));
            Assert.AreEqual(3, UnsafeDictionary.GetCount(map));
            UnsafeDictionary.TryGetValue(map, 2, out int result);
            Assert.AreEqual(3, result);

            UnsafeDictionary.Add(map, 3, 1);
            Assert.AreEqual(4, UnsafeDictionary.GetCount(map));

            UnsafeDictionary.Clear(map);
            Assert.AreEqual(0, UnsafeDictionary.GetCount(map));
            Assert.IsFalse(UnsafeDictionary.ContainsKey(map, 2));

            UnsafeDictionary.Add(map, 3, 10);
            Assert.AreEqual(1, UnsafeDictionary.GetCount(map));
            Assert.IsTrue(UnsafeDictionary.ContainsKey(map, 3));
            UnsafeDictionary.TryGetValue(map, 3, out int result2);
            Assert.AreEqual(10, result2);

            UnsafeDictionary.Clear(map);
            Assert.AreEqual(0, UnsafeDictionary.GetCount(map));

            UnsafeDictionary.Free(map);
        }
Exemple #2
0
        public void ContainsValueTest()
        {
            var set = UnsafeDictionary.Allocate <int, int>(10);

            Assert.IsFalse(UnsafeDictionary.ContainsKey <int>(set, 1));

            UnsafeDictionary.Add(set, 1, 5);
            UnsafeDictionary.Add(set, 2, 2);
            UnsafeDictionary.Add(set, 3, 38);

            Assert.IsTrue(UnsafeDictionary.ContainsValue <int>(set, 2));
            Assert.IsTrue(UnsafeDictionary.ContainsValue <int>(set, 38));
            Assert.IsFalse(UnsafeDictionary.ContainsValue <int>(set, 1));

            UnsafeDictionary.Free(set);
        }
Exemple #3
0
        public void ContainsTest()
        {
            var set = UnsafeDictionary.Allocate <int, int>(10);

            Assert.IsFalse(UnsafeDictionary.ContainsKey <int>(set, 1));

            UnsafeDictionary.Add(set, 1, 3);
            UnsafeDictionary.Add(set, 7, 3);
            UnsafeDictionary.Add(set, 51, 3);
            UnsafeDictionary.Add(set, 13, 3);

            Assert.IsFalse(UnsafeDictionary.ContainsKey <int>(set, 3));

            Assert.IsTrue(UnsafeDictionary.ContainsKey <int>(set, 1));
            Assert.IsTrue(UnsafeDictionary.ContainsKey <int>(set, 7));
            Assert.IsTrue(UnsafeDictionary.ContainsKey <int>(set, 13));
            Assert.IsTrue(UnsafeDictionary.ContainsKey <int>(set, 51));

            Assert.IsFalse(UnsafeDictionary.ContainsKey <int>(set, 14));

            UnsafeDictionary.Free(set);
        }