-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path155.MinStack.Test.cs
42 lines (41 loc) · 1.19 KB
/
155.MinStack.Test.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
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
[TestFixture]
public class TestClass : TestClassBase
{
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void TestMethod(int operationCount)
{
var stack = new Stack<int>();
var heap = new SortedList<int, int>();
var minStack = new MinStack();
Repeat(operationCount, () =>
{
var operation = stack.Count == 0 ? 0 : Random.Next(4);
var x = Random.Next(int.MaxValue);
switch (operation)
{
case 0: // Push
stack.Push(x);
heap.Add(x, x);
minStack.Push(x);
break;
case 1: // Pop
heap.Remove(stack.Peek());
stack.Pop();
minStack.Pop();
break;
case 2: // Top
Assert.AreEqual(stack.Peek(), minStack.Top());
break;
case 3: // GetMin
Assert.AreEqual(heap.First().Key, minStack.GetMin());
break;
}
});
}
}