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,61 @@
2010-07-13 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* RegistryKeyTest.cs: New tests for volatile keys.
2008-02-01 Gert Driesen <drieseng@users.sourceforge.net>
* RegistryKeyTest.cs: Added tests for max length of subkey and value
names. Improved existing argument check tests. Renamed existing
SetValue tests, and added simple tests for overload introduced in
.NET 2.0.
2007-11-07 Atsushi Enomoto <atsushi@ximian.com>
* RegistryKeyTest.cs : enabled bug #322839 test.
2007-10-14 Gert Driesen <drieseng@users.sourceforge.net>
* RegistryKeyTest.cs: Added test for bug #322839.
2007-08-30 Gert Driesen <drieseng@users.sourceforge.net>
* RegistryKeyTest.cs: Improve SetValue tests to ensure values are
persisted properly on Linux, since the unix implementation performs
caching.
2006-09-03 Gert Driesen <drieseng@users.sourceforge.net>
* RegistryKeyTest.cs: Added RunningOnUnix property that is used
to skip tests that only need to be run on Windows. Added tests Close
tests for local/remote registry hives and keys. Added tests for
OpenRemoteBaseKey (Windows only).
2006-08-23 Gert Driesen <drieseng@users.sourceforge.net>
* RegistryKeyTest.cs: Modified GetValueNamesTest and GetSubKeyNamesTest
to verify whether the buffer is cleared while iterating over values
and keys.
2006-08-20 Gert Driesen <drieseng@users.sourceforge.net>
* RegistryKeyTest.cs: Added test for expanding environment variables.
2006-08-14 Gert Driesen <drieseng@users.sourceforge.net>
* RegistryKeyTest.cs: Added large batch of tests.
2006-05-28 Gert Driesen <drieseng@users.sourceforge.net>
* RegistryKeyTest.cs: Added test for bug #78519.
2006-04-20 Gert Driesen <drieseng@users.sourceforge.net>
* RegistryKeyTest.cs: Added tests for bug #78132.
2006-04-18 Gert Driesen <drieseng@users.sourceforge.net>
* RegistryKeyTest.cs: Added tests for OpenSubKey and CreateSubKey.
2006-01-14 Robert Jordan <robertj@gmx.net>
* RegistryKeyTest.cs: Added unit test for bug #77212.

View File

@@ -0,0 +1 @@
e4e38befd16529ef227dec132fab73663e37d8b2

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections;
using System.Text;
using NUnit.Framework;
using Mono;
#if !MOBILE
using NUnit.Framework.SyntaxHelpers;
#endif
namespace MonoTests {
[TestFixture]
public class DataConverterTest
{
const string TEST_STRING = "Alignment test";
static string Dump (byte [] d)
{
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < d.Length; i++){
sb.Append (String.Format ("{0:x2} ", d [i]));
}
return sb.ToString ().Trim ();
}
[Test]
public void PackTests ()
{
Assert.AreEqual (Dump (DataConverter.Pack ("z8", "hello")), "68 65 6c 6c 6f 00");
Assert.AreEqual (Dump (DataConverter.Pack ("z6", "hello")), "68 00 65 00 6c 00 6c 00 6f 00 00 00");
Assert.AreEqual (Dump (DataConverter.Pack ("CCCC", 65, 66, 67, 68)), "41 42 43 44");
Assert.AreEqual (Dump (DataConverter.Pack ("4C", 65, 66, 67, 68, 69, 70)), "41 42 43 44");
Assert.AreEqual (Dump (DataConverter.Pack ("^iii", 0x1234abcd, 0x7fadb007)), "12 34 ab cd 7f ad b0 07 00 00 00 00");
Assert.AreEqual (Dump (DataConverter.Pack ("_s!i", 0x7b, 0x12345678)), "7b 00 00 00 78 56 34 12");
}
[Test]
public void ArrayTests ()
{
byte [] source = new byte [] { 1, 2, 3, 4 };
byte [] dest = new byte [4];
int l = DataConverter.Int32FromBE (source, 0);
Assert.AreEqual (l, 0x01020304);
}
[Test]
public void StringAlignment ()
{
byte[] packed = Mono.DataConverter.Pack ("bz8", 1, TEST_STRING);
IList unpacked = Mono.DataConverter.Unpack ("bz8", packed, 0);
Assert.AreEqual(1, (byte) unpacked[0]);
Assert.AreEqual(TEST_STRING, new string((char[]) unpacked[1]));
}
[Test]
public void UnpackTests ()
{
float f = (float)DataConverter.Unpack ("%f", DataConverter.Pack ("f", 3.14), 0) [0];
Assert.That ((f - 3.14f), Is.LessThanOrEqualTo (Single.Epsilon));
}
}
}

View File

@@ -0,0 +1,63 @@
2010-06-03 Jérémie Laval <jeremie.laval@gmail.com>
* CollectionStressTestHelper.cs: Bump remove test repeat to 1000.
Use a local variable for tracking status and only update the global one
at the end.
2010-03-24 Jérémie Laval <jeremie.laval@gmail.com>
* ConcurrentDictionaryTests.cs: Renaming in Assert
2010-03-24 Jérémie Laval <jeremie.laval@gmail.com>
* ConcurrentDictionaryTests.cs: Update behavior of TryAddDuplicateTest
The method returns false and doesn't throw exception anymore
2010-02-02 Jérémie Laval <jeremie.laval@gmail.com>
* CollectionStressTestHelper.cs:
* ConcurrentBagTests.cs:
* ConcurrentDictionaryTests.cs:
* ConcurrentQueueTests.cs:
* ConcurrentSkipListTests.cs:
* ConcurrentStackTests.cs:
* ParallelConcurrentQueueTests.cs:
* ParallelConcurrentStackTests.cs: Update namespaces and tested methods
2009-08-11 Jérémie Laval <jeremie.laval@gmail.com>
* BlockingCollectionTests.cs: Moved file.
2009-08-05 Jérémie Laval <jeremie.laval@gmail.com>
* ConcurrentDictionaryTests.cs: Re-enable ConcurrentDictionary unit
tests.
2009-08-04 Raja R Harinath <harinath@hurrynot.org>
* ParallelConcurrentQueueTests.cs (CountTestCase): Remove call to
internal method.
2009-07-31 Jérémie Laval <jeremie.laval@gmail.com>
* ConcurrentDictionary: Ignore tests until runtime/compiler
is fixed
2009-07-31 Jérémie Laval <jeremie.laval@gmail.com>
* ConcurrentDictionary.cs:
* ConcurrentQueue.cs: Adapt test to new API
2009-07-27 Jérémie Laval <jeremie.laval@gmail.com>
* BlockingCollectionTests.cs:
* CollectionStressTestHelper.cs:
* ConcurrentBagTests.cs:
* ConcurrentDictionaryTests.cs:
* ConcurrentQueueTests.cs:
* ConcurrentSkipListTests.cs:
* ConcurrentStackTests.cs:
* ParallelConcurrentQueueTests.cs:
* ParallelConcurrentStackTests.cs: ParallelFx unit tests for
System.Collections.Concurrent namespace.

View File

