Array.CreateInstance (typeof (Int32), (long[])null);
}
+ [Test]
+ public void CreateInstanceVoid ()
+ {
+ Assert.Throws<NotSupportedException> (delegate () {
+ Array.CreateInstance (typeof (void), 1);
+ });
+ }
+
[Test]
public void TestGetEnumerator() {
String[] s1 = {"this", "is", "a", "test"};
int[] myBoundArray = new int[1] { Int32.MinValue };
Array myExtremeArray=Array.CreateInstance ( typeof(String), myLengthArray, myBoundArray );
Assert.AreEqual (Int32.MaxValue, ((IList)myExtremeArray).IndexOf (42), "AD04");
-
}
[Test]
Assert.AreEqual (4, indices [0]);
}
+ [Test]
+ public void TestSortComparable()
+ {
+ int[] source = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ int[] expected = { 6, 5, 4, 3, 2, 1, 7, 8, 9 };
+ Comp[] c = { new Comp (100), new Comp (16), new Comp (11), new Comp (9), new Comp (0), new Comp (-100) };
+ IComparer<Comp> comp = null;
+ Array.Sort<Comp, int> (c, source, comp);
+
+ Assert.AreEqual (expected, source);
+ }
+
+ class Comp : IComparable
+ {
+ readonly int val;
+
+ public Comp (int a)
+ {
+ val = a;
+ }
+
+ int IComparable.CompareTo (object obj)
+ {
+ return val.CompareTo ((obj as Comp).val);
+ }
+ }
+
+ [Test]
+ public void TestSortComparableMixed()
+ {
+ var m = new TestSortComparableMixed_Comparer ();
+ var arr = new object [] { 1, 2, m, 4, 5, 6, 7, 8, 9, 10 };
+
+ Array.Sort (arr);
+
+ var expected = new object [] { m, 1, 2, 4, 5, 6, 7, 8, 9, 10 };
+ Assert.AreEqual (expected, arr);
+ }
+
+ class TestSortComparableMixed_Comparer : IComparable
+ {
+ public int CompareTo (object other)
+ {
+ return -1;
+ }
+ }
+
[Test]
public void TestInitializeEmpty()
{
}
}
+ [Test]
+ public void IEnumerator_Dispose ()
+ {
+ IEnumerable<int> e = new int[] { 1 };
+ var en = e.GetEnumerator ();
+ Assert.IsTrue (en.MoveNext (), "#1");
+ Assert.IsFalse (en.MoveNext (), "#2");
+ en.Dispose ();
+ Assert.IsFalse (en.MoveNext (), "#3");
+ }
+
+ [Test]
+ public void IEnumerator_ZeroSize ()
+ {
+ IEnumerable<int> e = Array.Empty<int> ();
+ var en = e.GetEnumerator ();
+ Assert.IsFalse (en.MoveNext (), "#1");
+
+ e = Array.Empty<int> ();
+ en = e.GetEnumerator ();
+ Assert.IsFalse (en.MoveNext (), "#2");
+ }
+
+ [Test]
public void ICollection_IsReadOnly() {
ICollection<string> arr = new string [10];
Assert.AreEqual (3, c.Counter);
}
+ [Test]
+ public void EnumeratorsEquality ()
+ {
+ int [] normalBase = new int [0];
+ IEnumerable<int> specialBase = new int [0];
+
+ var firstSpecial = specialBase.GetEnumerator ();
+ var secondSpecial = specialBase.GetEnumerator ();
+ var firstNormal = normalBase.GetEnumerator ();
+ var secondNormal = normalBase.GetEnumerator ();
+
+ Assert.IsFalse (object.ReferenceEquals (firstNormal, secondNormal));
+ Assert.IsTrue (object.ReferenceEquals (firstSpecial, secondSpecial));
+ }
[Test]
public void JaggedArrayCtor ()
Assert.AreEqual (10, ((object[])arr [i]).Length);
}
}
+
+ [Test]
+ public unsafe void PointerArraysBoxing ()
+ {
+ var x = new int*[10];
+ var e = x.GetEnumerator ();
+ e.MoveNext ();
+
+ Assert.Throws<NotSupportedException> (() => { var _ = e.Current; }, "#1");
+ Assert.Throws<NotSupportedException> (() => { var _ = x.GetValue (0); }, "#2");
+ Assert.Throws<NotSupportedException> (() => { x.SetValue (0, 0); }, "#3");
+ }
}
}