Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / Core / Castle.Core.Tests / LinkedListTestCase.cs
blob9fbc52d833715a62bacbfe008313f3a141f89116
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Core.Tests
17 using System;
19 using NUnit.Framework;
21 using Castle.Core.Internal;
23 [TestFixture]
24 public class LinkedListTestCase
26 [Test]
27 public void Enumerable()
29 LinkedList list = new LinkedList();
31 list.AddFirst( "third" );
32 list.AddFirst( "second" );
33 list.AddFirst( "first" );
35 int index = 0;
37 foreach(String value in list)
39 switch(index++)
41 case 0:
42 Assert.AreEqual( "first", value );
43 break;
44 case 1:
45 Assert.AreEqual( "second", value );
46 break;
47 case 2:
48 Assert.AreEqual( "third", value );
49 break;
54 [Test]
55 public void AddFirst()
57 LinkedList list = new LinkedList();
59 list.AddFirst( "third" );
60 Assert.AreEqual( "third", list.Head );
61 Assert.AreEqual( 1, list.Count );
63 list.AddFirst( "second" );
64 Assert.AreEqual( "second", list.Head );
65 Assert.AreEqual( 2, list.Count );
67 list.AddFirst( "first" );
68 Assert.AreEqual( "first", list.Head );
69 Assert.AreEqual( 3, list.Count );
72 [Test]
73 public void Add()
75 LinkedList list = new LinkedList();
77 list.Add( "1" );
78 Assert.AreEqual( "1", list.Head );
79 Assert.AreEqual( 1, list.Count );
81 list.Add( "2" );
82 Assert.AreEqual( "1", list.Head );
83 Assert.AreEqual( 2, list.Count );
85 list.Add( "3" );
86 Assert.AreEqual( "1", list.Head );
87 Assert.AreEqual( 3, list.Count );
90 [Test]
91 public void RemoveBoundary1()
93 LinkedList list = new LinkedList();
95 list.Add( "1" );
97 list.Add( "2" );
99 list.Add( "3" );
101 list.Remove( "1" );
103 Assert.AreEqual( "2", list.Head );
104 Assert.AreEqual( 2, list.Count );
106 String[] array = (String[]) list.ToArray( typeof(String) );
107 Assert.AreEqual( "2,3", String.Join(",", array) );
110 [Test]
111 public void RemoveBoundary2()
113 LinkedList list = new LinkedList();
115 list.Add( "1" );
117 list.Add( "2" );
119 list.Add( "3" );
121 list.Remove( "3" );
123 Assert.AreEqual( "1", list.Head );
124 Assert.AreEqual( 2, list.Count );
126 String[] array = (String[]) list.ToArray( typeof(String) );
127 Assert.AreEqual( "1,2", String.Join(",", array) );
130 [Test]
131 public void RemoveBoundary3()
133 LinkedList list = new LinkedList();
135 list.Add( "1" );
136 list.Add( "2" );
138 list.Remove( "2" );
140 Assert.AreEqual( "1", list.Head );
141 Assert.AreEqual( 1, list.Count );
143 String[] array = (String[]) list.ToArray( typeof(String) );
144 Assert.AreEqual( "1", String.Join(",", array) );
147 [Test]
148 public void RemoveMiddle1()
150 LinkedList list = new LinkedList();
152 list.Add( "1" );
154 list.Add( "2" );
156 list.Add( "3" );
158 list.Remove( "2" );
160 Assert.AreEqual( "1", list.Head );
161 Assert.AreEqual( 2, list.Count );
163 String[] array = (String[]) list.ToArray( typeof(String) );
164 Assert.AreEqual( "1,3", String.Join(",", array) );
167 [Test]
168 public void RemoveMiddle2()
170 LinkedList list = new LinkedList();
172 list.Add( "1" );
173 list.Add( "2" );
174 list.Add( "3" );
175 list.Add( "4" );
176 list.Add( "5" );
178 list.Remove( "3" );
180 Assert.AreEqual( "1", list.Head );
181 Assert.AreEqual( 4, list.Count );
183 String[] array = (String[]) list.ToArray( typeof(String) );
184 Assert.AreEqual( "1,2,4,5", String.Join(",", array) );
187 [Test]
188 public void IndexOf1()
190 LinkedList list = new LinkedList();
192 list.Add( "1" );
193 list.Add( "2" );
194 list.Add( "3" );
195 list.Add( "4" );
196 list.Add( "5" );
198 Assert.AreEqual( 0, list.IndexOf("1") );
199 Assert.AreEqual( -1, list.IndexOf("10") );
202 [Test]
203 public void IndexOf2()
205 LinkedList list = new LinkedList();
207 list.Add( "1" );
208 list.Add( "2" );
209 list.Add( "3" );
210 list.Add( "4" );
211 list.Add( "5" );
213 Assert.AreEqual( 4, list.IndexOf("5") );
214 Assert.AreEqual( -1, list.IndexOf("10") );
217 [Test]
218 public void Insert0()
220 LinkedList list = new LinkedList();
222 list.Add( "1" );
223 list.Add( "2" );
224 list.Add( "3" );
225 list.Insert(0, "x");
227 Assert.AreEqual( 4, list.Count );
229 String[] array = (String[]) list.ToArray( typeof(String) );
230 Assert.AreEqual( "x,1,2,3", String.Join(",", array) );
233 [Test]
234 public void Insert1()
236 LinkedList list = new LinkedList();
238 list.Add( "1" );
239 list.Add( "2" );
240 list.Add( "3" );
241 list.Insert(1, "x");
243 Assert.AreEqual( 4, list.Count );
245 String[] array = (String[]) list.ToArray( typeof(String) );
246 Assert.AreEqual( "1,x,2,3", String.Join(",", array) );
249 [Test]
250 public void Insert2()
252 LinkedList list = new LinkedList();
254 list.Add( "1" );
255 list.Add( "2" );
256 list.Add( "3" );
257 list.Insert(2, "x");
259 Assert.AreEqual( 4, list.Count );
261 String[] array = (String[]) list.ToArray( typeof(String) );
262 Assert.AreEqual( "1,2,x,3", String.Join(",", array) );
266 [Test]
267 public void Insert2bis()
269 LinkedList list = new LinkedList();
271 list.Add( "0" );
272 list.Add( "1" );
273 list.Add( "2" );
274 list.Add( "3" );
275 list.Add( "4" );
276 list.Add( "5" );
277 list.Insert(2, "x");
279 Assert.AreEqual( 7, list.Count );
281 String[] array = (String[]) list.ToArray( typeof(String) );
282 Assert.AreEqual( "0,1,x,2,3,4,5", String.Join(",", array) );
286 [Test]
287 public void Replace1()
289 LinkedList list = new LinkedList();
291 list.Add( "0" );
292 list.Add( "1" );
293 Assert.IsTrue( list.Replace("0", "x") );
295 Assert.AreEqual( 2, list.Count );
297 String[] array = (String[]) list.ToArray( typeof(String) );
298 Assert.AreEqual( "x,1", String.Join(",", array) );
301 [Test]
302 public void Replace2()
304 LinkedList list = new LinkedList();
306 list.Add( "0" );
307 list.Add( "1" );
308 Assert.IsTrue( list.Replace("1", "x") );
310 Assert.AreEqual( 2, list.Count );
312 String[] array = (String[]) list.ToArray( typeof(String) );
313 Assert.AreEqual( "0,x", String.Join(",", array) );
316 [Test]
317 public void Replace3()
319 LinkedList list = new LinkedList();
321 list.Add( "0" );
322 list.Add( "1" );
323 Assert.IsFalse( list.Replace("11", "x") );
325 Assert.AreEqual( 2, list.Count );
327 String[] array = (String[]) list.ToArray( typeof(String) );
328 Assert.AreEqual( "0,1", String.Join(",", array) );
331 [Test]
332 public void Replace4()
334 LinkedList list = new LinkedList();
336 list.Add( "0" );
337 list.Add( "1" );
338 list.Add( "2" );
339 list.Add( "3" );
340 Assert.IsTrue( list.Replace("2", "x") );
342 Assert.AreEqual( 4, list.Count );
344 String[] array = (String[]) list.ToArray( typeof(String) );
345 Assert.AreEqual( "0,1,x,3", String.Join(",", array) );
348 [Test]
349 public void ToArray()
351 LinkedList list = new LinkedList();
353 list.AddFirst( "third" );
354 list.AddFirst( "second" );
355 list.AddFirst( "first" );
357 String[] values = (String[]) list.ToArray( typeof(String) );
358 Assert.AreEqual( "first", values[0] );
359 Assert.AreEqual( "second", values[1] );
360 Assert.AreEqual( "third", values[2] );