-
Notifications
You must be signed in to change notification settings - Fork 291
/
SparseSet_Tests.cs
60 lines (47 loc) · 1.56 KB
/
SparseSet_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 SparseSetTests
{
[TestMethod]
public void SparseSet_Smoke_Test()
{
var set = new SparseSet(15, 10);
set.Add(6);
set.Add(15);
set.Add(0);
//IEnumerable test
Assert.AreEqual(set.Count, set.Count());
set.Remove(15);
Assert.IsTrue(set.HasItem(6));
Assert.AreEqual(2, set.Count);
//IEnumerable test
Assert.AreEqual(set.Count, set.Count());
}
[TestMethod]
public void SparseSet_Stress_Test()
{
var set = new SparseSet(1000, 1000);
var random = new Random();
var testCollection = Enumerable.Range(0, 1000)
.OrderBy(x => random.Next())
.ToList();
foreach (var element in testCollection) set.Add(element);
//IEnumerable test
Assert.AreEqual(set.Count, set.Count());
foreach (var element in testCollection) Assert.IsTrue(set.HasItem(element));
foreach (var element in testCollection)
{
Assert.IsTrue(set.HasItem(element));
set.Remove(element);
Assert.IsFalse(set.HasItem(element));
}
//IEnumerable test
Assert.AreEqual(set.Count, set.Count());
}
}
}