Implement QuickSort
This commit is contained in:
38
test/test.c
38
test/test.c
@@ -1,10 +1,12 @@
|
||||
#include "../include/types.h"
|
||||
#include "../include/radix.h"
|
||||
#include "../include/quicksort.h"
|
||||
#include "../include/lsort.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int test_array_i_append(lsort_array_i* array) {
|
||||
|
||||
printf("lsort_array_i_append()...\n");
|
||||
|
||||
lsort_array_i_append(array, 25);
|
||||
lsort_array_i_append(array, 64);
|
||||
lsort_array_i_append(array, 34);
|
||||
@@ -18,6 +20,8 @@ int test_array_i_append(lsort_array_i* array) {
|
||||
}
|
||||
|
||||
int test_array_i_swap(lsort_array_i* array) {
|
||||
printf("lsort_array_i_swap()...\n");
|
||||
|
||||
lsort_array_i_swap(array, 0, 5);
|
||||
lsort_array_i_swap(array, 4, 2);
|
||||
lsort_array_i_swap(array, 2, 3);
|
||||
@@ -28,6 +32,8 @@ int test_array_i_swap(lsort_array_i* array) {
|
||||
}
|
||||
|
||||
int test_append_swap() {
|
||||
printf("test_append_swap()...\n");
|
||||
|
||||
lsort_array_i array_append_swap = {0};
|
||||
|
||||
if (test_array_i_append(&array_append_swap)) return 1;
|
||||
@@ -50,6 +56,8 @@ int test_append_swap() {
|
||||
}
|
||||
|
||||
int test_radix_sort() {
|
||||
printf("lsort_radix()...\n");
|
||||
|
||||
lsort_array_i array_radix = {0};
|
||||
lsort_array_i_append(&array_radix, -2);
|
||||
lsort_array_i_append(&array_radix, -15);
|
||||
@@ -67,14 +75,36 @@ int test_radix_sort() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_quicksort() {
|
||||
printf("lsort_quicksort()...\n");
|
||||
lsort_array_i array_quicksort = {0};
|
||||
|
||||
lsort_array_i_append(&array_quicksort,6);
|
||||
lsort_array_i_append(&array_quicksort, 5);
|
||||
lsort_array_i_append(&array_quicksort, 4);
|
||||
lsort_array_i_append(&array_quicksort, 3);
|
||||
lsort_array_i_append(&array_quicksort, 2);
|
||||
lsort_array_i_append(&array_quicksort, 5);
|
||||
lsort_array_i_append(&array_quicksort, 1);
|
||||
lsort_array_i_append(&array_quicksort, 0);
|
||||
|
||||
lsort_quicksort(&array_quicksort, NULL);
|
||||
|
||||
if (check_sorted(&array_quicksort)) return 1;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
if (
|
||||
test_append_swap() ||
|
||||
test_radix_sort()
|
||||
test_radix_sort() ||
|
||||
test_quicksort()
|
||||
) return 1;
|
||||
|
||||
|
||||
printf("Test completed successfully.\n");
|
||||
|
||||
printf("\nTest completed successfully.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user