Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,145 @@
2010-04-09 Raja R Harinath <harinath@hurrynot.org>
* SortedSetTest.cs (ViewCount): Test that count reflects changes
in underlying set.
2010-04-07 Raja R Harinath <harinath@hurrynot.org>
* SortedSetTest.cs: Update to test more view functionality,
including set comparison operators.
2010-04-06 Jb Evain <jbevain@novell.com>
* SortedSetTest.cs: add test for SortedSubSet.Count.
2010-04-05 Raja R Harinath <harinath@hurrynot.org>
* SortedSetTest.cs: Add test for various set comparison operators.
2010-04-04 Raja R Harinath <harinath@hurrynot.org>
* SortedSetTest.cs: Add tests for IntersectWith, UnionWith,
ExceptWith and SymmetricExceptWith.
2010-04-02 Jb Evain <jbevain@novell.com>
* SortedSetTest.cs: add tests for Min and Max on subsets.
2010-04-02 Jb Evain <jbevain@novell.com>
* SortedSetTest.cs: add tests for GetViewBetween.
2010-04-02 Jb Evain <jbevain@novell.com>
* SortedSetTest.cs: add tests for Min and Max.
2010-04-02 Jb Evain <jbevain@novell.com>
* SortedSetTest.cs: add test for RemoveWhere.
2010-04-02 Jb Evain <jbevain@novell.com>
* SortedSetTest.cs: add test for Reverse.
2010-04-02 Jb Evain <jbevain@novell.com>
* SortedSetTest.cs: add new fixture.
2009-12-01 Jb Evain <jbevain@novell.com>
* StackTest.cs: add a test ensuring that disposing the stack
enumerator prevents to iterate further.
2009-11-25 Jb Evain <jbevain@novell.com>
* QueueTest.cs: add test for a specific combination of
calls that make the queue crash when enqueuing an item.
2009-11-25 Jb Evain <jbevain@novell.com>
* QueueTest.cs: add tests for ICollection.CopyTo.
2009-07-31 Raja R Harinath <harinath@hurrynot.org>
* SortedDictionaryTest.cs (Enumerator_Current): New test.
(KeyEnumerator_Current, ValueEnumerator_Current): Likewise.
2009-07-14 Gonzalo Paniagua Javier <gonzalo@novell.com>
* SortedListTest.cs: new tests for bug #521750 provided by
Kevin Fitzgerald.
2009-05-10 Andrés G. Aragoneses <aaragoneses@novell.com>
* LinkedListTest.cs: Added test for #481621,
converted from example code by Andy Hume <andyhume32@yahoo.co.uk>.
2009-03-11 Zoltan Varga <vargaz@gmail.com>
* SortedListTest.cs: Add tests for #483985.
2009-05-06 Pia Eriksson <pe@hallerud.se>
* SortedListTest.cs: Added test for CopyTo
* LinkedListTest.cs: Test for CopyTo extended w. case when Count == 0
* LinkedListTest.cs: Test for CopyTo extended w. case when Count == 0
* QueueTest.cs: Test for CopyTo extended w. case when Count == 0
* StackTest.cs: Test for CopyTo extended w. case when Count == 0
* SortedDictionaryTest.cs: Added test for CopyTo on SortedDictionary,
SortedDictionary.Keys and SortedDictionary.Values
2007-08-20 Jb Evain <jbevain@novell.com>
* SortedListTest.cs: Tests for #82492.
2007-05-02 Raja R Harinath <harinath@gmail.com>
* SortedDictionaryTest.cs (AddNullKeyNullable): Enable.
2007-04-19 Gert Driesen <drieseng@users.sourceforge.net>
* QueueTest.cs: Removed usage of deprecated Assertion class. Added
test for TrimExcess. Added tests for binary serialization.
* StackTest.cs: Removed usage of deprecated Assertion class. Added
test for TrimExcess. Added tests for binary serialization.
2007-03-27 Alan McGovern <alan.mcgovern@gmail.com>
* QueueTest.cs: Fixed compilation and cosmetic changes
2007-02-08 Ilya Kharmatsky <ilyak -at- mainsoft.com>
* SortedDictionaryTest.cs: Added 'Ignore' attribute under
TARGET_JVM to workaround not working under Grasshopper test.
2007-01-25 Ilya Kharmatsky <ilyak -at- mainsoft.com>
* QueueTest.cs, StackTest.cs: Added 'Ignore' attribute under
TARGET_JVM to workaround Grasshopper's bug.
2006-11-15 Andrew Skiba <andrews@mainsoft.com>
* LinkedListTest.cs, QueueTest.cs, SortedListTest.cs, StackTest.cs:
TARGET_JVM to workaround CopyTo limitations.
2006-04-05 Atsushi Enomoto <atsushi@ximian.com>
* SortedDictionaryTest.cs : new test.
2005-11-10 Zoltan Varga <vargaz@gmail.com>
* StackTest.cs QueueTest.cs: Remove tests for removed TrimToSize ()
method.
2005-11-09 Zoltan Varga <vargaz@gmail.com>
* SortedListTest.cs: New file.
2005-09-04 David Waite <mass@akuma.org>
* LinkedListTest.cs: Added tests for LinkedList<T>
2005-05-13 Atsushi Enomoto <atsushi@ximian.com>
* QueueTest.cs, StackTest.cs: moved from mscorlib test.

