Exemplo n.º 1
0
        public void TryGetValueTest()
        {
            var set = UnsafeSortedDictionary.Allocate <int, int>(10);

            Assert.IsFalse(UnsafeSortedDictionary.TryGetValue(set, 1, out int value));

            UnsafeSortedDictionary.Add(set, 1, 1);
            UnsafeSortedDictionary.Add(set, 7, 2);
            UnsafeSortedDictionary.Add(set, 51, 3);
            UnsafeSortedDictionary.Add(set, 13, 4);

            Assert.IsFalse(UnsafeSortedDictionary.TryGetValue(set, 3, out value));

            Assert.IsTrue(UnsafeSortedDictionary.TryGetValue(set, 1, out value));
            Assert.AreEqual(1, value);
            Assert.IsTrue(UnsafeSortedDictionary.TryGetValue(set, 7, out value));
            Assert.AreEqual(2, value);
            Assert.IsTrue(UnsafeSortedDictionary.TryGetValue(set, 13, out value));
            Assert.AreEqual(4, value);
            Assert.IsTrue(UnsafeSortedDictionary.TryGetValue(set, 51, out value));
            Assert.AreEqual(3, value);

            Assert.IsFalse(UnsafeSortedDictionary.TryGetValue(set, 14, out value));

            UnsafeSortedDictionary.Free(set);
        }
Exemplo n.º 2
0
        public void SetterTest()
        {
            var set = UnsafeSortedDictionary.Allocate <int, int>(4);

            UnsafeSortedDictionary.Add(set, 1, 1);
            UnsafeSortedDictionary.Add(set, 7, 2);

            // Add new key
            UnsafeSortedDictionary.Set(set, 2, 412);
            Assert.IsTrue(UnsafeSortedDictionary.TryGetValue <int, int>(set, 2, out int valNew));
            Assert.AreEqual(412, valNew);

            // Overwrite existing key
            UnsafeSortedDictionary.Set(set, 1, 333);
            Assert.IsTrue(UnsafeSortedDictionary.TryGetValue <int, int>(set, 1, out int valExist));
            Assert.AreEqual(333, valExist);
        }