#include "c_HeapSort.h" #include #include #include #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 false; \ } \ } while(0) typedef struct { int log_id; float core_temperature; } SensorLog; int compareSensorLogs(const void* a, const void* b) { const SensorLog* s1 = (const SensorLog*)a; const SensorLog* s2 = (const SensorLog*)b; if (s1->core_temperature < s2->core_temperature) return -1; if (s1->core_temperature > s2->core_temperature) return 1; return 0; } int compareInts(const void* a, const void* b) { return (*(int*)a - *(int*)b); } bool test_heapsort_inverted_array(void) { int datasets[] = { 100, 90, 80, 70, 60, 50, 40, 30, 20, 10 }; c_size_t total = sizeof(datasets) / sizeof(datasets); c_HeapSort(datasets, total, sizeof(int), compareInts); for (c_size_t i = 0; i < total - 1; i++) { EXPECT_EQ(datasets[i] <= datasets[i+1], true, "Inverted array sequence failed"); } return true; } bool test_heapsort_structures(void) { SensorLog logs[] = { { 901, 45.2f }, { 902, 101.4f}, { 903, -12.6f}, // Target absolute minimum (Must map to index 0) { 904, 32.0f }, { 905, 78.9f } }; c_size_t count = C_ARRAY_SIZE(logs); c_HeapSort(logs, count, sizeof(SensorLog), compareSensorLogs); // Verify structural sorting order consistency EXPECT_EQ(logs[0].log_id, 903, "Index 0 check failed"); EXPECT_EQ(logs[1].log_id, 904, "Index 1 check failed"); EXPECT_EQ(logs[2].log_id, 901, "Index 2 check failed"); EXPECT_EQ(logs[3].log_id, 905, "Index 3 check failed"); EXPECT_EQ(logs[4].log_id, 902, "Index 4 check failed"); return true; } int main(void) { printf("=== Starting Robust Fixed Framework Unit Testing ===\n"); if (test_heapsort_inverted_array() && test_heapsort_structures()) { printf(" [PASS] All Heapsort Pipeline Re-allocations Passed Correctly.\n"); } else { printf(" [FAIL] Test Sequence Intercepted Error.\n"); } return 0; }