1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 using System.Runtime.InteropServices;
11 #region General method
13 public static T[] InitArray<T>(int arrSize)
15 T[] array = new T[arrSize];
16 for (int i = 0; i < array.Length; i++)
18 array[i] = (T)Convert.ChangeType(i, typeof(T));
23 public static bool EqualArray<T>(T[] actualArray, int actualSize, T[] expectedArray, int expectedSize)
26 if (actualArray == null && expectedArray == null)
28 Console.WriteLine("\tTwo array are equal.Both of them null");
31 else if (actualArray == null && expectedArray != null)
33 Console.WriteLine("\tTwo array are not equal.The sourcArr is null,but the expectedArray is not null");
36 else if (actualArray != null && expectedArray == null)
38 Console.WriteLine("\tTwo array are not equal.The sourcArr is not null but the expectedArray is null");
41 else if (!actualSize.Equals(expectedSize))
43 Console.WriteLine("\tTwo array are not equal.The sizes are not equal:Expected:{0},Actaul:{1}", expectedSize, actualSize);
46 for (int i = 0; i < expectedSize; ++i)
48 if (!actualArray[i].Equals(expectedArray[i]))
50 Console.WriteLine("\tTwo array are not equal.The values of index {0} are not equal!", i);
51 Console.WriteLine("\t\tThe actualArray is {0},the expectedArray is {1}", actualArray[i].ToString(), expectedArray[i].ToString());
60 public static T[] GetExpChangeArray<T>(int cSize)
62 T[] array = new T[cSize];
64 for (int i = array.Length - 1; i >= 0; --i)
65 array[i] = (T)Convert.ChangeType(array.Length - 1 - i, typeof(T));
70 public static bool CheckAndChangeArray<T>(ref T[] arrArg, ref T arrSize, int actualArrSize, int expectedArrSize)
72 T[] actualArr = InitArray<T>(actualArrSize);
73 if (!EqualArray<T>(arrArg, actualArrSize, actualArr, actualArrSize))
78 arrSize = (T)Convert.ChangeType(expectedArrSize, typeof(T));
79 arrArg = GetExpChangeArray<T>(expectedArrSize);