-
Notifications
You must be signed in to change notification settings - Fork 0
/
StackTests.cs
79 lines (69 loc) · 1.95 KB
/
StackTests.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
using Core = CoreConcepts.DataStructures.Linear;
using Xunit;
namespace CoreConcepts.Tests.DataStructures.Linear
{
public class StackTests
{
[Fact]
public void Test_Default_Constructor()
{
Core.Stack<int> stack = new Core.Stack<int>();
Assert.Empty(stack);
Assert.Equal(0, stack.Count);
}
[Fact]
public void Test_Constructor_With_Initial_Value()
{
Core.Stack<int> stack = new Core.Stack<int>(5);
Assert.NotEmpty(stack);
Assert.Equal(1, stack.Count);
}
[Fact]
public void Test_Push()
{
Core.Stack<int> stack = new Core.Stack<int>();
int itemsToPush = 5;
for (int i = 0; i < itemsToPush; i++)
{
stack.Push(i);
}
Assert.Equal(itemsToPush, stack.Count);
}
[Fact]
public void Test_Peek()
{
Core.Stack<int> stack = new Core.Stack<int>();
int pushedValue = 5;
stack.Push(pushedValue);
Assert.Equal(pushedValue, stack.Peek());
}
[Fact]
public void Test_Pop()
{
Core.Stack<int> stack = new Core.Stack<int>();
int itemsToPush = 5;
for (int i = 1; i <= itemsToPush; i++)
{
stack.Push(i);
}
for (int i = itemsToPush; i > 0; i--)
{
int value = stack.Pop();
Assert.Equal(i, value);
}
Assert.Equal(0, stack.Count);
}
[Fact]
public void Test_Clear()
{
Core.Stack<int> stack = new Core.Stack<int>();
int itemsToPush = 5;
for (int i = 0; i < itemsToPush; i++)
{
stack.Push(i);
}
stack.Clear();
Assert.Equal(0, stack.Count);
}
}
}