public void TestToArray() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) { list.Add(j); } int[] a1 = list.ToArray(); Assert.AreEqual(a1.Length, list.Count); for (int j = 0; j < 1000; j++) { Assert.AreEqual(a1[j], list.Get(j)); } int[] a2 = new int[list.Count]; int[] a3 = list.ToArray(a2); Assert.AreSame(a2, a3); for (int j = 0; j < 1000; j++) { Assert.AreEqual(a2[j], list.Get(j)); } int[] ashort = new int[list.Count - 1]; int[] aLong = new int[list.Count + 1]; int[] a4 = list.ToArray(ashort); int[] a5 = list.ToArray(aLong); Assert.IsTrue(a4 != ashort); Assert.IsTrue(a5 != aLong); Assert.AreEqual(a4.Length, list.Count); for (int j = 0; j < 1000; j++) { Assert.AreEqual(a3[j], list.Get(j)); } Assert.AreEqual(a5.Length, list.Count); for (int j = 0; j < 1000; j++) { Assert.AreEqual(a5[j], list.Get(j)); } }