@@ -0,0 +1,129 @@
#if NET_4_0
//
// CollectionStressTestHelper.cs
//
// Author:
// Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
//
// Copyright (c) 2009 Jérémie "Garuma" Laval
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Threading;
using System.Linq;
using MonoTests.System.Threading.Tasks;
using NUnit;
using NUnit.Framework;
using NUnit.Framework.Constraints;
namespace MonoTests.System.Collections.Concurrent
{
public enum CheckOrderingType {
InOrder,
Reversed,
DontCare
}
public static class CollectionStressTestHelper
{
public static void AddStressTest (IProducerConsumerCollection<int> coll)
{
ParallelTestHelper.Repeat (delegate {
int amount = -1;
const int count = 10;
const int threads = 5;
ParallelTestHelper.ParallelStressTest (coll, (q) => {
int t = Interlocked.Increment (ref amount);
for (int i = 0; i < count; i++)
coll.TryAdd (t);
}, threads);
Assert.AreEqual (threads * count, coll.Count, "#-1");
int[] values = new int[threads];
int temp;
while (coll.TryTake (out temp)) {
values[temp]++;
}
for (int i = 0; i < threads; i++)
Assert.AreEqual (count, values[i], "#" + i);
});
}
public static void RemoveStressTest (IProducerConsumerCollection<int> coll, CheckOrderingType order)
{
ParallelTestHelper.Repeat (delegate {
const int count = 10;
const int threads = 5;
const int delta = 5;
for (int i = 0; i < (count + delta) * threads; i++)
while (!coll.TryAdd (i));
bool state = true;
Assert.AreEqual ((count + delta) * threads, coll.Count, "#0");
ParallelTestHelper.ParallelStressTest (coll, (q) => {
bool s = true;
int t;
for (int i = 0; i < count; i++) {
s &= coll.TryTake (out t);
// try again in case it was a transient failure
if (!s && coll.TryTake (out t))
s = true;
}
if (!s)
state = false;
}, threads);
Assert.IsTrue (state, "#1");
Assert.AreEqual (delta * threads, coll.Count, "#2");
string actual = string.Empty;
int temp;
while (coll.TryTake (out temp)) {
actual += temp.ToString ();;
}
IEnumerable<int> range = Enumerable.Range (order == CheckOrderingType.Reversed ? 0 : count * threads, delta * threads);
if (order == CheckOrderingType.Reversed)
range = range.Reverse ();
string expected = range.Aggregate (string.Empty, (acc, v) => acc + v);
if (order == CheckOrderingType.DontCare)
Assert.That (actual, new CollectionEquivalentConstraint (expected), "#3");
else
Assert.AreEqual (expected, actual, "#3");
}, 10);
}
}
}
#endif

View File

@@ -0,0 +1,358 @@
#if NET_4_0
// ConcurrentDictionaryTests.cs
//
// Copyright (c) 2008 Jérémie "Garuma" Laval
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//
using System;
using System.Linq;
using System.Threading;
using MonoTests.System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Concurrent;
using NUnit;
using NUnit.Framework;
#if !MOBILE
using NUnit.Framework.SyntaxHelpers;
#endif
namespace MonoTests.System.Collections.Concurrent
{
[TestFixture]
public class ConcurrentDictionaryTests
{
ConcurrentDictionary<string, int> map;
[SetUp]
public void Setup ()
{
map = new ConcurrentDictionary<string, int> ();
AddStuff();
}
void AddStuff ()
{
map.TryAdd ("foo", 1);
map.TryAdd ("bar", 2);
map["foobar"] = 3;
}
[Test]
public void AddWithoutDuplicateTest ()
{
map.TryAdd("baz", 2);
int val;
Assert.IsTrue (map.TryGetValue("baz", out val));
Assert.AreEqual(2, val);
Assert.AreEqual(2, map["baz"]);
Assert.AreEqual(4, map.Count);
}
[Test]
public void AddParallelWithoutDuplicateTest ()
{
ParallelTestHelper.Repeat (delegate {
Setup ();
int index = 0;
ParallelTestHelper.ParallelStressTest (map, delegate {
int own = Interlocked.Increment (ref index);
while (!map.TryAdd ("monkey" + own.ToString (), own));
}, 4);
Assert.AreEqual (7, map.Count);
int value;
Assert.IsTrue (map.TryGetValue ("monkey1", out value), "#1");
Assert.AreEqual (1, value, "#1b");
Assert.IsTrue (map.TryGetValue ("monkey2", out value), "#2");
Assert.AreEqual (2, value, "#2b");
Assert.IsTrue (map.TryGetValue ("monkey3", out value), "#3");
Assert.AreEqual (3, value, "#3b");
Assert.IsTrue (map.TryGetValue ("monkey4", out value), "#4");
Assert.AreEqual (4, value, "#4b");
});
}
[Test]
public void RemoveParallelTest ()
{
ParallelTestHelper.Repeat (delegate {
Setup ();
int index = 0;
bool r1 = false, r2 = false, r3 = false;
int val;
ParallelTestHelper.ParallelStressTest (map, delegate {
int own = Interlocked.Increment (ref index);
switch (own) {
case 1:
r1 = map.TryRemove ("foo", out val);
break;
case 2:
r2 =map.TryRemove ("bar", out val);
break;
case 3:
r3 = map.TryRemove ("foobar", out val);
break;
}
}, 3);
Assert.AreEqual (0, map.Count);
int value;
Assert.IsTrue (r1, "1");
Assert.IsTrue (r2, "2");
Assert.IsTrue (r3, "3");
Assert.IsFalse (map.TryGetValue ("foo", out value), "#1b " + value.ToString ());
Assert.IsFalse (map.TryGetValue ("bar", out value), "#2b");
Assert.IsFalse (map.TryGetValue ("foobar", out value), "#3b");
});
}
[Test]
public void AddWithDuplicate()
{
Assert.IsFalse (map.TryAdd("foo", 6));
}
[Test]
public void GetValueTest()
{
Assert.AreEqual(1, map["foo"], "#1");
Assert.AreEqual(2, map["bar"], "#2");
Assert.AreEqual(3, map.Count, "#3");
}
[Test, ExpectedException(typeof(KeyNotFoundException))]
public void GetValueUnknownTest()
{
int val;
Assert.IsFalse(map.TryGetValue("barfoo", out val));
val = map["barfoo"];
}
[Test]
public void ModificationTest()
{
map["foo"] = 9;
int val;
Assert.AreEqual(9, map["foo"], "#1");
Assert.IsTrue(map.TryGetValue("foo", out val), "#3");
Assert.AreEqual(9, val, "#4");
}
[Test]
public void IterateTest ()
{
string[] keys = { "foo", "bar", "foobar" };
int[] occurence = new int[3];
foreach (var kvp in map) {
int index = Array.IndexOf (keys, kvp.Key);
Assert.AreNotEqual (-1, index, "#a");
Assert.AreEqual (index + 1, kvp.Value, "#b");
Assert.That (++occurence[index], Is.LessThan (2), "#c");
}
}
[Test]
public void GetOrAddTest ()
{
Assert.AreEqual (1, map.GetOrAdd ("foo", (_) => 12));
Assert.AreEqual (13, map.GetOrAdd ("baz", (_) => 13));
}
[Test]
public void TryUpdateTest ()
{
Assert.IsFalse (map.TryUpdate ("foo", 12, 11));
Assert.AreEqual (1, map["foo"]);
Assert.IsTrue (map.TryUpdate ("foo", 11, 1));
Assert.AreEqual (11, map["foo"]);
}
[Test]
public void AddOrUpdateTest ()
{
Assert.AreEqual (11, map.AddOrUpdate ("bar", (_) => 12, (_, __) => 11));
Assert.AreEqual (12, map.AddOrUpdate ("baz", (_) => 12, (_, __) => 11));
}
[Test]
public void ContainsTest ()
{
Assert.IsTrue (map.ContainsKey ("foo"));
Assert.IsTrue (map.ContainsKey ("bar"));
Assert.IsTrue (map.ContainsKey ("foobar"));
Assert.IsFalse (map.ContainsKey ("baz"));
Assert.IsFalse (map.ContainsKey ("oof"));
}
class DumbClass : IEquatable<DumbClass>
{
int foo;
public DumbClass (int foo)
{
this.foo = foo;
}
public int Foo {
get {
return foo;
}
}
public override bool Equals (object rhs)
{
DumbClass temp = rhs as DumbClass;
return temp == null ? false : Equals (temp);
}
public bool Equals (DumbClass rhs)
{
return this.foo == rhs.foo;
}
public override int GetHashCode ()
{
return 5;
}
}
[Test]
public void SameHashCodeInsertTest ()
{
var classMap = new ConcurrentDictionary<DumbClass, string> ();
var class1 = new DumbClass (1);
var class2 = new DumbClass (2);
Assert.IsTrue (classMap.TryAdd (class1, "class1"), "class 1");
Console.WriteLine ();
Assert.IsTrue (classMap.TryAdd (class2, "class2"), "class 2");
Assert.AreEqual ("class1", classMap[class1], "class 1 check");
Assert.AreEqual ("class2", classMap[class2], "class 2 check");
}
[Test]
public void InitWithEnumerableTest ()
{
int[] data = {1,2,3,4,5,6,7,8,9,10};
var ndic = data.ToDictionary (x => x);
var cdic = new ConcurrentDictionary<int, int> (ndic);
foreach (var index in data) {
Assert.IsTrue (cdic.ContainsKey (index));
int val;
Assert.IsTrue (cdic.TryGetValue (index, out val));
Assert.AreEqual (index, val);
}
}
[Test]
public void QueryWithSameHashCodeTest ()
{
var ids = new long[] {
34359738370,
34359738371,
34359738372,
34359738373,
34359738374,
34359738375,
34359738376,
34359738377,
34359738420
};
var dict = new ConcurrentDictionary<long, long>();
long result;
for (var i = 0; i < 20; i++)
dict[-i] = -i * 1000;
foreach (var id in ids)
Assert.IsFalse (dict.TryGetValue (id, out result), id.ToString ());
foreach (var id in ids) {
Assert.IsTrue (dict.TryAdd (id, id));
Assert.AreEqual (id, dict[id]);
}
foreach (var id in ids) {
Assert.IsTrue (dict.TryRemove (id, out result));
Assert.AreEqual (id, result);
}
foreach (var id in ids)
Assert.IsFalse (dict.TryGetValue (id, out result), id.ToString () + " (second)");
}
[Test]
public void NullArgumentsTest ()
{
AssertThrowsArgumentNullException (() => { var x = map[null]; });
AssertThrowsArgumentNullException (() => map[null] = 0);
AssertThrowsArgumentNullException (() => map.AddOrUpdate (null, k => 0, (k, v) => v));
AssertThrowsArgumentNullException (() => map.AddOrUpdate ("", null, (k, v) => v));
AssertThrowsArgumentNullException (() => map.AddOrUpdate ("", k => 0, null));
AssertThrowsArgumentNullException (() => map.AddOrUpdate (null, 0, (k, v) => v));
AssertThrowsArgumentNullException (() => map.AddOrUpdate ("", 0, null));
AssertThrowsArgumentNullException (() => map.ContainsKey (null));
AssertThrowsArgumentNullException (() => map.GetOrAdd (null, 0));
int value;
AssertThrowsArgumentNullException (() => map.TryGetValue (null, out value));
AssertThrowsArgumentNullException (() => map.TryRemove (null, out value));
AssertThrowsArgumentNullException (() => map.TryUpdate (null, 0, 0));
}
[Test]
public void IDictionaryNullOnNonExistingKey ()
{
IDictionary dict = new ConcurrentDictionary<long, string> ();
object val = dict [1234L];
Assert.IsNull (val);
}
void AssertThrowsArgumentNullException (Action action)
{
try {
action ();
Assert.Fail ("Expected ArgumentNullException.");
} catch (ArgumentNullException ex) {
}
}
}
}
#endif

