2 // ConcurrentSkipListTests.cs
4 // Copyright (c) 2008 Jérémie "Garuma" Laval
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 using System.Threading;
28 using System.Collections.Concurrent;
29 using Mono.Collections.Concurrent;
32 using NUnit.Framework;
34 namespace MonoTests.Mono.Collections.Concurrent
36 [TestFixtureAttribute]
37 public class ConcurrentSkipListTests
39 ConcurrentSkipList<int> skiplist;
44 skiplist = new ConcurrentSkipList<int>();
56 public void AddTestCase()
58 Assert.IsTrue(skiplist.TryAdd(1), "#1");
59 Assert.AreEqual(1, skiplist.Count, "#2");
63 public void RemoveTestCase()
65 Assert.IsFalse(skiplist.Remove(2), "#1");
66 Assert.IsFalse(skiplist.Remove(3), "#2");
69 int count = skiplist.Count;
70 Assert.IsTrue(skiplist.Remove(1), "#3");
71 Assert.IsFalse(skiplist.Remove(1), "#4");
72 Assert.IsTrue(skiplist.Remove(4), "#5");
73 Assert.AreEqual(count - 2, skiplist.Count, "#6");
77 public void ContainsTestCase()
80 Assert.IsTrue(skiplist.Contains(1), "#1");
81 Assert.IsTrue(skiplist.Contains(2), "#2");
82 Assert.IsTrue(skiplist.Contains(3), "#3");
83 Assert.IsTrue(skiplist.Contains(4), "#4");
87 public void EnumerateTestCase()
91 string s = string.Empty;
92 foreach (int i in skiplist)
95 Assert.AreEqual("1234", s);
99 public void ToArrayTestCase()
101 int[] expected = new int[] { 1, 2, 3, 4 };
103 int[] array = skiplist.ToArray();
104 CollectionAssert.AreEqual(expected, array, "#1");
106 Array.Clear(array, 0, array.Length);
107 skiplist.CopyTo(array, 0);
108 CollectionAssert.AreEqual(expected, array, "#2");