Exemplo n.º 1
0
        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
        }
Exemplo n.º 2
0
        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]);
        }
Exemplo n.º 3
0
        public void shellSortTest5()
        {
            Sorts target = new Sorts(); // Creates an instance of the class to be tested (a target object/instance of the Sorts class)

            int SIZE = 15; // The size of the array
            int[] actual = { 1,1,1,2,2,2,3,3,3,4,4,4,5,5,5};

            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 expectedArray
            Array.Sort(expected); //the expected array is sorted by the .NET Array.Sort Method

            target.shellSort(actual, SIZE); //the actual array is now passed (by reference) to the shellSort method for testing

            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
        }
Exemplo n.º 4
0
        public void shellSortTest3()
        {
            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= {-7, -5, 1,1,2,4,4,6,7,9}; //the actual array declared with a sorted list of positive and negative values with duplicate values

            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.shellSort(actual, SIZE); //the actual array is now passed (by reference) to the shellSort 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]);
        }
Exemplo n.º 5
0
        public void shellSortTest1()
        {
            Sorts target = new Sorts(); // Creates an instance of the class to be tested (a target object/instance of the Sorts class)

            int SIZE = 100; // 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, 300, 850), 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 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.shellSort(actual, SIZE); //the actual array is now passed (by reference) to the shellSort method

            CollectionAssert.ReferenceEquals(expected, actual); //Checks if compared objects are of the same instance
            Assert.AreEqual(expected[0], actual[0]);//compares and checks the first index (low boundary)
            Assert.AreEqual(expected[SIZE - 1], actual[SIZE - 1]);//compares and checks the last index (high boundary)
            Assert.AreEqual(expected[(SIZE/2)], actual[(SIZE/2)]);//checks the middle index
        }
Exemplo n.º 6
0
        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
        }