Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/corlib/Test/System.Collections.Generic/DictionaryTest.cs')
-rw-r--r--mcs/class/corlib/Test/System.Collections.Generic/DictionaryTest.cs101
1 files changed, 25 insertions, 76 deletions
diff --git a/mcs/class/corlib/Test/System.Collections.Generic/DictionaryTest.cs b/mcs/class/corlib/Test/System.Collections.Generic/DictionaryTest.cs
index 3192530e0ee..b4ad8323e7b 100644
--- a/mcs/class/corlib/Test/System.Collections.Generic/DictionaryTest.cs
+++ b/mcs/class/corlib/Test/System.Collections.Generic/DictionaryTest.cs
@@ -341,8 +341,10 @@ namespace MonoTests.System.Collections.Generic {
IEnumerator itr = ((IEnumerable)_dictionary).GetEnumerator ();
while (itr.MoveNext ()) {
object o = itr.Current;
- Assert.AreEqual (typeof (KeyValuePair<string,object>), o.GetType (), "Current should return a type of KeyValuePair");
- KeyValuePair<string,object> entry = (KeyValuePair<string,object>) itr.Current;
+ Assert.AreEqual (typeof (DictionaryEntry), o.GetType (), "Current should return a type of DictionaryEntry");
+ DictionaryEntry entry = (DictionaryEntry)itr.Current;
+ if (entry.Key.ToString () == "key4")
+ entry.Value = "value33";
}
Assert.AreEqual ("value4", _dictionary ["key4"].ToString (), "");
}
@@ -358,7 +360,7 @@ namespace MonoTests.System.Collections.Generic {
IEnumerator <KeyValuePair <string, object>> itr = ((IEnumerable <KeyValuePair <string, object>>)_dictionary).GetEnumerator ();
while (itr.MoveNext ()) {
object o = itr.Current;
- Assert.AreEqual (typeof (KeyValuePair <string, object>), o.GetType (), "Current should return a type of KeyValuePair<object,string>");
+ Assert.AreEqual (typeof (KeyValuePair <string, object>), o.GetType (), "Current should return a type of DictionaryEntry");
KeyValuePair <string, object> entry = (KeyValuePair <string, object>)itr.Current;
}
Assert.AreEqual ("value4", _dictionary ["key4"].ToString (), "");
@@ -376,7 +378,9 @@ namespace MonoTests.System.Collections.Generic {
while (itr.MoveNext ()) {
object o = itr.Current;
Assert.AreEqual (typeof (DictionaryEntry), o.GetType (), "Current should return a type of DictionaryEntry");
- DictionaryEntry entry = (DictionaryEntry) itr.Current;
+ DictionaryEntry entry = (DictionaryEntry)itr.Current;
+ if (entry.Key.ToString () == "key4")
+ entry.Value = "value33";
}
Assert.AreEqual ("value4", _dictionary ["key4"].ToString (), "");
@@ -392,17 +396,23 @@ namespace MonoTests.System.Collections.Generic {
int i = 0;
foreach (KeyValuePair <string, object> entry in _dictionary)
+ {
i++;
+ }
Assert.AreEqual(4, i, "fail1: foreach entry failed!");
i = 0;
- foreach (KeyValuePair <string, object> entry in ((IEnumerable)_dictionary))
+ foreach (DictionaryEntry entry in ((IEnumerable)_dictionary))
+ {
i++;
+ }
Assert.AreEqual(4, i, "fail2: foreach entry failed!");
i = 0;
foreach (DictionaryEntry entry in ((IDictionary)_dictionary))
+ {
i++;
+ }
Assert.AreEqual (4, i, "fail3: foreach entry failed!");
}
@@ -490,14 +500,13 @@ namespace MonoTests.System.Collections.Generic {
[Test]
public void PlainEnumeratorReturnTest ()
{
- // Test that we return a KeyValuePair even for non-generic dictionary iteration
+ // Test that we return a DictionaryEntry for non-generic dictionary iteration
_dictionary["foo"] = "bar";
IEnumerator<KeyValuePair<string, object>> enumerator = _dictionary.GetEnumerator();
- Assert.IsTrue(enumerator.MoveNext(), "#1");
- Assert.AreEqual (typeof (KeyValuePair<string,object>), ((IEnumerator)enumerator).Current.GetType (), "#2");
- Assert.AreEqual (typeof (DictionaryEntry), ((IDictionaryEnumerator)enumerator).Entry.GetType (), "#3");
- Assert.AreEqual (typeof (KeyValuePair<string,object>), ((IDictionaryEnumerator)enumerator).Current.GetType (), "#4");
- Assert.AreEqual (typeof (KeyValuePair<string,object>), ((object) enumerator.Current).GetType (), "#5");
+ Assert.IsTrue(enumerator.MoveNext());
+ Assert.IsTrue(((IEnumerator)enumerator).Current is DictionaryEntry);
+ Assert.IsTrue(((IDictionaryEnumerator)enumerator).Current is DictionaryEntry);
+ Assert.IsFalse(((object) enumerator.Current) is DictionaryEntry);
}
[Test, ExpectedException (typeof (InvalidOperationException))]
@@ -606,12 +615,11 @@ namespace MonoTests.System.Collections.Generic {
}
[Test]
- public void Empty_KeysValues_CopyTo ()
+ public void Empty_Values_CopyTo ()
{
Dictionary<int, int> d = new Dictionary<int, int> ();
- int[] array = new int[1];
- d.Keys.CopyTo (array, array.Length);
- d.Values.CopyTo (array, array.Length);
+ int[] array = new int[10];
+ d.Values.CopyTo (array, 0);
}
[Test]
@@ -619,67 +627,8 @@ namespace MonoTests.System.Collections.Generic {
{
Dictionary<int, int> d = new Dictionary<int, int> ();
ICollection c = (ICollection) d;
- DictionaryEntry [] array = new DictionaryEntry [1];
- c.CopyTo (array, array.Length);
-
- ICollection<KeyValuePair<int,int>> c2 = d;
- KeyValuePair<int,int> [] array2 = new KeyValuePair<int,int> [1];
- c2.CopyTo (array2, array2.Length);
- }
-
- [Test]
- public void IDictionary_Contains ()
- {
- IDictionary d = new Dictionary<int, int> ();
- d.Add (1, 2);
- Assert.IsTrue (d.Contains (1));
- Assert.IsFalse (d.Contains (2));
- Assert.IsFalse (d.Contains ("x"));
- }
-
- [Test, ExpectedException (typeof (ArgumentNullException))]
- public void IDictionary_Contains2 ()
- {
- IDictionary d = new Dictionary<int, int> ();
- d.Contains (null);
- }
-
- [Test, ExpectedException (typeof (ArgumentNullException))]
- public void IDictionary_Add1 ()
- {
- IDictionary d = new Dictionary<int, int> ();
- d.Add (null, 1);
- }
-
- [Test, ExpectedException (typeof (ArgumentException))]
- public void IDictionary_Add2 ()
- {
- IDictionary d = new Dictionary<int, int> ();
- d.Add ("bar", 1);
- }
-
- [Test, ExpectedException (typeof (ArgumentException))]
- public void IDictionary_Add3 ()
- {
- IDictionary d = new Dictionary<int, int> ();
- d.Add (1, "bar");
- }
-
- [Test]
- public void IDictionary_Remove1 ()
- {
- IDictionary d = new Dictionary<int, int> ();
- d.Add (1, 2);
- d.Remove (1);
- d.Remove (5);
- d.Remove ("foo");
- }
-
- [Test, ExpectedException (typeof (ArgumentNullException))]
- public void IDictionary_Remove2 ()
- {
- IDictionary d = new Dictionary<int, int> ();
- d.Remove (null);
+ DictionaryEntry[] array = new DictionaryEntry[1];
+ c.CopyTo (array, 0);
}
}
}