Files

111 lines
3.0 KiB
C
Raw Permalink Normal View History

2026-05-05 01:21:11 -05:00
#include "../include/types.h"
2026-05-06 05:47:11 -05:00
#include "../include/radix.h"
2026-05-08 04:33:59 -05:00
#include "../include/quicksort.h"
2026-05-06 05:47:11 -05:00
#include "../include/lsort.h"
#include <stdio.h>
2026-05-05 01:21:11 -05:00
2026-05-05 01:30:10 -05:00
int test_array_i_append(lsort_array_i* array) {
2026-05-08 04:33:59 -05:00
printf("lsort_array_i_append()...\n");
2026-05-05 01:30:10 -05:00
lsort_array_i_append(array, 25);
lsort_array_i_append(array, 64);
lsort_array_i_append(array, 34);
lsort_array_i_append(array, 74);
lsort_array_i_append(array, 99);
lsort_array_i_append(array, 23);
2026-05-05 01:21:11 -05:00
if (array->items[5] != 23) return 1;
return 0;
}
2026-05-05 01:30:10 -05:00
int test_array_i_swap(lsort_array_i* array) {
2026-05-08 04:33:59 -05:00
printf("lsort_array_i_swap()...\n");
2026-05-05 01:30:10 -05:00
lsort_array_i_swap(array, 0, 5);
lsort_array_i_swap(array, 4, 2);
lsort_array_i_swap(array, 2, 3);
2026-05-05 01:21:11 -05:00
if (array->items[0] != 23 || array->items[5] != 25 || array->items[4] != 34 || array->items[2] != 74 || array->items[3] != 99) return 1;
return 0;
}
2026-05-04 18:18:55 -05:00
2026-05-06 05:47:11 -05:00
int test_append_swap() {
2026-05-08 04:33:59 -05:00
printf("test_append_swap()...\n");
2026-05-06 05:47:11 -05:00
lsort_array_i array_append_swap = {0};
if (test_array_i_append(&array_append_swap)) return 1;
if (test_array_i_swap(&array_append_swap)) return 1;
lsort_array_i array_sort_check = {0};
lsort_array_i_append(&array_sort_check, 1);
lsort_array_i_append(&array_sort_check, 5);
lsort_array_i_append(&array_sort_check, 7);
lsort_array_i_append(&array_sort_check, 8);
lsort_array_i_append(&array_sort_check, 15);
lsort_array_i_append(&array_sort_check, 28);
if (check_sorted(&array_sort_check) == 1) return 1;
lsort_array_i_swap(&array_sort_check, 2, 4);
lsort_array_i_swap(&array_sort_check, 0, 3);
if (check_sorted(&array_sort_check) == 0) return 1;
return 0;
}
int test_radix_sort() {
2026-05-08 04:33:59 -05:00
printf("lsort_radix()...\n");
2026-05-06 05:47:11 -05:00
lsort_array_i array_radix = {0};
lsort_array_i_append(&array_radix, -2);
lsort_array_i_append(&array_radix, -15);
lsort_array_i_append(&array_radix, 25);
lsort_array_i_append(&array_radix, 56);
lsort_array_i_append(&array_radix, 23);
lsort_array_i_append(&array_radix, -222);
lsort_array_i_append(&array_radix, -58);
2026-05-04 18:18:55 -05:00
2026-05-06 05:47:11 -05:00
lsort_array_i array_radix_return = {0};
lsort_radix(&array_radix, &array_radix_return);
if (check_sorted(&array_radix_return) != 0) return 1;
return 0;
}
2026-05-08 04:33:59 -05:00
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;
}
2026-05-06 05:47:11 -05:00
int main(void) {
if (
test_append_swap() ||
2026-05-08 04:33:59 -05:00
test_radix_sort() ||
test_quicksort()
2026-05-06 05:47:11 -05:00
) return 1;
2026-05-08 04:33:59 -05:00
printf("\nTest completed successfully.\n");
2026-05-04 18:18:55 -05:00
return 0;
}