public void insertionSortTest3() { Sorts target = new Sorts(); // Creates an instance of the class to be tested (a target object/instance of the Sorts class) int SIZE = 160; // The size of the array int[] actual = new int[SIZE]; //actual array declared of type int with 'SIZE' number of elements /*populateArray(Size ofArray, Minimum Random Value, Maximum Random Value): This function returns a populated array of a size and random values in range specified by the functions arguments*/ Array.Copy(populateArray(SIZE, 35, 350), actual, SIZE); /*Copies the randomly populated array from the populateArray function to the actual array*/ Array.Sort(actual); //produces the fully sorted array that will be used in the unit test. int[] expected = new int[SIZE];//expected array declared of type int with 'SIZE' number of elements used to store the required or expected order of elements Array.Copy(actual, expected, SIZE);//the actual array 's content is copied to the expected array Array.Sort(expected); //the expected array is sorted by the .NET Array.Sort Method target.insertionSort(actual, SIZE); //the actual array is now passed (by reference) to the insertionSort method CollectionAssert.ReferenceEquals(expected, actual); //Checks if compared objects are of the same instance CollectionAssert.AreEqual(expected, actual);//compares the content of the expected and actual collection }
public void insertionSortTest4() { Sorts target = new Sorts(); // Creates an instance of the class to be tested (a target object/instance of the Sorts class) int SIZE = 1; // The size of the array int[] actual= new int[SIZE]; //actual array declared of type int with 'SIZE' number of elements /*populateArray(Size ofArray, Minimum Random Value, Maximum Random Value): This function returns a populated array of a size and random values in range specified by the functions arguments*/ Array.Copy(populateArray(SIZE, -500, 500), actual, SIZE); /*Copies the randomly populated array from the populateArray function to the actual array*/ int[] expected = new int[SIZE];//expected array declared of type int with 'SIZE' number of elements used to sort the required or expected order of elements Array.Copy(actual, expected, SIZE);//the actual array 's content is copied to the expected array Array.Sort(expected); //the expected array is sorted by the .NET Array.Sort Method target.insertionSort(actual, SIZE); //the actual array is now passed (by reference) to the insertionSort method CollectionAssert.ReferenceEquals(expected, actual); //Checks if compared objects are of the same instance for (int count = 0; count < SIZE; count++) // loop that iterates through the arrays (collections) and checks if each element are respectively identical Assert.AreEqual(expected[count], actual[count]); }
public void insertionSortTest2() { Sorts target = new Sorts(); // Creates an instance of the class to be tested (a target object/instance of the Sorts class) int SIZE = 10; // The size of the array int[] actual = { 3, 6, 9, 10, 12, 11, 21, 19, 27, 1}; int[] expected = new int[SIZE];//expected array declared of type int with 'SIZE' number of elements used to hold the required or expected order of elements Array.Copy(actual, expected, SIZE);//the actual array 's content is copied to the expected array Array.Sort(expected); //the expected array is sorted by the .NET Array.Sort Method target.insertionSort(actual, SIZE); //the actual array is now passed (by reference) to the insertionSort method CollectionAssert.ReferenceEquals(expected, actual); //Checks if compared objects are of the same instance CollectionAssert.AreEqual(expected, actual);//compares the content of the expected and actual collection }