Пример #1
0
        public void Foreach_Success()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();
            var items    = new[] { 1, 5, 10, 7, 100, 54, 23, 86 };

            foreach (var item in items)
            {
                skipList.Add(item, item + 1);
            }

            var sortedItems = items.ToList();

            sortedItems.Sort();

            var index = 0;

            foreach (var skipListItem in skipList)
            {
                Assert.AreEqual(sortedItems[index], skipListItem.Key);
                Assert.AreEqual(sortedItems[index] + 1, skipListItem.Value);
                index++;
            }

            index = 0;
            foreach (var skipListValue in skipList.Select(x => x.Value))
            {
                Assert.AreEqual(sortedItems[index] + 1, skipListValue);
                index++;
            }
        }
Пример #2
0
        public void Add_Success()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();

            AddItems_0_to_1000(skipList);
            Assert.AreEqual(1000, skipList.Count);
        }
Пример #3
0
        public void AddRemove_Success()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();

            skipList.Add(3, 3);
            skipList.Add(1, 1);
            skipList.Add(10, 10);

            Assert.IsFalse(skipList.Remove(0));
            Assert.IsFalse(skipList.Remove(2));
            Assert.IsFalse(skipList.Remove(6));
            Assert.IsFalse(skipList.Remove(20));

            Assert.IsTrue(skipList.Remove(10));
            Assert.IsTrue(skipList.ContainsKey(1));
            Assert.IsTrue(skipList.ContainsKey(3));
            Assert.IsFalse(skipList.ContainsKey(10));
            Assert.AreEqual(2, skipList.Count);

            Assert.IsTrue(skipList.Remove(1));
            Assert.IsFalse(skipList.ContainsKey(1));
            Assert.IsTrue(skipList.ContainsKey(3));
            Assert.IsFalse(skipList.ContainsKey(10));
            Assert.AreEqual(1, skipList.Count);

            Assert.IsTrue(skipList.Remove(3));
            Assert.IsFalse(skipList.ContainsKey(1));
            Assert.IsFalse(skipList.ContainsKey(3));
            Assert.IsFalse(skipList.ContainsKey(10));
            Assert.AreEqual(0, skipList.Count);

            Assert.IsFalse(skipList.Remove(1));
        }
Пример #4
0
        public void GetNotExists_Fail()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();

            AddItems_0_to_1000(skipList);

            Assert.IsFalse(skipList.TryGetValue(1234, out var value));
        }
Пример #5
0
        public void ContainsKey_Success()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();

            AddItems_0_to_1000(skipList);

            for (var i = 0; i < 1000; i++)
            {
                Assert.IsTrue(skipList.ContainsKey(i));
            }
        }
Пример #6
0
        public void DuplicateKey_Exception()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();

            skipList.Add(1, 1);

            Assert.ThrowsException <ArgumentException>(() =>
            {
                skipList.Add(1, 1);
            });
        }
Пример #7
0
        public void ContainsKey_Fail()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();

            AddItems_0_to_1000(skipList);

            Assert.IsFalse(skipList.ContainsKey(-2));
            Assert.IsFalse(skipList.ContainsKey(-1));
            Assert.IsFalse(skipList.ContainsKey(1000));
            Assert.IsFalse(skipList.ContainsKey(1001));
            Assert.IsFalse(skipList.ContainsKey(1123123));
        }
Пример #8
0
        public void RemoveBoundary_Fail()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();

            AddItems_0_to_1000(skipList);

            Assert.IsFalse(skipList.Remove(-3));
            Assert.IsFalse(skipList.Remove(-2));
            Assert.IsFalse(skipList.Remove(-1));
            Assert.IsFalse(skipList.Remove(1000));
            Assert.IsFalse(skipList.Remove(1001));
            Assert.IsFalse(skipList.Remove(1002));
        }
Пример #9
0
        public void GetAllItems_Success()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();

            AddItems_0_to_1000(skipList);

            Int32 value;

            for (var i = 0; i < 1000; i++)
            {
                Assert.IsTrue(skipList.TryGetValue(i, out value));
                Assert.AreEqual(i + 1, value);
            }
        }
Пример #10
0
        public void CopyTo_Success()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>
            {
                { 2, 10 },
                { 234, 3 }
            };

            var targetArray = new KeyValuePair <Int32, Int32> [4];

            skipList.CopyTo(targetArray, 0);
            Assert.AreEqual(new KeyValuePair <Int32, Int32>(2, 10), targetArray[0]);
            Assert.AreEqual(new KeyValuePair <Int32, Int32>(234, 3), targetArray[1]);
            Assert.AreEqual(default, targetArray[2]);
Пример #11
0
        public void Contains_Success()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>
            {
                { 2, 10 },
                { 234, 3 }
            };

            Assert.AreEqual(2, skipList.Count);
            Assert.IsTrue(skipList.ContainsKey(234));
            Assert.IsTrue(skipList.Contains(new KeyValuePair <int, int>(234, 3)));
            Assert.IsFalse(skipList.Contains(new KeyValuePair <int, int>(234, 1)));
            Assert.IsFalse(skipList.Contains(new KeyValuePair <int, int>(50, 50)));
        }
Пример #12
0
        public void Clear_Success()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>
            {
                { 3, 5 },
                { 6, 7 }
            };

            Assert.AreEqual(2, skipList.Count);

            skipList.Clear();
            Assert.AreEqual(0, skipList.Count);
            Assert.AreEqual(0, skipList.AsEnumerable().Count());
        }
Пример #13
0
        private void AddItems_0_to_1000(ConcurrentSkipListMap <Int32, Int32> skipList)
        {
            for (var i = 0; i < 1000; i += 3)
            {
                skipList.Add(i, i + 1);
            }

            for (var i = 1; i < 1000; i += 3)
            {
                skipList.Add(i, i + 1);
            }

            for (var i = 2; i < 1000; i += 3)
            {
                skipList.Add(i, i + 1);
            }
        }
Пример #14
0
        public void Remove_Success()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();

            AddItems_0_to_1000(skipList);

            var oldLength     = skipList.Count;
            var toRemoveItems = new[] { 2, 934, 54, 19, 245, 512, 777, 13 };

            foreach (var item in toRemoveItems)
            {
                Assert.IsTrue(skipList.Remove(item));
            }

            Assert.AreEqual(oldLength - toRemoveItems.Length, skipList.Count);

            foreach (var item in toRemoveItems)
            {
                Assert.IsFalse(skipList.ContainsKey(item));
            }
        }
Пример #15
0
        public void CopyTo_Fail()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>
            {
                { 2, 10 },
                { 234, 3 }
            };

            KeyValuePair <Int32, Int32>[] targetArray_null = null;
            Assert.ThrowsException <ArgumentNullException>(() =>
            {
                skipList.CopyTo(targetArray_null, 0);
            });

            var targetArray = new KeyValuePair <Int32, Int32> [4];

            Assert.ThrowsException <ArgumentException>(() =>
            {
                skipList.CopyTo(targetArray, 3);
            });

            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
            {
                skipList.CopyTo(targetArray, -11);
            });

            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
            {
                skipList.CopyTo(targetArray, targetArray.Length);
            });

            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
            {
                skipList.CopyTo(targetArray, targetArray.Length + 1);
            });
        }
Пример #16
0
        public void IsReadOnly_Success()
        {
            var skipList = new ConcurrentSkipListMap <Int32, Int32>();

            Assert.IsFalse(skipList.IsReadOnly);
        }