public void bubbleSortTest1() { int SIZE = 10; Sorts target = new Sorts(); // Creates an instance of the class to be tested (a target object/instance of the Sorts class) int[] actual= new int[SIZE]; //actual declared as an empty array int[] expected = new int[SIZE]; //expected declared as empty array Array.Sort(expected); //the expected array is sorted by the .NET Array.Sort Method target.bubbleSort(actual, SIZE); //the actual array is now passed (by reference i.e. by default) to the bubbleSort 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 bubbleSortTest2() { Sorts target = new Sorts(); // Creates an instance of the class to be tested (a target object/instance of the Sorts class) int SIZE = 30; // 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, -100, -1), actual, SIZE); /*Copies the randomly populated array from the populateArray function to the actual*/ 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.bubbleSort(actual, SIZE); //the actual is now passed (by reference by default) to the bubbleSort 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 bubbleSortTest3() { Sorts target = new Sorts(); // Creates an instance of the class to be tested (a target object/instance of the Sorts class) int SIZE = 50; // The size of the array int[] actual = new int[SIZE]; //actual 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, -100, 100), actual, SIZE); /*Copies the randomly populated array from the populateArray function to the actual*/ 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.bubbleSort(actual, SIZE); //the actual is now passed (by reference) to the bubbleSort 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 }