2010-04-02 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System / Test / System.Collections.Generic / SortedSetTest.cs
bloba4b4c523732898d692afdf883db58106c40dda19
1 //
2 // SortedSetTest.cs
3 //
4 // Author:
5 // Jb Evain <jbevain@novell.com>
6 //
7 // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #if NET_4_0
31 using System;
32 using System.Collections;
33 using System.Collections.Generic;
34 using System.Linq;
35 using System.Runtime.Serialization;
37 using NUnit.Framework;
39 namespace MonoTests.System.Collections.Generic
41 [TestFixture]
42 public class SortedSetTest
44 [Test]
45 public void CtorNullComparer ()
47 var set = new SortedSet<int> ((IComparer<int>) null);
48 Assert.AreEqual (Comparer<int>.Default, set.Comparer);
51 [Test]
52 [ExpectedException (typeof (ArgumentNullException))]
53 public void CtorNullCollection ()
55 new SortedSet<int> (null as IEnumerable<int>);
58 [Test]
59 public void CtorDefault ()
61 var set = new SortedSet<int> ();
62 Assert.IsNotNull (set.Comparer);
65 [Test]
66 public void Add ()
68 var set = new SortedSet<int> ();
69 Assert.AreEqual (0, set.Count);
70 Assert.IsTrue (set.Add (2));
71 Assert.IsTrue (set.Add (4));
72 Assert.IsTrue (set.Add (3));
73 Assert.AreEqual (3, set.Count);
74 Assert.IsFalse (set.Add (2));
77 [Test]
78 public void Remove ()
80 var set = new SortedSet<int> ();
81 Assert.IsTrue (set.Add (2));
82 Assert.IsTrue (set.Add (4));
83 Assert.AreEqual (2, set.Count);
84 Assert.IsTrue (set.Remove (4));
85 Assert.IsTrue (set.Remove (2));
86 Assert.AreEqual (0, set.Count);
87 Assert.IsFalse (set.Remove (4));
88 Assert.IsFalse (set.Remove (2));
91 [Test]
92 public void Clear ()
94 var set = new SortedSet<int> { 2, 3, 4, 5 };
95 Assert.AreEqual (4, set.Count);
96 set.Clear ();
97 Assert.AreEqual (0, set.Count);
100 [Test]
101 public void Contains ()
103 var set = new SortedSet<int> { 2, 3, 4, 5 };
104 Assert.IsTrue (set.Contains (4));
105 Assert.IsFalse (set.Contains (7));
108 [Test]
109 public void GetEnumerator ()
111 var set = new SortedSet<int> { 5, 3, 1, 2, 6, 4 };
112 Assert.IsTrue (set.SequenceEqual (new [] { 1, 2, 3, 4, 5, 6 }));
115 [Test]
116 public void Reverse ()
118 var set = new SortedSet<int> { 5, 3, 1, 2, 6, 4 };
119 var reversed = set.Reverse ();
120 Assert.IsTrue (reversed.SequenceEqual (new [] { 6, 5, 4, 3, 2, 1 }));
125 #endif