forked from sarbian/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImmutableStackTest.cs
More file actions
140 lines (115 loc) · 4.21 KB
/
Copy pathImmutableStackTest.cs
File metadata and controls
140 lines (115 loc) · 4.21 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Linq;
using Xunit;
using ModuleManager.Collections;
namespace ModuleManagerTests.Collections
{
public class ImmutableStackTest
{
[Fact]
public void TestValue()
{
object obj = new object();
ImmutableStack<object> stack = new ImmutableStack<object>(obj);
Assert.Same(obj, stack.value);
}
[Fact]
public void TestIsRoot()
{
ImmutableStack<object> stack1 = new ImmutableStack<object>(new object());
ImmutableStack<object> stack2 = stack1.Push(new object());
Assert.True(stack1.IsRoot);
Assert.False(stack2.IsRoot);
}
[Fact]
public void TestRoot()
{
ImmutableStack<object> stack1 = new ImmutableStack<object>(new object());
ImmutableStack<object> stack2 = stack1.Push(new object());
ImmutableStack<object> stack3 = stack2.Push(new object());
Assert.Same(stack1, stack1.Root);
Assert.Same(stack1, stack2.Root);
Assert.Same(stack1, stack3.Root);
}
[Fact]
public void TestDepth()
{
ImmutableStack<object> stack1 = new ImmutableStack<object>(new object());
ImmutableStack<object> stack2 = stack1.Push(new object());
ImmutableStack<object> stack3 = stack2.Push(new object());
Assert.Equal(1, stack1.Depth);
Assert.Equal(2, stack2.Depth);
Assert.Equal(3, stack3.Depth);
}
[Fact]
public void TestPush()
{
object obj1 = new object();
object obj2 = new object();
object obj3 = new object();
ImmutableStack<object> stack1 = new ImmutableStack<object>(obj1);
ImmutableStack<object> stack2 = stack1.Push(obj2);
ImmutableStack<object> stack3 = stack2.Push(obj3);
Assert.Same(stack2, stack3.parent);
Assert.Same(stack1, stack2.parent);
Assert.Same(obj1, stack1.value);
Assert.Same(obj2, stack2.value);
Assert.Same(obj3, stack3.value);
}
[Fact]
public void TestPop()
{
object obj1 = new object();
object obj2 = new object();
object obj3 = new object();
ImmutableStack<object> stack = new ImmutableStack<object>(obj1).Push(obj2).Push(obj3);
Assert.Same(obj1, stack.Pop().Pop().value);
Assert.Same(obj2, stack.Pop().value);
Assert.Same(obj3, stack.value);
}
[Fact]
public void TestPop__Root()
{
ImmutableStack<object> stack = new ImmutableStack<object>(new object());
Assert.Throws<InvalidOperationException>(delegate
{
stack.Pop();
});
}
[Fact]
public void TestReplaceValue()
{
object obj1 = new object();
object obj2 = new object();
object obj3 = new object();
ImmutableStack<object> stack1 = new ImmutableStack<object>(obj1);
ImmutableStack<object> stack2 = stack1.Push(obj2);
ImmutableStack<object> stack3 = stack2.ReplaceValue(obj3);
Assert.Same(obj3, stack3.value);
Assert.Same(stack1, stack3.parent);
}
[Fact]
public void TestReplaceValue__Root()
{
object obj1 = new object();
object obj2 = new object();
ImmutableStack<object> stack1 = new ImmutableStack<object>(obj1);
ImmutableStack<object> stack2 = stack1.ReplaceValue(obj2);
Assert.Same(obj2, stack2.value);
Assert.Null(stack2.parent);
}
[Fact]
public void TestEnumerator()
{
object obj1 = new object();
object obj2 = new object();
object obj3 = new object();
ImmutableStack<object> stack = new ImmutableStack<object>(obj1).Push(obj2).Push(obj3);
object[] objs = stack.ToArray();
Assert.Equal(3, objs.Length);
Assert.Same(obj3, objs[0]);
Assert.Same(obj2, objs[1]);
Assert.Same(obj1, objs[2]);
}
}
}