-
Notifications
You must be signed in to change notification settings - Fork 292
/
SkipList_Tests.cs
60 lines (49 loc) · 1.53 KB
/
SkipList_Tests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Linq;
using Advanced.Algorithms.DataStructures;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Advanced.Algorithms.Tests.DataStructures
{
[TestClass]
public class SkipListTests
{
[TestMethod]
public void SkipList_Test()
{
var skipList = new SkipList<int>();
for (var i = 1; i < 100; i++) skipList.Insert(i);
for (var i = 1; i < 100; i++) Assert.AreEqual(i, skipList.Find(i));
Assert.AreEqual(0, skipList.Find(101));
for (var i = 1; i < 100; i++)
{
skipList.Delete(i);
Assert.AreEqual(0, skipList.Find(i));
}
for (var i = 1; i < 50; i++) skipList.Insert(i);
try
{
skipList.Insert(25);
Assert.Fail("Duplicate insertion allowed.");
}
catch (Exception)
{
}
try
{
skipList.Delete(52);
Assert.Fail("Deletion of item not in skip list did'nt throw exception.");
}
catch (Exception)
{
}
//IEnumerable test using linq
Assert.AreEqual(skipList.Count, skipList.Count());
for (var i = 1; i < 50; i++) Assert.AreEqual(i, skipList.Find(i));
for (var i = 1; i < 50; i++)
{
skipList.Delete(i);
Assert.AreEqual(0, skipList.Find(i));
}
}
}
}