-
Notifications
You must be signed in to change notification settings - Fork 294
/
Copy pathOrderedHashSet_Tests.cs
66 lines (55 loc) · 2.05 KB
/
OrderedHashSet_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
61
62
63
64
65
66
using System;
using System.Linq;
using Advanced.Algorithms.DataStructures.Foundation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Advanced.Algorithms.Tests.DataStructures
{
[TestClass]
public class OrderedHashSetTests
{
/// <summary>
/// key value HashSet tests
/// </summary>
[TestMethod]
public void OrderedHashSet_Test()
{
var hashSet = new OrderedHashSet<int>();
var nodeCount = 1000;
//insert test
for (var i = 0; i <= nodeCount; i++)
{
hashSet.Add(i);
Assert.AreEqual(true, hashSet.Contains(i));
}
//IEnumerable test using linq
Assert.AreEqual(hashSet.Count, hashSet.Count());
Assert.AreEqual(hashSet.Count, hashSet.AsEnumerableDesc().Count());
for (var i = 0; i <= nodeCount; i++)
{
hashSet.Remove(i);
Assert.AreEqual(false, hashSet.Contains(i));
}
//IEnumerable test using linq
Assert.AreEqual(hashSet.Count, hashSet.Count());
Assert.AreEqual(hashSet.Count, hashSet.AsEnumerableDesc().Count());
var rnd = new Random();
var testSeries = Enumerable.Range(1, nodeCount).OrderBy(x => rnd.Next()).ToList();
foreach (var item in testSeries)
{
hashSet.Add(item);
Assert.AreEqual(true, hashSet.Contains(item));
}
//IEnumerable test using linq
Assert.AreEqual(hashSet.Count, hashSet.Count());
Assert.AreEqual(hashSet.Count, hashSet.AsEnumerableDesc().Count());
for (var i = 1; i <= nodeCount; i++)
{
hashSet.Remove(i);
Assert.AreEqual(false, hashSet.Contains(i));
}
//IEnumerable test using linq
Assert.AreEqual(hashSet.Count, hashSet.Count());
Assert.AreEqual(hashSet.Count, hashSet.AsEnumerableDesc().Count());
}
}
}