View File

@@ -0,0 +1,344 @@
#if NET_2_0
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
namespace MonoTests.System.Collections.Generic
{
[TestFixture]
public class LinkedListTest
{
class EquatableValue : IEquatable<EquatableValue>
{
public readonly string Value;
public EquatableValue (string value)
{
this.Value = value;
}
public bool Equals (EquatableValue other)
{
if (other == null)
return false;
return string.Equals (Value, other.Value, StringComparison.OrdinalIgnoreCase);
}
}
LinkedList <int> intlist;
LinkedList <string> strings;
[SetUp]
public void Setup ()
{
intlist = new LinkedList <int> ();
// 2 3 4
intlist.AddLast (3);
intlist.AddLast (4);
intlist.AddFirst (2);
string [] tmpStrings = new string [] { "foo", "bar", "baz" };
// FIXME workaround for 74953
List <string> workaround = new List <string> ();
foreach (string s in tmpStrings)
workaround.Add (s);
// strings = new LinkedList <string> (tmpStrings);
strings = new LinkedList <string> (workaround);
}
[Test]
public void AddedTest ()
{
int i = 2;
foreach (int current in intlist)
{
Assert.AreEqual (i, current);
i++;
}
Assert.AreEqual (5, i);
}
[Test]
public void CreatedTest ()
{
string [] values = new string [] { "foo", "bar", "baz" };
int i = 0;
foreach (string current in strings)
{
Assert.AreEqual (values [i], current);
i++;
}
Assert.AreEqual (3, i);
}
[Test]
public void NonCircularNodeTest ()
{
LinkedListNode <int> node = intlist.First;
Assert.AreEqual (2, node.Value);
LinkedListNode <int> previous = node.Previous;
Assert.IsNull (previous);
node = node.Next;
Assert.IsNotNull (node);
Assert.AreEqual (3, node.Value);
node = node.Next;
Assert.IsNotNull (node);
Assert.AreEqual (4, node.Value);
node = node.Next;
Assert.IsNull (node);
}
[Test]
public void ClearTest ()
{
LinkedListNode <int> node = intlist.First;
intlist.Clear ();
Assert.AreEqual (0, intlist.Count);
Assert.AreEqual (2, node.Value);
Assert.IsNull (node.Next);
Assert.IsNull (node.Previous);
}
[Test]
public void ContainsTest ()
{
Assert.IsTrue (intlist.Contains (3));
Assert.IsFalse (intlist.Contains (5));
}
[Test]
public void AddBeforeAndAfterTest ()
{
LinkedListNode <int> node = intlist.Find (3);
intlist.AddAfter (node, new LinkedListNode <int> (5));
LinkedListNode <int> sixNode = intlist.AddAfter (node, 6);
LinkedListNode <int> sevenNode = intlist.AddBefore (node, 7);
intlist.AddBefore (node, new LinkedListNode <int> (8));
Assert.AreEqual (6, sixNode.Value);
Assert.AreEqual (7, sevenNode.Value);
// 2 7 8 3 6 5 4
int [] values = new int [] { 2, 7, 8, 3, 6, 5, 4 };
int i = 0;
foreach (int current in intlist)
{
Assert.AreEqual (values [i], current);
i++;
}
for (LinkedListNode <int> current = intlist.First; current != null; current = current.Next )
Assert.AreSame (intlist, current.List);
}
[Test]
public void CopyToTest ()
{
int [] values = new int [] { 2, 3, 4 };
int [] output = new int [3];
intlist.CopyTo (output, 0);
for (int i = 0; i < 3; i++)
Assert.AreEqual (values [i], output [i]);
LinkedList <int> l = new LinkedList <int> ();
values = new int [l.Count];
l.CopyTo (values, 0);
}
[Test]
public void FindTest ()
{
intlist.AddFirst (4);
LinkedListNode <int> head, tail;
head = intlist.Find (4);
tail = intlist.FindLast (4);
Assert.AreEqual (intlist.First, head);
Assert.AreEqual (intlist.Last, tail);
}
[Test]
public void RemoveTest ()
{
Assert.IsTrue (intlist.Remove (3));
Assert.AreEqual (2, intlist.Count);
int [] values = { 2, 4 };
int i = 0;
foreach (int current in intlist)
{
Assert.AreEqual (values [i], current);
i++;
}
Assert.IsFalse (intlist.Remove (5));
LinkedListNode <string> node = strings.Find ("baz");
strings.Remove (node);
Assert.IsNull (node.List);
Assert.IsNull (node.Previous);
Assert.IsNull (node.Next);
string [] values2 = { "foo", "bar" };
i = 0;
foreach (string current in strings)
{
Assert.AreEqual (values2 [i], current);
i++;
}
}
[Test, ExpectedException (typeof (ArgumentNullException))]
public void RemoveNullNodeTest ()
{
intlist.Remove (null);
}
[Test, ExpectedException (typeof (InvalidOperationException))]
public void RemoveInvalidNodeTest ()
{
intlist.Remove (new LinkedListNode <int> (4));
}
[Test]
public void RemoveFirstLastTest ()
{
strings.RemoveFirst ();
strings.RemoveLast ();
Assert.AreEqual (1, strings.Count);
Assert.AreEqual ("bar", strings.First.Value);
}
[Test]
public void ListSerializationTest ()
{
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, intlist);
stream.Position = 0;
object deserialized = formatter.Deserialize(stream);
Assert.IsTrue(deserialized is LinkedList <int>);
LinkedList <int> dlist = deserialized as LinkedList <int>;
int [] values = { 2, 3, 4 };
int i = 0;
foreach (int value in dlist)
{
Assert.AreEqual (values [i], value);
i++;
}
Assert.AreEqual(3, i);
}
/* FIXME: disabled pending fix for #75299
[Test]
*/
public void EnumeratorSerializationTest ()
{
BinaryFormatter formatter = new BinaryFormatter ();
MemoryStream stream = new MemoryStream ();
LinkedList<int>.Enumerator e = intlist.GetEnumerator ();
formatter.Serialize (stream, e);
stream.Position = 0;
object deserialized = formatter.Deserialize(stream);
Assert.IsTrue(deserialized is LinkedList <int>.Enumerator);
LinkedList <int>.Enumerator d = (LinkedList <int>.Enumerator) deserialized;
int [] values = { 2, 3, 4 };
int i = 0;
while (d.MoveNext ())
{
Assert.AreEqual (values [i], d.Current);
i++;
}
Assert.AreEqual(3, i);
}
public void EnumeratorAfterEnd ()
{
var linkedList = new LinkedList<string> ();
linkedList.AddLast ("a");
var e = linkedList.GetEnumerator ();
Assert.IsTrue (e.MoveNext (), "#1");
Assert.IsFalse (e.MoveNext (), "#2");
Assert.IsFalse (e.MoveNext (), "#3");
}
[Test] //bug 481621
public void PlayWithNullValues ()
{
LinkedList <string> li = new LinkedList <string> ();
li.AddLast ((string)null);
li.AddLast ("abcd");
li.AddLast ((string)null);
li.AddLast ("efgh");
Assert.AreEqual (4, li.Count);
Assert.AreEqual ("efgh", li.Last.Value);
Assert.IsNull (li.First.Value);
Assert.IsTrue (li.Remove ((string)null));
Assert.AreEqual (3, li.Count);
Assert.AreEqual ("efgh", li.Last.Value);
Assert.AreEqual ("abcd", li.First.Value);
Assert.IsTrue (li.Remove ((string)null));
Assert.AreEqual (2, li.Count);
Assert.AreEqual ("efgh", li.Last.Value);
Assert.AreEqual ("abcd", li.First.Value);
Assert.IsFalse (li.Remove ((string)null));
Assert.AreEqual (2, li.Count);
Assert.AreEqual ("efgh", li.Last.Value);
Assert.AreEqual ("abcd", li.First.Value);
}
[Test]
public void EqualityComparer ()
{
var list = new LinkedList<EquatableValue> ();
var mv = new EquatableValue ("first");
list.AddFirst (mv);
var test = new EquatableValue ("FIRST");
Assert.IsTrue (list.Contains (test), "#1");
Assert.AreSame (mv, list.Find (test).Value, "#2");
Assert.AreSame (mv, list.FindLast (test).Value, "#3");
}
[Test]
public void RemoveFromEmptyList ()
{
var linkedList = new LinkedList<string> ();
try {
linkedList.RemoveFirst ();
Assert.Fail ("#1");
} catch (InvalidOperationException) {
}
try {
linkedList.RemoveLast ();
Assert.Fail ("#1");
} catch (InvalidOperationException) {
}
}
}
}
#endif

