The object is to write code for the Test Sort and the Selection Sort, according to what we have developed in class.
Here are the points that have to be covered in your code, if I leave something out inadvertently I expect you to insert it.
We will call the "tester" the user who is calling Test Sort which in turn calls Selection Sort. We do not have to be 'user friendly to the tester since that is yourself the software developer, who is providing the function Selection Sort to the application programmer.
1. Create your Test Sort function. You can name your testing function anything you want within reason. (We can dispense with the Test Sort Small Arrays name, since in this midterm we are not going to deal with timing the actual sort.) Since only you are dealing with this function (in the future most likely within your company whatever that might turn out to be), I don't insist upon certain naming conditions being followed.
2. The Test Sort function, first presents the tester with a list of two things: Selection Sort and Exit. Whenever the tester chooses Exit (or it is chosen for him/her by the Test Sort function you will print a message, but only if the Selection Sort has been called at some point. The message will state that the Selection Sort succeeded or that it did not succeed. No reasons given. If the Selection Sort has not actually been run for whatever reason, there will be no message to the tester. (There is a little logical problem here, which will show up when we have actually implemented more than one type of sort, but we will ignore that for now.)
3. If the tester chooses Exit there is nothing further to do but exit with a relevant message if a Selection Sort has been run.
4. On the other hand, if the tester chooses Selection Sort, ask them for the size of the array they wish to sort; state that it has to be between 1 and 1,000. If the tester enters an incorrect integer, just exit, let the tester deal with it.
5.Caveat: You are going to print in some fashion or other, either to the screen or to a file both the unsorted and then the sorted array. If you print to the screen, you must be able print the array "horizontally". If you cannot do that, it is perfectly okay, the important thing is your function, Selection Sort, not the Test Sort. If you cannot print "horizontally" or print to a file, you will use an array size of 10, and print the array anyway you can.
6. At this point we do not need the tester anymore until we finish the Selection Sort. Create an array of the size you wish, either what the tester entered, or 10 (see 5. Above). Name your array, integerTestArray (I prefer meaningful names, not just A) and we will Il be in sync. Also name the integer holding the size of the array, size TestArray. Here is where you create the array in C):
int integerTestArray (size TestArray);
(I am using the mixed case naming convention; see handout.)
7. Fill this array, if you can with random integers, in a range of 1 to twice the size of the array (these boundaries are chosen for no particular reason). If using random integers is not worth the effort, then just fill your array sequentially in descending order starting with the size you've decided on.
8. Create another array inside your Test Sort function, call it copyOfIntegerTestArray, but you can choose another name if you don't like that one, but at least indicate that it is going to hold a copy of something or other, and of course make its size, .size TestArray rTestArray into copyOfIntegerTestArray. This array is not to be changed during the running of your Test Sort function. Here is where you create the array in C):
int copyOfIntegerTestArray (size TestArray];
We have agreed in our crowd sourcing sessions vis-a-vis Agile Technology Software Development that we will declare the following signature for our Selection Sort:
int selectionSort (int * integerArray, int sizeArray)
This function should be written following the pseudo code we have done in lecture.
9. Since all sorts require a function that swaps two integers. You should create it now as a separate function, to be called by your sort function, and for future use. Here is its signature.
int swapIntegers (int integerA, int integerB)
Vis-a-vis bullet-proofing, I don't think we should check whether the input arguments are indeed integers, whatever they are, a specified amount of storage will be swapped. Let the user be responsible for incorrect arguments in this case. Too much bullet-proofing would make the code unreadable.
10. Have your Test Sort function now call your sorting function passing it the array to be sorted and its size (see signature in Step 8.).
11. Hook everything together via main(), i.e. main calls your Test Sort function.
12. If the sorting function fails, print "Sorting function failed." and exit the Test Sort function. You don't have to give a reason and in fact you don't know the reason, the sorting function's code will have to be reexamined by you.
13. If the sorting function is successful, have your Test Sort function (not your sorting function, because that is not its job) "publish" both the unsorted array preceded by something like: "Here is the unsorted array." And then "publish" the sorted array preceding by something like: "Here is the sorted array."
14.Test Sort has now accomplished what it was asked to do. At this point increment its local variable numberOfSorts Performed, initialized originally by Test Sort to 0.
15. In your Test Sort function, if the numberOfSortsPerformed is greater or equal to the numberOfSorts, initialized originally by Test Sort to be the number of sort functions it is capable of calling, have your Test Sort function exit.
16. If this is not the case, then present the same list to the tester as was presented initially. However, in the case that we actually have written another sort say, Bubble Sort, we have some work to do since we already have the array we are going to sort, namely copyOfIntegerTestArray, so we don't want to ask the tester anything more. An easy way to get around this is to query the user for the size etc. etc. before we present the list, but then if the tester chooses to Exit they have done work for nothing. But then again that is not our concern, that is the tester's mistake, so that seems to be the solution to that problem. However, let's not deal with that now, since we have not even written one sorting function.
17. Finally calling upon our crowd sourcing aspect of Agile Technology, is there anything missing from this specification. If in your opinion there is, let's discuss it.