selectionsort
This commit is contained in:
40
test/test.c
40
test/test.c
@@ -21,6 +21,8 @@
|
||||
#include "bubble_sort.h"
|
||||
#include "count_sort.h"
|
||||
#include "quick_sort.h"
|
||||
#include "bitonic_sort.h"
|
||||
#include "selection_sort.h"
|
||||
|
||||
static int *test_case;
|
||||
static int *test_array;
|
||||
@@ -146,6 +148,44 @@ int main(int argc, char **argv) {
|
||||
passed++;
|
||||
}
|
||||
|
||||
//test bitonic
|
||||
pass = 1;
|
||||
memcpy(test_array, test_case, sizeof(int) * n);
|
||||
fprintf(stdout, "\tbitonic sort: ");
|
||||
fflush(stdout);
|
||||
bitonic_sort(test_array, n);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (test_array[i] != qarray[i]) {
|
||||
fprintf(stdout, "fail\n");
|
||||
failed++;
|
||||
pass = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pass) {
|
||||
fprintf(stdout, "pass\n");
|
||||
passed++;
|
||||
}
|
||||
|
||||
// Test selection sort
|
||||
pass = 1;
|
||||
memcpy(test_array, test_case, sizeof(int) * n);
|
||||
fprintf(stdout, "\tselection sort: ");
|
||||
fflush(stdout);
|
||||
selection_sort(test_array, n);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (test_array[i] != qarray[i]) {
|
||||
fprintf(stdout, "fail\n");
|
||||
failed++;
|
||||
pass = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pass) {
|
||||
fprintf(stdout, "pass\n");
|
||||
passed++;
|
||||
}
|
||||
|
||||
fprintf(stdout, "%d tests passed\n", passed);
|
||||
fprintf(stdout, "%d tests failed\n", failed);
|
||||
|
||||
|
Reference in New Issue
Block a user