-
Notifications
You must be signed in to change notification settings - Fork 292
/
D-aryHeap_Tests.cs
81 lines (61 loc) · 2.27 KB
/
D-aryHeap_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
using System;
using System.Collections.Generic;
using System.Linq;
using Advanced.Algorithms.DataStructures;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Advanced.Algorithms.Tests.DataStructures
{
[TestClass]
public class DAryHeapTests
{
[TestMethod]
public void Min_D_ary_Heap_Test()
{
var rnd = new Random();
var initial = Enumerable.Range(0, 51).OrderBy(x => rnd.Next()).ToList();
var minHeap = new DaryHeap<int>(4, SortDirection.Ascending, initial);
for (var i = 51; i <= 99; i++) minHeap.Insert(i);
for (var i = 0; i <= 99; i++)
{
var min = minHeap.Extract();
Assert.AreEqual(min, i);
}
//IEnumerable tests.
Assert.AreEqual(minHeap.Count, minHeap.Count());
var testSeries = Enumerable.Range(1, 49).OrderBy(x => rnd.Next()).ToList();
foreach (var item in testSeries) minHeap.Insert(item);
for (var i = 1; i <= 49; i++)
{
var min = minHeap.Extract();
Assert.AreEqual(min, i);
}
//IEnumerable tests.
Assert.AreEqual(minHeap.Count, minHeap.Count());
}
[TestMethod]
public void Max_D_ary_Heap_Test()
{
var rnd = new Random();
var initial = new List<int>(Enumerable.Range(0, 51)
.OrderBy(x => rnd.Next()));
var maxHeap = new DaryHeap<int>(4, SortDirection.Descending, initial);
for (var i = 51; i <= 99; i++) maxHeap.Insert(i);
for (var i = 99; i >= 0; i--)
{
var max = maxHeap.Extract();
Assert.AreEqual(max, i);
}
//IEnumerable tests.
Assert.AreEqual(maxHeap.Count, maxHeap.Count());
var testSeries = Enumerable.Range(1, 49).OrderBy(x => rnd.Next()).ToList();
foreach (var item in testSeries) maxHeap.Insert(item);
for (var i = 49; i > 0; i--)
{
var max = maxHeap.Extract();
Assert.AreEqual(i, max);
}
//IEnumerable tests.
Assert.AreEqual(maxHeap.Count, maxHeap.Count());
}
}
}