-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathHashSet_Tests.cs
113 lines (90 loc) · 3.35 KB
/
HashSet_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Linq;
using Advanced.Algorithms.DataStructures.Foundation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Advanced.Algorithms.Tests.DataStructures
{
[TestClass]
public class HashSetTests
{
/// <summary>
/// key value dictionary tests
/// </summary>
[TestMethod]
public void HashSet_SeparateChaining_Test()
{
var hashSet = new HashSet<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());
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());
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());
foreach (var item in testSeries) Assert.AreEqual(true, hashSet.Contains(item));
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());
}
[TestMethod]
public void HashSet_OpenAddressing_Test()
{
var hashSet = new HashSet<int>(HashSetType.OpenAddressing);
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());
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());
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());
foreach (var item in testSeries) Assert.AreEqual(true, hashSet.Contains(item));
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());
}
}
}