5 // Ben Maurer (bmaurer@ximian.com)
10 using System.Collections;
11 using System.Collections.Generic;
13 using NUnit.Framework;
15 namespace MonoTests.System.Collections.Generic {
17 public class StackTest: Assertion
20 public void TestCtor ()
22 Stack <int> a = new Stack <int> ();
23 Stack <int> b = new Stack <int> (1);
24 Stack <object> c = new Stack <object> ();
25 Stack <object> d = new Stack <object> (1);
26 Stack <object> e = new Stack <object> (0);
30 [ExpectedException (typeof (ArgumentOutOfRangeException))]
31 public void TestCtorEx ()
33 Stack <int> a = new Stack <int> (-1);
37 public void TestCtorEnum ()
39 List <int> l = new List <int> ();
44 Stack <int> s = new Stack <int> (l);
46 // Things get pop'd in reverse
53 [ExpectedException (typeof (ArgumentNullException))]
54 public void TestCtorEnumNull ()
56 Stack <int> s = new Stack <int> (null);
60 public void TestClear()
62 Stack <int> s = new Stack <int> ();
65 AssertEquals (s.Count, 0);
70 AssertEquals (s.Count, 2);
74 AssertEquals (s.Count, 0);
78 public void TestContains ()
80 Stack <int> s = new Stack <int> ();
82 AssertEquals (s.Contains (1), false);
86 AssertEquals (s.Contains (1), true);
87 AssertEquals (s.Contains (0), false);
91 public void TestCopyTo ()
93 int [] x = new int [3];
94 Stack <int> z = new Stack <int> ();
100 AssertEquals (x [0], 10);
101 AssertEquals (x [1], 2);
102 AssertEquals (x [2], 1);
106 public void TestPeek ()
108 Stack <int> s = new Stack <int> ();
111 AssertEquals (s.Peek (), 1);
112 AssertEquals (s.Count, 1);
116 [ExpectedException (typeof (InvalidOperationException))]
117 public void TestPeekEx ()
119 Stack <int> s = new Stack <int> ();
124 [ExpectedException (typeof (InvalidOperationException))]
125 public void TestPeekEx2 ()
127 Stack <int> s = new Stack <int> ();
134 public void TestPop ()
136 Stack <int> s = new Stack <int> ();
139 AssertEquals (s.Pop (), 1);
140 AssertEquals (s.Count, 0);
144 [ExpectedException (typeof (InvalidOperationException))]
145 public void TestPopEx ()
147 Stack <int> s = new Stack <int> ();
152 [ExpectedException (typeof (InvalidOperationException))]
153 public void TestPopEx2 ()
155 Stack <int> s = new Stack <int> ();
162 public void TestPush ()
164 Stack <int> s = new Stack <int> ();
166 AssertEquals (s.Count, 1);
168 AssertEquals (s.Count, 2);
170 for (int i = 0; i < 100; i ++)
173 AssertEquals (s.Count, 102);
177 public void TestToArray ()
179 Stack <int> s = new Stack <int> ();
181 int [] x = s.ToArray ();
183 AssertEquals (x.Length, 0);
187 AssertEquals (x.Length, 1);
188 AssertEquals (x [0], 1);
192 public void TestEnumerator ()
194 Stack <int> s = new Stack <int> ();
203 foreach (int x in s) {
214 foreach (int x in s) {
215 AssertEquals (x, 3 - i);
221 void AssertPop <T> (Stack <T> s, T t)
223 AssertEquals (s.Pop (), t);