-
Notifications
You must be signed in to change notification settings - Fork 1
/
MaxBinaryHeapTests.cs
52 lines (44 loc) · 1.36 KB
/
MaxBinaryHeapTests.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
using System;
using Xunit;
using System.Linq;
using AlgorithmsAndDataStructures.DataStructures.BinaryHeaps;
namespace AlgorithmsAndDataStructures.Tests.DataStructures.BinaryHeap
{
public class MaxBinaryHeapTests
{
[Fact]
public void TopElementIsInsertedWhenHeapIsEmpty()
{
var sut = new MaxBinaryHeap<int>();
sut.Insert(10);
Assert.Equal(10, sut.GetTop());
}
[Fact]
public void MaxValueElementIsOnTheTop()
{
var sut = new MaxBinaryHeap<int>();
sut.Insert(10);
sut.Insert(20);
Assert.Equal(20, sut.GetTop());
Assert.Equal(10, sut.GetTop());
}
// TODO: Replace with property based testing.
[Fact]
public void MaxValueElementIsAlwaysOnTheTop()
{
var sut = new MaxBinaryHeap<int>(1001);
var randomValues = new int[1000];
var random = new Random();
for (var i = 0; i < 1000; i++)
{
randomValues[i] = random.Next(10000);
sut.Insert(randomValues[i]);
}
var orderedArray = randomValues.OrderByDescending(arg => arg).ToArray();
for (var i = 0; i < 1000; i++)
{
Assert.Equal(orderedArray[i], sut.GetTop());
}
}
}
}