View File

@@ -0,0 +1,382 @@
//
// Queue.cs
//
// Author:
// Ben Maurer (bmaurer@ximian.com)
//
#if NET_2_0
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
namespace MonoTests.System.Collections.Generic {
[TestFixture]
public class QueueTest
{
[Test]
public void TestCtor ()
{
Queue <int> a = new Queue <int> ();
Queue <int> b = new Queue <int> (1);
Queue <object> c = new Queue <object> ();
Queue <object> d = new Queue <object> (1);
Queue <object> e = new Queue <object> (0);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void TestCtorEx ()
{
Queue <int> a = new Queue <int> (-1);
}
[Test]
public void TestCtorEnum ()
{
List <int> l = new List <int> ();
l.Add (1);
l.Add (2);
l.Add (3);
Queue <int> s = new Queue <int> (l);
AssertDequeue (s, 1);
AssertDequeue (s, 2);
AssertDequeue (s, 3);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestCtorEnumNull ()
{
Queue <int> s = new Queue <int> (null);
}
[Test]
public void TestClear()
{
Queue <int> s = new Queue <int> ();
s.Clear ();
Assert.AreEqual (0, s.Count, "#1");
s.Enqueue (1);
s.Enqueue (2);
Assert.AreEqual (2, s.Count, "#2");
s.Clear ();
Assert.AreEqual (0, s.Count, "#3");
IEnumerator enumerator = s.GetEnumerator();
s.Clear();
try {
enumerator.Reset();
Assert.Fail ("#4");
} catch(InvalidOperationException) {
}
}
[Test]
public void TestContains ()
{
Stack <int> s = new Stack <int> ();
Assert.IsFalse (s.Contains (1), "#1");
s.Push (1);
Assert.IsTrue (s.Contains (1), "#2");
Assert.IsFalse (s.Contains (0), "#3");
}
[Test]
public void TestCopyTo ()
{
int [] x = new int [3];
Queue <int> z = new Queue <int> ();
z.Enqueue (1);
z.Enqueue (2);
x [0] = 10;
z.CopyTo (x, 1);
Assert.AreEqual (10, x [0], "#1");
Assert.AreEqual (1, x [1], "#2");
Assert.AreEqual (2, x [2], "#3");
z = new Queue <int> ();
x = new int [z.Count];
z.CopyTo (x, 0);
}
[Test]
public void TestICollectionCopyTo ()
{
var queue = new Queue<int> ();
((ICollection) queue).CopyTo (new int [0], 0);
queue.Enqueue (1);
queue.Enqueue (2);
var array = new int [queue.Count];
((ICollection) queue).CopyTo (array, 0);
Assert.AreEqual (1, array [0]);
Assert.AreEqual (2, array [1]);
array = new int [queue.Count + 1];
array [0] = 42;
((ICollection) queue).CopyTo (array, 1);
Assert.AreEqual (42, array [0]);
Assert.AreEqual (1, array [1]);
Assert.AreEqual (2, array [2]);
}
[Test]
public void TestPeek ()
{
Queue <int> s = new Queue <int> ();
s.Enqueue (1);
Assert.AreEqual (1, s.Peek (), "#1");
Assert.AreEqual (1, s.Count, "#2");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestPeekEx ()
{
Queue <int> s = new Queue <int> ();
s.Peek ();
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestPeekEx2 ()
{
Queue <int> s = new Queue <int> ();
s.Enqueue (1);
s.Dequeue ();
s.Peek ();
}
[Test]
public void TestDequeue ()
{
Queue <int> s = new Queue <int> ();
s.Enqueue (1);
Assert.AreEqual (1, s.Dequeue (), "#1");
Assert.AreEqual (0, s.Count, "#2");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestDequeueEx ()
{
Queue <int> s = new Queue <int> ();
s.Dequeue ();
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestDequeueEx2 ()
{
Queue <int> s = new Queue <int> ();
s.Enqueue (1);
s.Dequeue ();
s.Dequeue ();
}
[Test]
public void TestEnqueue ()
{
Queue <int> s = new Queue <int> ();
s.Enqueue (1);
Assert.AreEqual (1, s.Count, "#1");
s.Enqueue (2);
Assert.AreEqual (2, s.Count, "#2");
for (int i = 0; i < 100; i ++)
s.Enqueue (i);
Assert.AreEqual (102, s.Count, "#3");
}
[Test]
public void TestToArray ()
{
Queue <int> s = new Queue <int> ();
int [] x = s.ToArray ();
Assert.AreEqual (0, x.Length, "#1");
s.Enqueue (1);
x = s.ToArray ();
Assert.AreEqual (1, x.Length, "#2");
Assert.AreEqual (1, x [0], "#3");
}
[Test]
public void TestEnumerator ()
{
Queue <int> s = new Queue <int> ();
foreach (int x in s)
Assert.Fail ("#1" + x);
s.Enqueue (1);
int i = 0;
foreach (int x in s) {
Assert.AreEqual (0, i, "#2");
Assert.AreEqual (1, x, "#3");
i ++;
}
for (i = 2; i < 100; i ++)
s.Enqueue (i);
i = 1;
foreach (int x in s) {
Assert.AreEqual (i, x, "#4");
i ++;
}
}
[Test]
public void TrimExcessTest ()
{
Queue <int> s = new Queue <int> ();
s.TrimExcess ();
Assert.AreEqual (0, s.Count, "#1");
s.Enqueue (1);
s.Enqueue (3);
Assert.AreEqual (1, s.Dequeue (), "#2");
Assert.AreEqual (3, s.Peek (), "#3");
s.TrimExcess ();
Assert.AreEqual (1, s.Count, "#4");
Assert.AreEqual (3, s.Peek (), "#5");
s.Enqueue (2);
Assert.AreEqual (3, s.Dequeue (), "#6");
Assert.AreEqual (2, s.Dequeue (), "#7");
s.TrimExcess ();
Assert.AreEqual (0, s.Count, "#8");
}
[Test]
public void TrimExcessDequeueEnqueue ()
{
var queue = new Queue<int> ();
queue.Enqueue (1);
queue.Enqueue (2);
queue.Enqueue (3);
queue.TrimExcess ();
Assert.AreEqual (1, queue.Dequeue ());
queue.Enqueue (4);
Assert.AreEqual (2, queue.Dequeue ());
Assert.AreEqual (3, queue.Dequeue ());
Assert.AreEqual (4, queue.Dequeue ());
Assert.AreEqual (0, queue.Count);
}
[Test]
[Category ("NotWorking")] // bug #80649
public void SerializeTest ()
{
Queue <int> s = new Queue <int> ();
s.Enqueue (1);
s.Enqueue (3);
s.Enqueue (2);
s.Dequeue ();
BinaryFormatter bf = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, s);
byte [] buffer = new byte [ms.Length];
ms.Position = 0;
ms.Read (buffer, 0, buffer.Length);
Assert.AreEqual (_serializedQueue, buffer);
}
[Test]
#if TARGET_JVM
[Category ("NotWorking")]
#endif
public void DeserializeTest ()
{
MemoryStream ms = new MemoryStream ();
ms.Write (_serializedQueue, 0, _serializedQueue.Length);
ms.Position = 0;
BinaryFormatter bf = new BinaryFormatter ();
Queue<int> s = (Queue<int>) bf.Deserialize (ms);
Assert.AreEqual (2, s.Count, "#1");
Assert.AreEqual (3, s.Dequeue (), "#2");
Assert.AreEqual (2, s.Dequeue (), "#3");
}
void AssertDequeue <T> (Queue <T> s, T t)
{
Assert.AreEqual (t, s.Dequeue ());
}
static byte [] _serializedQueue = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x02, 0x00, 0x00, 0x00,
0x49, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2c, 0x20, 0x56, 0x65,
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x32, 0x2e, 0x30, 0x2e, 0x30,
0x2e, 0x30, 0x2c, 0x20, 0x43, 0x75, 0x6c, 0x74, 0x75, 0x72, 0x65,
0x3d, 0x6e, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6c, 0x2c, 0x20, 0x50,
0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x54, 0x6f, 0x6b,
0x65, 0x6e, 0x3d, 0x62, 0x37, 0x37, 0x61, 0x35, 0x63, 0x35, 0x36,
0x31, 0x39, 0x33, 0x34, 0x65, 0x30, 0x38, 0x39, 0x05, 0x01, 0x00,
0x00, 0x00, 0x7f, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43,
0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e,
0x47, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x2e, 0x51, 0x75, 0x65,
0x75, 0x65, 0x60, 0x31, 0x5b, 0x5b, 0x53, 0x79, 0x73, 0x74, 0x65,
0x6d, 0x2e, 0x49, 0x6e, 0x74, 0x33, 0x32, 0x2c, 0x20, 0x6d, 0x73,
0x63, 0x6f, 0x72, 0x6c, 0x69, 0x62, 0x2c, 0x20, 0x56, 0x65, 0x72,
0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x32, 0x2e, 0x30, 0x2e, 0x30, 0x2e,
0x30, 0x2c, 0x20, 0x43, 0x75, 0x6c, 0x74, 0x75, 0x72, 0x65, 0x3d,
0x6e, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6c, 0x2c, 0x20, 0x50, 0x75,
0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x54, 0x6f, 0x6b, 0x65,
0x6e, 0x3d, 0x62, 0x37, 0x37, 0x61, 0x35, 0x63, 0x35, 0x36, 0x31,
0x39, 0x33, 0x34, 0x65, 0x30, 0x38, 0x39, 0x5d, 0x5d, 0x05, 0x00,
0x00, 0x00, 0x06, 0x5f, 0x61, 0x72, 0x72, 0x61, 0x79, 0x05, 0x5f,
0x68, 0x65, 0x61, 0x64, 0x05, 0x5f, 0x74, 0x61, 0x69, 0x6c, 0x05,
0x5f, 0x73, 0x69, 0x7a, 0x65, 0x08, 0x5f, 0x76, 0x65, 0x72, 0x73,
0x69, 0x6f, 0x6e, 0x07, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08,
0x08, 0x08, 0x02, 0x00, 0x00, 0x00, 0x09, 0x03, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
0x00, 0x05, 0x00, 0x00, 0x00, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b };
}
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,347 @@
//
// StackTest.cs
//
// Author:
// Ben Maurer (bmaurer@ximian.com)
//
#if NET_2_0
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
namespace MonoTests.System.Collections.Generic
{
[TestFixture]
public class StackTest
{
[Test]
public void TestCtor ()
{
Stack <int> a = new Stack <int> ();
Stack <int> b = new Stack <int> (1);
Stack <object> c = new Stack <object> ();
Stack <object> d = new Stack <object> (1);
Stack <object> e = new Stack <object> (0);
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void TestCtorEx ()
{
new Stack <int> (-1);
}
[Test]
public void TestCtorEnum ()
{
List <int> l = new List <int> ();
l.Add (1);
l.Add (2);
l.Add (3);
Stack <int> s = new Stack <int> (l);
// Things get pop'd in reverse
AssertPop (s, 3);
AssertPop (s, 2);
AssertPop (s, 1);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestCtorEnumNull ()
{
new Stack <int> (null);
}
[Test]
public void TestClear()
{
Stack <int> s = new Stack <int> ();
s.Clear ();
Assert.AreEqual (0, s.Count, "#1");
s.Push (1);
s.Push (2);
Assert.AreEqual (2, s.Count, "#2");
s.Clear ();
Assert.AreEqual (0, s.Count, "#3");
}
[Test]
public void TestContains ()
{
Stack <int> s = new Stack <int> ();
Assert.IsFalse (s.Contains (1), "#1");
s.Push (1);
Assert.IsTrue (s.Contains (1), "#2");
Assert.IsFalse (s.Contains (0), "#3");
}
[Test]
public void TestCopyTo ()
{
int [] x = new int [3];
Stack <int> z = new Stack <int> ();
z.Push (1);
z.Push (2);
x [0] = 10;
z.CopyTo (x, 1);
Assert.AreEqual (10, x [0], "#1");
Assert.AreEqual (2, x [1], "#2");
Assert.AreEqual (1, x [2], "#3");
z = new Stack <int> ();
x = new int [z.Count];
z.CopyTo (x, 0);
ICollection c = new Stack <int> ();
x = new int [c.Count];
c.CopyTo (x, 0);
}
[Test]
public void TestPeek ()
{
Stack <int> s = new Stack <int> ();
s.Push (1);
Assert.AreEqual (1, s.Peek (), "#1");
Assert.AreEqual (1, s.Count, "#2");
IEnumerator enumerator = s.GetEnumerator();
s.Peek();
enumerator.Reset();
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestPeekEx ()
{
Stack <int> s = new Stack <int> ();
s.Peek ();
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestPeekEx2 ()
{
Stack <int> s = new Stack <int> ();
s.Push (1);
s.Pop ();
s.Peek ();
}
[Test]
public void TestPop ()
{
Stack <int> s = new Stack <int> ();
s.Push (1);
Assert.AreEqual (1, s.Pop (), "#1");
Assert.AreEqual (0, s.Count, "#2");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestPopEx ()
{
Stack <int> s = new Stack <int> ();
s.Pop ();
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void TestPopEx2 ()
{
Stack <int> s = new Stack <int> ();
s.Push (1);
s.Pop ();
s.Pop ();
}
[Test]
public void TestPush ()
{
Stack <int> s = new Stack <int> ();
s.Push (1);
Assert.AreEqual (1, s.Count, "#1");
s.Push (2);
Assert.AreEqual (2, s.Count, "#2");
for (int i = 0; i < 100; i ++)
s.Push (i);
Assert.AreEqual (102, s.Count, "#3");
}
[Test]
public void TestToArray ()
{
Stack <int> s = new Stack <int> ();
int [] x = s.ToArray ();
Assert.AreEqual (0, x.Length, "#1");
s.Push (1);
x = s.ToArray ();
Assert.AreEqual (1, x.Length, "#2");
Assert.AreEqual (1, x [0], "#3");
}
[Test]
public void TestEnumerator ()
{
Stack <int> s = new Stack <int> ();
foreach (int x in s)
Assert.Fail ("#1:" + x);
s.Push (1);
int i = 0;
foreach (int x in s) {
Assert.AreEqual (0, i, "#2");
Assert.AreEqual (1, x, "#3");
i ++;
}
i = 0;
s.Push (2);
s.Push (3);
foreach (int x in s) {
Assert.AreEqual (3 - i, x, "#4");
Assert.IsTrue (i < 3, "#5");
i ++;
}
}
[Test]
public void DisposeEnumerator ()
{
var stack = new Stack<int> ();
stack.Push (1);
stack.Push (2);
var enumerator = stack.GetEnumerator ();
Assert.IsTrue (enumerator.MoveNext ());
enumerator.Dispose ();
Assert.IsFalse (enumerator.MoveNext ());
}
[Test]
public void TrimExcessTest ()
{
Stack <int> s = new Stack <int> ();
s.TrimExcess ();
Assert.AreEqual (0, s.Count, "#1");
s.Push (1);
s.Push (3);
Assert.AreEqual (3, s.Pop (), "#2");
Assert.AreEqual (1, s.Peek (), "#3");
s.TrimExcess ();
Assert.AreEqual (1, s.Count, "#4");
Assert.AreEqual (1, s.Peek (), "#5");
s.Push (2);
Assert.AreEqual (2, s.Pop (), "#6");
Assert.AreEqual (1, s.Pop (), "#7");
s.TrimExcess ();
Assert.AreEqual (0, s.Count, "#8");
}
[Test]
[Category ("NotWorking")] // bug #80649
public void SerializeTest ()
{
Stack <int> s = new Stack <int> ();
s.Push (1);
s.Push (3);
s.Push (2);
s.Pop ();
BinaryFormatter bf = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, s);
byte [] buffer = new byte [ms.Length];
ms.Position = 0;
ms.Read (buffer, 0, buffer.Length);
Assert.AreEqual (_serializedStack, buffer);
}
[Test]
#if TARGET_JVM
[Category ("NotWorking")]
#endif // TARGET_JVM
public void DeserializeTest ()
{
MemoryStream ms = new MemoryStream ();
ms.Write (_serializedStack, 0, _serializedStack.Length);
ms.Position = 0;
BinaryFormatter bf = new BinaryFormatter ();
Stack<int> s = (Stack<int>) bf.Deserialize (ms);
Assert.AreEqual (2, s.Count, "#1");
Assert.AreEqual (3, s.Pop (), "#2");
Assert.AreEqual (1, s.Pop (), "#3");
}
void AssertPop <T> (Stack <T> s, T t)
{
Assert.AreEqual (t, s.Pop ());
}
static byte [] _serializedStack = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x02, 0x00, 0x00, 0x00,
0x49, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2c, 0x20, 0x56, 0x65,
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x32, 0x2e, 0x30, 0x2e, 0x30,
0x2e, 0x30, 0x2c, 0x20, 0x43, 0x75, 0x6c, 0x74, 0x75, 0x72, 0x65,
0x3d, 0x6e, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6c, 0x2c, 0x20, 0x50,
0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x54, 0x6f, 0x6b,
0x65, 0x6e, 0x3d, 0x62, 0x37, 0x37, 0x61, 0x35, 0x63, 0x35, 0x36,
0x31, 0x39, 0x33, 0x34, 0x65, 0x30, 0x38, 0x39, 0x05, 0x01, 0x00,
0x00, 0x00, 0x7f, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2e, 0x43,
0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e,
0x47, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x2e, 0x53, 0x74, 0x61,
0x63, 0x6b, 0x60, 0x31, 0x5b, 0x5b, 0x53, 0x79, 0x73, 0x74, 0x65,
0x6d, 0x2e, 0x49, 0x6e, 0x74, 0x33, 0x32, 0x2c, 0x20, 0x6d, 0x73,
0x63, 0x6f, 0x72, 0x6c, 0x69, 0x62, 0x2c, 0x20, 0x56, 0x65, 0x72,
0x73, 0x69, 0x6f, 0x6e, 0x3d, 0x32, 0x2e, 0x30, 0x2e, 0x30, 0x2e,
0x30, 0x2c, 0x20, 0x43, 0x75, 0x6c, 0x74, 0x75, 0x72, 0x65, 0x3d,
0x6e, 0x65, 0x75, 0x74, 0x72, 0x61, 0x6c, 0x2c, 0x20, 0x50, 0x75,
0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x54, 0x6f, 0x6b, 0x65,
0x6e, 0x3d, 0x62, 0x37, 0x37, 0x61, 0x35, 0x63, 0x35, 0x36, 0x31,
0x39, 0x33, 0x34, 0x65, 0x30, 0x38, 0x39, 0x5d, 0x5d, 0x03, 0x00,
0x00, 0x00, 0x06, 0x5f, 0x61, 0x72, 0x72, 0x61, 0x79, 0x05, 0x5f,
0x73, 0x69, 0x7a, 0x65, 0x08, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69,
0x6f, 0x6e, 0x07, 0x00, 0x00, 0x08, 0x08, 0x08, 0x02, 0x00, 0x00,
0x00, 0x09, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b };
}
}
#endif