sort.c
/*
 * testSort - run the sort function and test we're doing it right
 */
run the sort function and test we're doing it right
run the sort function and test we ' re doing it right
void testSort(SORT_FUNCTION fn, const char *name) {
  int j;
  for (j = 0; j < TEST_SIZE; j++)
    array[j] = random();
  (*fn)(array, TEST_SIZE);
  checkSorted(array, TEST_SIZE, name, "random fill");
  for (j = 0; j < TEST_SIZE; j++)
    array[j] = 0;
  (*fn)(array, TEST_SIZE);
  checkSorted(array, TEST_SIZE, name, "zeroes");
  for (j = 0; j < TEST_SIZE; j++)
    array[j] = j;
  (*fn)(array, TEST_SIZE);
  checkSorted(array, TEST_SIZE, name, "ascending");
  for (j = 0; j < TEST_SIZE; j++)
    array[j] = TEST_SIZE - j;
  (*fn)(array, TEST_SIZE);
  checkSorted(array, TEST_SIZE, name, "descending");
}
void testSort ( SORT_FUNCTION fn , const char * name ) { int j ; for ( j = 0 ; j < TEST_SIZE ; j ++ ) array [ j ] = random ( ) ; ( * fn ) ( array , TEST_SIZE ) ; checkSorted ( array , TEST_SIZE , name , " " ) ; for ( j = 0 ; j < TEST_SIZE ; j ++ ) array [ j ] = 0 ; ( * fn ) ( array , TEST_SIZE ) ; checkSorted ( array , TEST_SIZE , name , " " ) ; for ( j = 0 ; j < TEST_SIZE ; j ++ ) array [ j ] = j ; ( * fn ) ( array , TEST_SIZE ) ; checkSorted ( array , TEST_SIZE , name , " " ) ; for ( j = 0 ; j < TEST_SIZE ; j ++ ) array [ j ] = TEST_SIZE - j ; ( * fn ) ( array , TEST_SIZE ) ; checkSorted ( array , TEST_SIZE , name , " " ) ; }
testSort - run the sort function and test we're doing it right
testSort - run the sort function and test we ' re doing it right
/* initialize the array with random numbers */ /* initialize the array with identical numbers */ /* initialize the array with ascending values */ /* initialize the array with descending values */