Welcome to mirror list, hosted at ThFree Co, Russian Federation.

StackTest.cs « System.Collections « Test « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fdcc3b07cceb0d7a075223b45bc28f75597a82d2 (plain)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
//
// StackTest.cs
//
// Author:
//  Chris Hynes <chrish@assistedsolutions.com>
//
// (C) 2001 Chris Hynes
//

using System;

using System.Collections;

using NUnit.Framework;

namespace MonoTests.System.Collections
{
	public class StackTest: TestCase
	{
                private Stack stack1;
                private Stack stack2;
                private Stack stackInt;

                public void TestConstructor()
                {
                        AssertEquals(false, stack1 == null);
                }
                
                public void TestICollectionConstructor()
                {
                        Stack stackTest = new Stack(new int[] {0, 1, 2, 3, 4});

                        for (int i = 4; i >= 0; i--)
                                AssertEquals(i, stackTest.Pop());

                        AssertEquals(0, stackTest.Count);
                }

                public void TestIntConstructor()
                {
                        Stack stackTest = new Stack(50);

                        AssertEquals(false, stackTest == null);
                }

                public void TestCount()
                {
                        Stack stackTest = new Stack();

                        stackTest.Push(50);
                        stackTest.Push(5);
                        stackTest.Push(0);
                        stackTest.Push(50);

                        AssertEquals(4, stackTest.Count);
                }

                public void TestIsSyncronized()
                {
                        AssertEquals(false, stack1.IsSynchronized);
                        AssertEquals(true, Stack.Synchronized(stack1).IsSynchronized);
                }

                public void TestSyncRoot()
                {
                        AssertEquals(false, stack1.SyncRoot == null);
                }

                public void TestGetEnumerator()
                {
                        stackInt.Pop();

                        int j = 3;

                        foreach (int i in stackInt)
                        {
                                AssertEquals(j--, i);
                        }

                        stackInt.Clear();

                        IEnumerator e = stackInt.GetEnumerator();

                        AssertEquals(false, e.MoveNext());
                }

                public void TestClear()
                {
                        stackInt.Clear();

                        AssertEquals(0, stackInt.Count);
                }

                public void TestClone()
                {
                        Stack clone = (Stack)stackInt.Clone();

                        while (stackInt.Count > 0)
                        {
                                AssertEquals(stackInt.Pop(), clone.Pop());
                        }
                }

                public void TestContains()
                {
                        string toLocate = "test";

                        stackInt.Push(toLocate);

                        stackInt.Push("chaff");

                        Assert(stackInt.Contains(toLocate));

                        stackInt.Pop();

                        Assert(stackInt.Contains(toLocate));

                        stackInt.Pop();

                        Assert(!stackInt.Contains(toLocate));
                }

                public void TestCopyTo()
                {
                        int[] arr = new int[stackInt.Count - 1];
                        int[,] arrMulti;

                        try 
                        {
                                stackInt.CopyTo(null, 0);
                                Fail("Should throw an ArgumentNullException");
                        } 
                        catch (ArgumentNullException) {}

                        try
                        {
                                stackInt.CopyTo(arr, -1);
                                Fail("Should throw an ArgumentOutOfRangeException");
                        } 
                        catch (ArgumentOutOfRangeException) {}

                        try
                        {
                                stackInt.CopyTo(arrMulti = new int[1, 1], 1);
                                Fail("Should throw an ArgumentException");
                        } 
                        catch (ArgumentException) {}

                        try
                        {
                                stackInt.CopyTo(arr = new int[2], 3);
                                Fail("Should throw an ArgumentException");
                        } 
                        catch (ArgumentException) {}

                        try
                        {
                                stackInt.CopyTo(arr = new int[3], 2);
                                Fail("Should throw an ArgumentException");
                        } 
                        catch (ArgumentException) {}

                        try
                        {
                                stackInt.CopyTo(arr = new int[2], 3);
                                Fail("Should throw an ArgumentException");
                        } 
                        catch (ArgumentException) {}

                        arr = new int[stackInt.Count];

                        stackInt.CopyTo(arr, 0);

                        int j = 4;

                        for (int i = 0; i < 4; i++)
                        {
                               AssertEquals(j--, arr[i]);
                        }
                }

                public void TestSyncronized()
                {
                        Stack syncStack = Stack.Synchronized(stackInt);

                        syncStack.Push(5);

                        for (int i = 5; i >= 0; i--)
                                AssertEquals(i, syncStack.Pop());
                }

                public void TestPushPeekPop()
                {
                        stackInt.Pop();

                        int topVal = (int)stackInt.Peek();

                        AssertEquals(3, topVal);

                        AssertEquals(4, stackInt.Count);

                        AssertEquals(topVal, stackInt.Pop());

                        AssertEquals(2, stackInt.Pop());

                        Stack test = new Stack();
                        test.Push(null);

                        AssertEquals(null, test.Pop());
                }

                public void TestToArray()
                {
                        object[] arr = stackInt.ToArray();

                        AssertEquals(stackInt.Count, arr.Length);                       

                        for (int i = 0; i < 5; i++)
                                AssertEquals(arr[i], stackInt.Pop());
                }

                static void Main(string[] args)
		{
      			//
			// TODO: Add code to start application here
			//
		}

                protected override void SetUp()
                {
                        stack1 = new Stack();
                        stack2 = new Stack();

                        stackInt = new Stack();
    
                        for (int i = 0; i < 5; i++)
                                stackInt.Push(i);
                }

                public static ITest Suite 
                { 
                        get 
                        {
                                TestSuite stackSuite = new TestSuite(); 
                                
                                stackSuite.AddTest(new StackTest("TestConstructor"));
                                stackSuite.AddTest(new StackTest("TestICollectionConstructor"));
                                stackSuite.AddTest(new StackTest("TestIntConstructor"));

                                stackSuite.AddTest(new StackTest("TestCount"));
                                stackSuite.AddTest(new StackTest("TestIsSyncronized"));
                                stackSuite.AddTest(new StackTest("TestSyncRoot"));

                                stackSuite.AddTest(new StackTest("TestGetEnumerator"));
                                stackSuite.AddTest(new StackTest("TestClear"));
                                stackSuite.AddTest(new StackTest("TestClone"));
                                stackSuite.AddTest(new StackTest("TestContains"));
                                stackSuite.AddTest(new StackTest("TestPushPeekPop"));
                                stackSuite.AddTest(new StackTest("TestCopyTo"));
                                stackSuite.AddTest(new StackTest("TestSyncronized"));
                                stackSuite.AddTest(new StackTest("TestToArray"));

                                return stackSuite;
                        }
                }

		public StackTest() : base ("MonoTests.System.Collections.StackTest testcase") {}
                public StackTest(string name): base(name) {}
        }
}