76 lines
2.8 KiB
C
76 lines
2.8 KiB
C
#include "c_InPlaceMSDRadixSort.h"
|
|||
|
|
#include <stdlib.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
|
||
|
|
#include "c_Memory.h"
|
||
|
|
|
||
|
|
// Your updated line tracing diagnostic macro
|
||
|
|
#define EXPECT_EQ(actual, expected, msg) \
|
||
|
|
do { \
|
||
|
|
if ((actual) != (expected)) { \
|
||
|
|
printf(" [X] Assert Failed: %s (Expected %d, got %d) %s:%d\n", msg, (int)(expected), (int)(actual), __FILE__, __LINE__); \
|
||
|
|
return C_FALSE; \
|
||
|
|
} \
|
||
|
|
} while(0)
|
||
|
|
|
||
|
|
c_bool_t test_inplace_msd_radix_sort_execution(void) {
|
||
|
|
c_InPlaceMSDRadixSort_t sort;
|
||
|
|
sort.R = 256; // Standard extended ASCII alphabet boundaries
|
||
|
|
|
||
|
|
c_size_t n = 7;
|
||
|
|
// Unsorted variable-length string test pool configurations
|
||
|
|
char* test_data[] = {
|
||
|
|
"she",
|
||
|
|
"sells",
|
||
|
|
"seashells",
|
||
|
|
"by",
|
||
|
|
"the",
|
||
|
|
"sea",
|
||
|
|
"shore"
|
||
|
|
};
|
||
|
|
|
||
|
|
// Allocate an array of modifiable pointers to replicate the application environment
|
||
|
|
char** arr = (char**)C_ALLOC(n * sizeof(char*));
|
||
|
|
if (arr == NULL) return C_FALSE;
|
||
|
|
for (c_size_t i = 0; i < n; i++) arr[i] = test_data[i];
|
||
|
|
|
||
|
|
printf(" [LOG] Launching space-optimized In-Place MSD Radix Sort...\n");
|
||
|
|
c_err_t err = c_InPlaceMSDRadixSort_Sort(&sort, arr, n);
|
||
|
|
|
||
|
|
EXPECT_EQ(err, C_ERR_OK, "In-place MSD sort engine returned unexpected runtime error code");
|
||
|
|
|
||
|
|
// Mathematically sorted verification checkpoints list mapping:
|
||
|
|
// Expected alphabetical sequence: by, sea, seashells, sells, she, shore, the
|
||
|
|
EXPECT_EQ(strcmp(arr[0], "by"), 0, "Sorted position 0 incorrect");
|
||
|
|
EXPECT_EQ(strcmp(arr[1], "sea"), 0, "Sorted position 1 incorrect");
|
||
|
|
EXPECT_EQ(strcmp(arr[2], "seashells"), 0, "Sorted position 2 incorrect");
|
||
|
|
EXPECT_EQ(strcmp(arr[3], "sells"), 0, "Sorted position 3 incorrect");
|
||
|
|
EXPECT_EQ(strcmp(arr[4], "she"), 0, "Sorted position 4 incorrect");
|
||
|
|
EXPECT_EQ(strcmp(arr[5], "shore"), 0, "Sorted position 5 incorrect");
|
||
|
|
EXPECT_EQ(strcmp(arr[6], "the"), 0, "Sorted position 6 incorrect");
|
||
|
|
|
||
|
|
// Checkpoint 2: Variable Length Validation check
|
||
|
|
// "sea" must strictly precede its extended prefix branch form "seashells"
|
||
|
|
EXPECT_EQ(strcmp(arr[1], "sea") == 0 && strcmp(arr[2], "seashells") == 0, C_TRUE, "Variable-length short-prefix ordering failed");
|
||
|
|
|
||
|
|
printf(" [STAT] In-Place MSD Radix Sort verified successfully. Alphabetic Output: ");
|
||
|
|
for (c_size_t i = 0; i < n; i++) {
|
||
|
|
printf("%s ", arr[i]);
|
||
|
|
}
|
||
|
|
printf("\n");
|
||
|
|
|
||
|
|
C_FREE(arr);
|
||
|
|
return C_TRUE;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(void) {
|
||
|
|
printf("=== Starting Framework Verification: In-Place MSD Radix Sort ===\n");
|
||
|
|
if (test_inplace_msd_radix_sort_execution()) {
|
||
|
|
printf(" [PASS] Variable-Length In-Place Cyclic Swap Permutations and Array Pointer Re-maps Verified.\n");
|
||
|
|
} else {
|
||
|
|
printf(" [FAIL] Radix Partition Tree In-Place Structural Analysis Anomalies Intercepted.\n");
|
||
|
|
}
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|