View File

@@ -0,0 +1,220 @@
#if NET_4_0
// ConcurrentQueueTest.cs
//
// Copyright (c) 2008 Jérémie "Garuma" Laval
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//
using System;
using System.Linq;
using System.Threading;
using System.Collections.Generic;
using System.Collections.Concurrent;
using NUnit.Framework;
namespace MonoTests.System.Collections.Concurrent
{
[TestFixture()]
public class ConcurrentQueueTests
{
ConcurrentQueue<int> queue;
[SetUpAttribute]
public void Setup()
{
queue = new ConcurrentQueue<int>();
for (int i = 0; i < 10; i++) {
queue.Enqueue(i);
}
}
[Test]
public void StressEnqueueTestCase ()
{
/*ParallelTestHelper.Repeat (delegate {
queue = new ConcurrentQueue<int> ();
int amount = -1;
const int count = 10;
const int threads = 5;
ParallelTestHelper.ParallelStressTest (queue, (q) => {
int t = Interlocked.Increment (ref amount);
for (int i = 0; i < count; i++)
queue.Enqueue (t);
}, threads);
Assert.AreEqual (threads * count, queue.Count, "#-1");
int[] values = new int[threads];
int temp;
while (queue.TryDequeue (out temp)) {
values[temp]++;
}
for (int i = 0; i < threads; i++)
Assert.AreEqual (count, values[i], "#" + i);
});*/
CollectionStressTestHelper.AddStressTest (new ConcurrentQueue<int> ());
}
[Test]
public void StressDequeueTestCase ()
{
/*ParallelTestHelper.Repeat (delegate {
queue = new ConcurrentQueue<int> ();
const int count = 10;
const int threads = 5;
const int delta = 5;
for (int i = 0; i < (count + delta) * threads; i++)
queue.Enqueue (i);
bool state = true;
ParallelTestHelper.ParallelStressTest (queue, (q) => {
int t;
for (int i = 0; i < count; i++)
state &= queue.TryDequeue (out t);
}, threads);
Assert.IsTrue (state, "#1");
Assert.AreEqual (delta * threads, queue.Count, "#2");
string actual = string.Empty;
int temp;
while (queue.TryDequeue (out temp)) {
actual += temp;
}
string expected = Enumerable.Range (count * threads, delta * threads)
.Aggregate (string.Empty, (acc, v) => acc + v);
Assert.AreEqual (expected, actual, "#3");
});*/
CollectionStressTestHelper.RemoveStressTest (new ConcurrentQueue<int> (), CheckOrderingType.InOrder);
}
[Test]
public void CountTestCase()
{
Assert.AreEqual(10, queue.Count, "#1");
int value;
queue.TryPeek(out value);
queue.TryDequeue(out value);
queue.TryDequeue(out value);
Assert.AreEqual(8, queue.Count, "#2");
}
//[Ignore]
[Test]
public void EnumerateTestCase()
{
string s = string.Empty;
foreach (int i in queue) {
s += i;
}
Assert.AreEqual("0123456789", s, "#1 : " + s);
}
[Test()]
public void TryPeekTestCase()
{
int value;
queue.TryPeek(out value);
Assert.AreEqual(0, value, "#1 : " + value);
queue.TryDequeue(out value);
Assert.AreEqual(0, value, "#2 : " + value);
queue.TryDequeue(out value);
Assert.AreEqual(1, value, "#3 : " + value);
queue.TryPeek(out value);
Assert.AreEqual(2, value, "#4 : " + value);
queue.TryPeek(out value);
Assert.AreEqual(2, value, "#5 : " + value);
}
[Test()]
public void TryDequeueTestCase()
{
int value;
queue.TryPeek(out value);
Assert.AreEqual(0, value, "#1");
Assert.IsTrue(queue.TryDequeue(out value), "#2");
Assert.IsTrue(queue.TryDequeue(out value), "#3");
Assert.AreEqual(1, value, "#4");
}
[Test()]
public void TryDequeueEmptyTestCase()
{
int value;
queue = new ConcurrentQueue<int> ();
queue.Enqueue(1);
Assert.IsTrue(queue.TryDequeue(out value), "#1");
Assert.IsFalse(queue.TryDequeue(out value), "#2");
Assert.IsTrue(queue.IsEmpty, "#3");
}
[Test]
public void ToArrayTest()
{
int[] array = queue.ToArray();
string s = string.Empty;
foreach (int i in array) {
s += i;
}
Assert.AreEqual("0123456789", s, "#1 : " + s);
queue.CopyTo(array, 0);
s = string.Empty;
foreach (int i in array) {
s += i;
}
Assert.AreEqual("0123456789", s, "#2 : " + s);
}
[Test, ExpectedException (typeof (ArgumentNullException))]
public void ToExistingArray_Null ()
{
queue.CopyTo (null, 0);
}
[Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
public void ToExistingArray_OutOfRange ()
{
queue.CopyTo (new int[3], -1);
}
[Test, ExpectedException (typeof (ArgumentException))]
public void ToExistingArray_IndexOverflow ()
{
queue.CopyTo (new int[3], 4);
}
[Test, ExpectedException (typeof (ArgumentException))]
public void ToExistingArray_Overflow ()
{
queue.CopyTo (new int[3], 0);
}
}
}
#endif

View File

@@ -0,0 +1,306 @@
#if NET_4_0
// ConcurrentStackTests.cs
//
// Copyright (c) 2008 Jérémie "Garuma" Laval
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//
using System;
using System.Threading;
using System.Linq;
using System.Collections.Concurrent;
using NUnit.Framework;
using NUnit.Framework.Constraints;
namespace MonoTests.System.Collections.Concurrent
{
[TestFixture()]
public class ConcurrentStackTests
{
ConcurrentStack<int> stack;
[SetUpAttribute]
public void Setup()
{
stack = new ConcurrentStack<int>();
for (int i = 0; i < 10; i++) {
stack.Push(i);
}
}
[Test]
public void StressPushTestCase ()
{
/*ParallelTestHelper.Repeat (delegate {
stack = new ConcurrentStack<int> ();
int amount = -1;
const int count = 10;
const int threads = 5;
ParallelTestHelper.ParallelStressTest (stack, (q) => {
int t = Interlocked.Increment (ref amount);
for (int i = 0; i < count; i++)
stack.Push (t);
}, threads);
Assert.AreEqual (threads * count, stack.Count, "#-1");
int[] values = new int[threads];
int temp;
while (stack.TryPop (out temp)) {
values[temp]++;
}
for (int i = 0; i < threads; i++)
Assert.AreEqual (count, values[i], "#" + i);
});*/
CollectionStressTestHelper.AddStressTest (new ConcurrentStack<int> ());
}
[Test]
public void StressPopTestCase ()
{
/*ParallelTestHelper.Repeat (delegate {
stack = new ConcurrentStack<int> ();
const int count = 10;
const int threads = 5;
const int delta = 5;
for (int i = 0; i < (count + delta) * threads; i++)
stack.Push (i);
bool state = true;
ParallelTestHelper.ParallelStressTest (stack, (q) => {
int t;
for (int i = 0; i < count; i++)
state &= stack.TryPop (out t);
}, threads);
Assert.IsTrue (state, "#1");
Assert.AreEqual (delta * threads, stack.Count, "#2");
string actual = string.Empty;
int temp;
while (stack.TryPop (out temp)) {
actual += temp;
}
string expected = Enumerable.Range (0, delta * threads).Reverse()
.Aggregate (string.Empty, (acc, v) => acc + v);
Assert.AreEqual (expected, actual, "#3");
});*/
CollectionStressTestHelper.RemoveStressTest (new ConcurrentStack<int> (), CheckOrderingType.Reversed);
}
[Test]
public void CountTestCase()
{
Assert.IsTrue(stack.Count == 10, "#1");
int value;
stack.TryPeek(out value);
stack.TryPop(out value);
stack.TryPop(out value);
Assert.IsTrue(stack.Count == 8, "#2");
stack.Clear();
Assert.IsTrue(stack.Count == 0, "#3");
Assert.IsTrue(stack.IsEmpty, "#4");
}
[Test()]
public void EnumerateTestCase()
{
string s = string.Empty;
foreach (int i in stack) {
s += i;
}
Assert.IsTrue(s == "9876543210", "#1 : " + s);
}
[Test()]
public void TryPeekTestCase()
{
int value;
stack.TryPeek(out value);
Assert.IsTrue(value == 9, "#1 : " + value);
stack.TryPop(out value);
Assert.IsTrue(value == 9, "#2 : " + value);
stack.TryPop(out value);
Assert.IsTrue(value == 8, "#3 : " + value);
stack.TryPeek(out value);
Assert.IsTrue(value == 7, "#4 : " + value);
stack.TryPeek(out value);
Assert.IsTrue(value == 7, "#5 : " + value);
}
[Test()]
public void TryPopTestCase()
{
int value;
stack.TryPeek(out value);
Assert.IsTrue(value == 9, "#1");
stack.TryPop(out value);
stack.TryPop(out value);
Assert.IsTrue(value == 8, "#2 : " + value);
}
[Test()]
public void TryPopEmptyTestCase()
{
int value;
stack.Clear();
stack.Push(1);
Assert.IsTrue(stack.TryPop(out value), "#1");
Assert.IsFalse(stack.TryPop(out value), "#2");
Assert.IsTrue(stack.IsEmpty, "#3");
}
[Test]
public void ToArrayTest()
{
int[] array = stack.ToArray();
string s = string.Empty;
foreach (int i in array) {
s += i;
}
Assert.IsTrue(s == "9876543210", "#1 : " + s);
stack.CopyTo(array, 0);
s = string.Empty;
foreach (int i in array) {
s += i;
}
Assert.IsTrue(s == "9876543210", "#1 : " + s);
}
[Test, ExpectedException (typeof (ArgumentNullException))]
public void ToExistingArray_Null ()
{
stack.CopyTo (null, 0);
}
[Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
public void ToExistingArray_OutOfRange ()
{
stack.CopyTo (new int[3], -1);
}
[Test, ExpectedException (typeof (ArgumentException))]
public void ToExistingArray_IndexOverflow ()
{
stack.CopyTo (new int[3], 4);
}
[Test, ExpectedException (typeof (ArgumentException))]
public void ToExistingArray_Overflow ()
{
stack.CopyTo (new int[3], 0);
}
[Test]
public void TryPopRangeTest ()
{
int[] values = new int[3];
Assert.AreEqual (3, stack.TryPopRange (values));
Assert.That (values, new CollectionEquivalentConstraint (new int[] { 9, 8, 7 }));
Assert.AreEqual (10 - values.Length, stack.Count);
for (int i = 9 - values.Length; i >= 0; i--) {
int outValue;
Assert.IsTrue (stack.TryPop (out outValue));
Assert.AreEqual (i, outValue);
}
}
[Test]
public void TryPopRangeEmpty ()
{
stack = new ConcurrentStack<int>();
Assert.AreEqual (0, stack.TryPopRange (new int [1]));
}
[Test]
public void TryPopRangeTestWithOneElement ()
{
int[] values = new int[1];
Assert.AreEqual (1, stack.TryPopRange (values));
Assert.That (values, new CollectionEquivalentConstraint (new int[] { 9 }));
Assert.AreEqual (10 - values.Length, stack.Count);
for (int i = 9 - values.Length; i >= 0; i--) {
int outValue;
Assert.IsTrue (stack.TryPop (out outValue));
Assert.AreEqual (i, outValue);
}
}
[Test]
public void TryPopRangeFullTest ()
{
int[] values = new int[10];
Assert.AreEqual (10, stack.TryPopRange (values));
Assert.That (values, new CollectionEquivalentConstraint (Enumerable.Range (0, 10).Reverse ()));
Assert.AreEqual (0, stack.Count);
}
[Test]
public void TryPopRangePartialFillTest ()
{
int[] values = new int[5];
Assert.AreEqual (2, stack.TryPopRange (values, 3, 2));
Assert.That (values, new CollectionEquivalentConstraint (new int[] { 0, 0, 0, 9, 8 }));
Assert.AreEqual (8, stack.Count);
}
[Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
public void TryPopRange_NegativeIndex ()
{
stack.TryPopRange (new int[3], -2, 3);
}
[Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
public void TryPopRange_LargeIndex ()
{
stack.TryPopRange (new int[3], 200, 3);
}
[Test, ExpectedException (typeof (ArgumentException))]
public void TryPopRange_LargeCount ()
{
stack.TryPopRange (new int[3], 2, 5);
}
[Test, ExpectedException (typeof (ArgumentNullException))]
public void TryPopRange_NullArray ()
{
stack.TryPopRange (null);
}
[Test]
public void PushRangeTestCase()
{
var testStack = new ConcurrentStack<int>();
var testData = new int[] { 1, 2, 3, 4, 5 };
testStack.PushRange (testData);
Assert.AreEqual (testData.Length, testStack.Count);
}
}
}
#endif

View File

@@ -0,0 +1,59 @@
#if NET_4_0
// ParallelConcurrentQueueTests.cs
//
// Copyright (c) 2008 Jérémie "Garuma" Laval
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//
using System;
using System.Collections.Concurrent;
using MonoTests.System.Threading.Tasks;
using NUnit.Framework;
namespace MonoTests.System.Collections.Concurrent
{
[TestFixture()]
public class ParallelConcurrentQueueTests
{
ConcurrentQueue<int> queue;
[SetUpAttribute]
public void Setup()
{
queue = new ConcurrentQueue<int>();
}
[Test]
public void CountTestCase()
{
const int numThread = 5;
ParallelTestHelper.ParallelAdder(queue, numThread);
Assert.AreEqual(10 * numThread, queue.Count, "#1");
int value;
queue.TryPeek(out value);
ParallelTestHelper.ParallelRemover(queue, numThread, 3);
Assert.AreEqual(10 * numThread - 3, queue.Count, "#2");
}
}
}
#endif

View File

@@ -0,0 +1,62 @@
#if NET_4_0
// ParallelConcurrentStackTests.cs
//
// Copyright (c) 2008 Jérémie "Garuma" Laval
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//
using System;
using MonoTests.System.Threading.Tasks;
using System.Collections.Concurrent;
using NUnit.Framework;
namespace MonoTests.System.Collections.Concurrent
{
[TestFixture()]
public class ParallelConcurrentStackTests
{
ConcurrentStack<int> stack;
[SetUpAttribute]
public void Setup()
{
stack = new ConcurrentStack<int>();
}
[Test]
public void CountTestCase()
{
const int numThread = 5;
ParallelTestHelper.ParallelAdder(stack, numThread);
Assert.AreEqual(10 * numThread, stack.Count, "#1");
int value;
stack.TryPeek(out value);
ParallelTestHelper.ParallelRemover(stack, numThread, 3);
Assert.AreEqual(10 * numThread - 3, stack.Count, "#2");
stack.Clear();
Assert.AreEqual(0, stack.Count, "#3");
Assert.IsTrue(stack.IsEmpty, "#4");
}
}
}
#endif

View File

@@ -0,0 +1,96 @@
//
// PartitionerTests.cs
//
// Author:
// Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
//
// Copyright (c) 2009 Jérémie "Garuma" Laval
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#if NET_4_0
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using NUnit.Framework;
#if !MOBILE
using NUnit.Framework.SyntaxHelpers;
#endif
namespace MonoTests.System.Collections.Concurrent
{
[TestFixture]
public class PartitionerTests
{
[Test]
public void PartitionerCreateIntegerWithExplicitRange ()
{
OrderablePartitioner<Tuple<int, int>> partitioner = Partitioner.Create (1, 20, 5);
var partitions = partitioner.GetOrderablePartitions (3);
Assert.AreEqual (3, partitions.Count);
Assert.That (partitions, Is.All.Not.Null);
var iterator = partitions[0];
Assert.IsTrue (iterator.MoveNext ());
Assert.IsTrue (iterator.Current.Equals (Create (0, 1, 6)));
Assert.IsTrue (iterator.MoveNext ());
Assert.IsTrue (iterator.Current.Equals (Create (1, 6, 11)));
Assert.IsTrue (iterator.MoveNext ());
Assert.IsTrue (iterator.Current.Equals (Create (2, 11, 16)));
Assert.IsTrue (iterator.MoveNext ());
Assert.IsTrue (iterator.Current.Equals (Create (3, 16, 20)));
Assert.IsFalse (partitions[1].MoveNext ());
Assert.IsFalse (partitions[2].MoveNext ());
}
[Test]
public void PartitionerCreateLongWithExplicitRange ()
{
OrderablePartitioner<Tuple<long, long>> partitioner = Partitioner.Create ((long)1, (long)20, (long)5);
var partitions = partitioner.GetOrderablePartitions (3);
Assert.AreEqual (3, partitions.Count);
Assert.That (partitions, Is.All.Not.Null);
var iterator = partitions[0];
Assert.IsTrue (iterator.MoveNext ());
Assert.IsTrue (iterator.Current.Equals (CreateL (0, 1, 6)));
Assert.IsTrue (iterator.MoveNext ());
Assert.IsTrue (iterator.Current.Equals (CreateL (1, 6, 11)));
Assert.IsTrue (iterator.MoveNext ());
Assert.IsTrue (iterator.Current.Equals (CreateL (2, 11, 16)));
Assert.IsTrue (iterator.MoveNext ());
Assert.IsTrue (iterator.Current.Equals (CreateL (3, 16, 20)));
Assert.IsFalse (partitions[1].MoveNext ());
Assert.IsFalse (partitions[2].MoveNext ());
}
static KeyValuePair<long, Tuple<int, int>> Create (long ind, int i1, int i2)
{
return new KeyValuePair<long, Tuple<int, int>> (ind, Tuple.Create (i1, i2));
}
static KeyValuePair<long, Tuple<long, long>> CreateL (long ind, long i1, long i2)
{
return new KeyValuePair<long, Tuple<long, long>> (ind, Tuple.Create (i1, i2));
}
}
}
#endif

View File

@@ -0,0 +1,228 @@
2010-01-24 Robert Jordan <robertj@gmx.net>
* DictionaryTest.cs: Add test case for bug #474009.
2009-09-22 Raja R Harinath <harinath@hurrynot.org>
* DictionaryTest.cs (ICollectionCopyTo): Test various odd
scenarios where .NET CopyTo does _not_ throw an exception.
(ICollectionCopyTo_ex1..4): Ensure that ArgumentExceptions are
thrown in appropriate cases.
2009-07-31 Raja R Harinath <harinath@hurrynot.org>
* ListTest.cs: Add a few testcases for IList interface, using null
values with a List<int>.
2009-07-31 Raja R Harinath <harinath@hurrynot.org>
* DictionaryTest.cs (KeyEnumerator_Current): New test. Test the
Keys slice enumerator.
(ValueEnumerator_Current): Likewise, for the Values slice.
2009-07-30 Raja R Harinath <harinath@hurrynot.org>
* ListTest.cs (Enumerator_Current): New test, includes
relevant parts of #491858 and #517415.
2009-07-30 Raja R Harinath <harinath@hurrynot.org>
* DictionaryTest.cs (Enumerator_Current): New test, includes
relevant parts of #491858 and #517415.
2009-04-02 Jb Evain <jbevain@novell.com>
* DictionaryTest.cs: add test for bug #328036.
2008-11-14 Jb Evain <jbevain@novell.com>
* DictionaryTest.cs: add tests for #444778.
2008-11-14 Jb Evain <jbevain@novell.com>
* DictionaryTest.cs: add tests for bug #444768.
2008-10-06 Zoltan Varga <vargaz@gmail.com>
* DictionaryTest.cs: Add a test for #432441.
2008-09-29 Jb Evain <jbevain@novell.com>
* DictionaryTest.cs: test for null argument for ContainsKey.
Patch by Jonathan Anderson <jonathan.l.anderson@gmail.com>
2008-09-24 Jb Evain <jbevain@novell.com>
* DictionaryTest.cs: add tests for bug #429530.
2008-09-12 Jb Evain <jbevain@novell.com>
* DictionaryTest.cs: add tests for #425693.
2008-06-16 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
* DictionaryTest.cs: Add test for an incompatibility
2008-04-30 Gert Driesen <drieseng@users.sourceforge.net>
* DictionaryTest.cs: Added not working tests for bug #384723. Spaces
to tabs.
2008-03-21 Sebastien Pouliot <sebastien@ximian.com>
* EqualityComparerTest.cs: New. Add test cases for using null with
GetHashCode (bug #372892).
2008-01-06 Zoltan Varga <vargaz@gmail.com>
* ListTest.cs: Make some tests public.
2007-11-05 Sebastien Pouliot <sebastien@ximian.com>
* DictionaryTest.cs: Test case for #322783 based on Francisco Moraes
sample code.
2006-04-16 Jonathan Chambers <joncham@gmail.com>
* ListTest.cs: Test Contains after Remove.
Test for bug #81387.
2007-03-08 Gert Driesen <drieseng@users.sourceforge.net>
* ComparerTest.cs: Added test for bug #80929. Added tests to verify
binary serialization compatibility.
* IListTest.cs: Fixed header.
2007-03-07 Gert Driesen <drieseng@users.sourceforge.net>
* IListTest.cs: Added test for bug #80260.
2006-09-12 Gert Driesen <drieseng@users.sourceforge.net>
* ListTest.cs: Added tests for binary serialization, and Enumerator
version checks.
2006-05-08 Atsushi Enomoto <atsushi@ximian.com>
* ListTest.cs : test for bug #77277 by Kazuki Oikawa.
2006-03-16 Ankit Jain <jankit@novell.com>
* ListTest.cs: Add some tests for InsertRange.
2006-01-23 Raja R Harinath <rharinath@novell.com>
* DictionaryTest.cs (IDictionary_*): Add a few tests for the
IDictionary explicit implementation.
2006-01-19 Raja R Harinath <rharinath@novell.com>
* DictionaryTest.cs: Remove NotWorking annotations.
(Empty_CopyTo, Empty_Values_CopyTo): Fix tests to check that
CopyTo from an empty dictionary does not throw an exception when
'index==array.Length'.
(PlainEnumeratorReturnTest): Check the type of 'Entry' property too.
2006-01-19 Atsushi Enomoto <atsushi@ximian.com>
* DictionaryTest.cs : fixed several tests to not fail under .NET 2.0
and thus marked some as NotWorking. Numbered some assertions.
2005-12-21 Sebastien Pouliot <sebastien@ximian.com>
* ListTest.cs: Added test cases for #77039 for sorting a list with
IComparable (generic or not) and without IComparable (exception).
2005-12-20 Sebastien Pouliot <sebastien@ximian.com>
* ListTest.cs: Added test case for #76361 for sorting the list with a
generic comparer.
2005-12-19 Sebastien Pouliot <sebastien@ximian.com>
* DictionaryTest.cs: Added test cases for CopyTo, including a test for
DictionaryEntry.
* ListTest.cs: Added test case for #77019 when copying from an empty
dictionary.
2005-12-19 Sebastien Pouliot <sebastien@ximian.com>
* ListTest.cs: Added test case for a binary search with an empty list
(bug #77030). Removed IsReadOnly test case as this isn't part of the
public API anymore.
2005-08-16 Martin Baulig <martin@ximian.com>
* DictionaryTest.cs (IEnumeratorGenericTest): Reflect latest
`KeyValuePair<K,V>' API changes.
2005-06-27 Raja R Harinath <rharinath@novell.com>
* DictionaryTest.cs (FailFastTest1, FailFastTest2, FailFastTest3):
New tests to ensure that enumerators are invalidated on
modifications to the dictionary.
2005-06-22 Raja R Harinath <rharinath@novell.com>
* DictionaryTest.cs (KeyValueEnumeratorTest): Add test for infloop
if dictionary is read while it's being enumerated.
2005-06-20 David Waite <mass@akuma.org>
* ListTest.cs: Substantial new tests
2005-06-18 David Waite <mass@akuma.org>
* DictionaryTest.cs (AddTest3): Added test of simple interaction with
struct dictionary
(AddDuplicateTest,IndexerGetNullTest,IndexerSetNullTest): Added tests
for exceptional cases to verify correct exceptions
(TryGetValueTest): check return value from TryGetValue
(KeyValueEnumeratorTest): Added test from verification of ms.net beta2
behavior for non-generic IEnumerator/IDictionaryEnumerator behavior
against Dictionary<>
(SerializationTest): Added test to utilize serialization routines.
2005-06-16 Raja R Harinath <rharinath@novell.com>
* DictionaryTest.cs (SliceCollectionsEnumeratorTest): New test
based on #75053.
2005-06-07 Ankit Jain <ankit@corewars.org>
* DictionaryTest.cs (KeyValueEnumeratorTest): Added new test.
2005-05-19 Raja R Harinath <rharinath@novell.com>
* ListTest.cs (TestGetRange): Add missing ';'. Actually compare
the length of the list.
2005-05-18 Miguel de Icaza <miguel@novell.com>
* ListTest.cs: Added.
2005-05-13 Atsushi Enomoto <atsushi@ximian.com>
* QueueTest.cs, StackTest.cs: They are now in System.dll
2005-05-05 Raja R Harinath <rharinath@novell.com>
* DictionaryTest.cs (MyTest.GetHashCode): Add to silence a
compiler warning.
2005-04-04 Raja R Harinath <rharinath@novell.com>
* DictionaryTest.cs: Update.
2005-04-02 Ben Maurer <bmaurer@ximian.com>
* DictionaryTest.cs: new test.
2005-01-29 Ben Maurer <bmaurer@ximian.com>
* QueueTest.cs: new Test.
2004-12-27 Ben Maurer <bmaurer@ximian.com>
* StackTest.cs: new Test.

View File

@@ -0,0 +1,148 @@
//
// MonoTests.System.Collections.Generic.Test.ComparerTest
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// Copyright (C) 2007 Gert Driesen
// Copyright 2011 Xamarin Inc (http://www.xamarin.com).
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NUnit.Framework;
using System;
namespace MonoTests.System.Collections.Generic
{
[TestFixture]
public class ComparerTest
{
class CustomComparer : IComparable, IComparable<object>
{
int IComparable<object>.CompareTo (object other)
{
throw new NotImplementedException ();
}
int IComparable.CompareTo (object obj)
{
return 9;
}
}
#if NET_4_5
[Test]
public void Create ()
{
var comparer = Comparer<int>.Create ((a, b) => a - b);
Assert.AreEqual (-1, comparer.Compare (1, 2), "#1");
}
[Test]
public void Create_Invalid ()
{
try {
Comparer<int>.Create (null);
Assert.Fail ("#1");
} catch (ArgumentNullException) {
}
}
#endif
[Test]
public void DefaultComparer_UserComparable ()
{
IComparer c = Comparer<object>.Default;
Assert.AreEqual (-9, c.Compare (new object (), new CustomComparer ()), "#1");
Assert.AreEqual (9, c.Compare (new CustomComparer (), new object ()), "#2");
}
[Test]
public void DefaultComparer_NotComparableArgument ()
{
IComparer c = Comparer<object>.Default;
try {
c.Compare (new object (), new object ());
Assert.Fail ("#1");
} catch (ArgumentException) {
}
var o = new object ();
Assert.AreEqual (0, c.Compare (o, o), "#2");
}
#if !NET_4_0 // FIXME: the blob contains the 2.0 mscorlib version
[Test] // bug #80929
public void SerializeDefault ()
{
Comparer<int> c = Comparer<int>.Default;
BinaryFormatter bf = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
bf.Serialize (ms, c);
byte [] buffer = new byte [ms.Length];
ms.Position = 0;
ms.Read (buffer, 0, buffer.Length);
Assert.AreEqual (_serializedDefault, buffer);
}
#endif
[Test]
public void DeserializeDefault ()
{
MemoryStream ms = new MemoryStream ();
ms.Write (_serializedDefault, 0, _serializedDefault.Length);
ms.Position = 0;
BinaryFormatter bf = new BinaryFormatter ();
Comparer<int> c = (Comparer<int>) bf.Deserialize (ms);
Assert.IsNotNull (c);
}
private static readonly byte [] _serializedDefault = new byte [] {
0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00,
0x89, 0x01, 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, 0x47, 0x65, 0x6e, 0x65,
0x72, 0x69, 0x63, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x72, 0x65, 0x72,
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, 0x00, 0x00, 0x00, 0x00,
0x0b };
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,66 @@
//
// Unit tests for System.Collections.Generic.EqualityComparer
//
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
namespace MonoTests.System.Collections.Generic {
[TestFixture]
public class EqualityComparerTest {
[Test]
public void Default_GetHashCode_Null ()
{
// https://bugzilla.novell.com/show_bug.cgi?id=372892
Assert.AreEqual (0, EqualityComparer<object>.Default.GetHashCode (null), "object");
Assert.AreEqual (0, EqualityComparer<string>.Default.GetHashCode (null), "string");
}
[Test]
public void NonGenericGetHashCodeForNullArgument ()
{
IEqualityComparer comparer = EqualityComparer<object>.Default;
Assert.AreEqual (0, comparer.GetHashCode (null));
}
[Test] // #703027
public void NonGenericEqualsForNullArguments ()
{
IEqualityComparer comparer = EqualityComparer<object>.Default;
Assert.IsTrue (comparer.Equals (null, null));
}
}
}
#endif

View File

@@ -0,0 +1,53 @@
//
// MonoTests.System.Collections.Generic.Test.IListTest
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// Copyright (C) 2007 Gert Driesen
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Collections.Generic;
using NUnit.Framework;
namespace MonoTests.System.Collections.Generic
{
[TestFixture]
public class IListTest
{
[Test] // bug #80260
public void CastToArray ()
{
IList<string> list = new string[] { "foo", "bar" };
string[] array = (string[]) list;
Assert.IsNotNull (array, "#1");
Assert.AreEqual (2, array.Length, "#2");
Assert.AreEqual ("foo", array [0], "#3");
Assert.AreEqual ("bar", array [1], "#4");
}
}
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
2010-06-09 Jonathan Pryor <jpryor@novell.com>
* KeyedCollectionTest.cs: Verify exception safety of Insert().
2008-01-20 Juraj Skripsky <js@hotfeet.ch>
* ReadOnlyCollectionTest.cs: Add test to verify that ReadOnlyCollection
is indeed only a simple wrapper for a given IList.
Add tests for ICollection.IsSynchronized, IList.IsFixedSize and
IList.IsReadOnly.
2008-01-13 Gert Driesen <drieseng@users.sourceforge.net>
* CollectionTest.cs: Added test for ICollection.CopyTo.
* ReadOnlyCollectionTest.cs: Added ctor tests, and test for
ICollection.CopyTo.
2005-10-25 Atsushi Enomoto <atsushi@ximian.com>
* KeyedCollectionTest.cs : new file by Carlo Kok (ck@carlo-kok.com).
2005-06-21 Raja R Harinath <rharinath@novell.com>
* CollectionTest.cs (IEnumerable.GetEnumerator): Don't prefix with
System.Collections, since it resolves to the MonoTests namespace.
2005-06-21 David Waite <mass@akuma.org>
* CollectionTest.cs : added

View File

@@ -0,0 +1,190 @@
//
// MonoTests.System.Collections.Generic.Test.CollectionTest
//
// Authors:
// David Waite (mass@akuma.org)
//
// Copyright (C) 2005 David Waite
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.Collections.ObjectModel
{
[TestFixture]
public class CollectionTest
{
[Test]
public void UsableSyncLockTest ()
{
List <int> list = new List <int> ();
Collection <int> c = new Collection <int> (list);
object listLock = ((ICollection) list).SyncRoot;
object cLock = ((ICollection) c).SyncRoot;
Assert.AreSame (listLock, cLock);
}
[Test]
public void UnusableSyncLockTest ()
{
UnimplementedList <int> list = new UnimplementedList <int> ();
Collection <int> c = new Collection <int> (list);
object cLock = ((ICollection) c).SyncRoot;
Assert.IsNotNull (cLock);
Assert.IsTrue (cLock.GetType ().Equals (typeof (object)));
}
[Test]
public void ICollection_CopyTo ()
{
Collection <int> c = new Collection <int> ();
c.Add (10);
c.Add (7);
Array array = Array.CreateInstance (typeof (int), 2);
((ICollection) c).CopyTo (array, 0);
Assert.AreEqual (10, array.GetValue (0), "#A1");
Assert.AreEqual (7, array.GetValue (1), "#A2");
array = Array.CreateInstance (typeof (int), 5);
((ICollection) c).CopyTo (array, 2);
Assert.AreEqual (0, array.GetValue (0), "#B1");
Assert.AreEqual (0, array.GetValue (1), "#B2");
Assert.AreEqual (10, array.GetValue (2), "#B3");
Assert.AreEqual (7, array.GetValue (3), "#B4");
Assert.AreEqual (0, array.GetValue (4), "#B5");
array = Array.CreateInstance (typeof (object), 5);
((ICollection) c).CopyTo (array, 2);
Assert.IsNull (array.GetValue (0), "#C1");
Assert.IsNull (array.GetValue (1), "#C2");
Assert.AreEqual (10, array.GetValue (2), "#C3");
Assert.AreEqual (7, array.GetValue (3), "#C4");
Assert.IsNull (array.GetValue (4), "#C2");
}
class UnimplementedList <T> : IList <T>
{
#region IList <T> Members
int IList <T>.IndexOf (T item)
{
throw new Exception ("The method or operation is not implemented.");
}
void IList <T>.Insert (int index, T item)
{
throw new Exception ("The method or operation is not implemented.");
}
void IList <T>.RemoveAt (int index)
{
throw new Exception ("The method or operation is not implemented.");
}
T IList <T>.this [int index]
{
get
{
throw new Exception ("The method or operation is not implemented.");
}
set
{
throw new Exception ("The method or operation is not implemented.");
}
}
#endregion
#region ICollection <T> Members
void ICollection <T>.Add (T item)
{
throw new Exception ("The method or operation is not implemented.");
}
void ICollection <T>.Clear ()
{
throw new Exception ("The method or operation is not implemented.");
}
bool ICollection <T>.Contains (T item)
{
throw new Exception ("The method or operation is not implemented.");
}
void ICollection <T>.CopyTo (T [] array, int arrayIndex)
{
throw new Exception ("The method or operation is not implemented.");
}
int ICollection <T>.Count
{
get { throw new Exception ("The method or operation is not implemented."); }
}
bool ICollection <T>.IsReadOnly
{
get { throw new Exception ("The method or operation is not implemented."); }
}
bool ICollection <T>.Remove (T item)
{
throw new Exception ("The method or operation is not implemented.");
}
#endregion
#region IEnumerable <T> Members
IEnumerator <T> IEnumerable <T>.GetEnumerator ()
{
throw new Exception ("The method or operation is not implemented.");
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator ()
{
throw new Exception ("The method or operation is not implemented.");
}
#endregion
}
}
}
#endif

View File

@@ -0,0 +1,225 @@
// KeyedCollectionTest.cs - NUnit Test Cases for System.Collections.ObjectModel.KeyedCollection
//
// Carlo Kok (ck@carlo-kok.com)
//
// (C) Carlo Kok
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Globalization;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace MonoTests.System.Collections.ObjectModel
{
[TestFixture]
public class KeyedCollectionTest
{
private class CaseInsensitiveComparer : IEqualityComparer<string>
{
public CaseInsensitiveComparer () { }
#region IEqualityComparer<string> Members
public bool Equals (string x, string y)
{
return String.Compare (x, y, true,
CultureInfo.InvariantCulture) == 0;
}
public int GetHashCode (string obj)
{
return obj.ToUpper (CultureInfo.InvariantCulture).GetHashCode ();
}
#endregion
}
private class StrKeyCollection : KeyedCollection<string, string>
{
public StrKeyCollection (
IEqualityComparer<string> comparer,
int dictionaryCreationThreshold):
base (comparer, dictionaryCreationThreshold)
{
}
protected override string GetKeyForItem (string item)
{
return "Key:" + item;
}
public IDictionary<string, string> GetDictionary()
{
return Dictionary;
}
}
public KeyedCollectionTest ()
{
}
[Test]
public void TestDelete ()
{
StrKeyCollection collection =
new StrKeyCollection (EqualityComparer<string>.Default, 2);
collection.Add ("One"); // Key:First
collection.Add ("Two"); // Key:Two
Assert.IsTrue (collection.Remove ("Key:One"));
collection.Add ("Four"); // Key:Four
collection.Insert (2, "Three"); // Key:Three
Assert.IsTrue (collection.Remove ("Key:Three"));
Assert.IsFalse (collection.Remove ("Unknown"));
Assert.AreEqual (collection.GetDictionary ().Count, 2);
Assert.AreEqual (collection.Count, 2, "Collection count not equal to 2");
// check if all items are ordered correctly
Assert.AreEqual (collection [0], "Two");
Assert.AreEqual (collection [1], "Four");
Assert.AreEqual (collection ["Key:Two"], "Two");
Assert.AreEqual (collection ["Key:Four"], "Four");
try {
collection ["Key:One"].ToString();
Assert.Fail ("Unknown key should fail");
} catch (KeyNotFoundException e) {
e.ToString(); // avoid warning
// oke
}
try {
collection ["Key:One"].ToString();
Assert.Fail ("Unknown key should fail");
} catch (KeyNotFoundException e) {
e.ToString (); // avoid warning
// oke
}
}
[Test]
public void Insert_InvalidIndexDoesNotInsert ()
{
StrKeyCollection collection =
new StrKeyCollection(EqualityComparer<string>.Default, 0);
InsertInvalidIndex (collection, -1);
InsertInvalidIndex (collection, 1);
}
void InsertInvalidIndex (StrKeyCollection collection, int index)
{
try {
collection.Insert (index, "One");
Assert.Fail ("Invalid index should fail.");
}
catch (ArgumentOutOfRangeException) {
}
catch (Exception e) {
Assert.Fail ("Invalid exception type: expected ArgumentOutOfRangeException, got " + e.GetType ().Name);
}
IDictionary<string, string> dict = collection.GetDictionary ();
if (dict != null) {
Assert.AreEqual (0, dict.Count);
Assert.IsFalse (dict.ContainsKey ("Key:One"));
}
}
[Test]
public void Insert_DuplicateKey ()
{
StrKeyCollection collection =
new StrKeyCollection(EqualityComparer<string>.Default, 0);
collection.Add ("One");
try {
collection.Add ("One");
Assert.Fail ("Duplicate keys should throw ArgumentException.");
}
catch (ArgumentException) {
}
catch (Exception e) {
Assert.Fail ("Invalid exception type: expected ArgumentOutOfRangeException, got " + e.GetType ().Name);
}
Assert.AreEqual (1, collection.Count);
Assert.AreEqual (1, collection.GetDictionary ().Count);
}
[Test]
public void Insert_DuplicateKey_NoDictionary ()
{
StrKeyCollection collection =
new StrKeyCollection(EqualityComparer<string>.Default, 4);
collection.Add ("One");
try {
collection.Add ("One");
Assert.Fail ("Duplicate keys should throw ArgumentException.");
}
catch (ArgumentException) {
}
catch (Exception e) {
Assert.Fail ("Invalid exception type: expected ArgumentOutOfRangeException, got " + e.GetType ().Name);
}
Assert.AreEqual (1, collection.Count);
Assert.AreEqual (null, collection.GetDictionary ());
}
[Test]
public void TestInsert ()
{
StrKeyCollection collection =
new StrKeyCollection(EqualityComparer<string>.Default, 2);
Assert.IsNull (collection.GetDictionary (),
"Dictionary created too early"); // There can't be a dictionary yet
collection.Add ("One"); // Key:First
Assert.IsNull (collection.GetDictionary(),
"Dictionary created too early"); // There can't be a dictionary yet
collection.Add ("Two"); // Key:Two
Assert.IsNull (collection.GetDictionary (),
"Dictionary created too early"); // There can't be a dictionary yet
collection.Add ("Four"); // Key:Four
Assert.IsNotNull(collection.GetDictionary (),
"Dictionary created too late"); // There must be a dictionary
collection.Insert (2, "Three"); // Key:Three
Assert.AreEqual (collection.Count, 4,
"Collection count not equal to 4");
// check if all items are ordered correctly
Assert.AreEqual (collection [0], "One");
Assert.AreEqual (collection [1], "Two");
Assert.AreEqual (collection [2], "Three");
Assert.AreEqual (collection [3], "Four");
Assert.AreEqual (collection ["Key:One"], "One");
Assert.AreEqual (collection ["Key:Two"], "Two");
Assert.AreEqual (collection ["Key:Three"], "Three");
Assert.AreEqual (collection ["Key:Four"], "Four");
Assert.AreEqual (collection.GetDictionary ().Count, 4);
try {
collection ["UnkownKey"].ToString();
Assert.Fail ("Unknown key should fail");
} catch(KeyNotFoundException e) {
e.ToString(); // avoid warning
// oke
}
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More