Kh Tseegii wrote:
> Hi all,
>
>
> How to make proper test driver for next module?
>
> void sel_sort ( int array[ ], int limit )
> {
> int top, search, temp;
> for ( top = 0; top < limit-1; top++)
> for ( search = top + 1; search < limit; search++)
> if ( array[search] > array[top] ) {
> temp = array[search];
> array[search] = array[top];
> array[top] = temp;
> }
> }
>
>
>
> Thank you, Tse
I assume to test the sel_sort() function? Well, first off, you
shouldn't have written your own sort routine, even if it is probably a
class assignment - constantly "reinventing the wheel" is why we are
never going to get anywhere. But that is another issue and I digress.
The best way to test a new function/class/method is to write test cases
that will test every major aspect of both it and the context for which
the function exists. Sorting routines typically have two worst-cases:
The data is already sorted in order or the data is sorted in reverse
(and, depending on the algorithm, either one can also be the best case).
The average case is typically a randomly generated sequence of values.
The test driver should also test the output to confirm that the results
are indeed in the correct order.
These pages should help you out:
http://en.wikipedia.org/wiki/Sorting_algorithm
http://en.wikipedia.org/wiki/Selection_sort
Selection sort is O(N^2) no matter what you throw at it AND it isn't
typically a stable sort either, which basically means it is a terrible
sorting algorithm.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/