Entropyk/bindings/c/tests/test_lifecycle.c
Sepehr fa480ed303 feat: implement mass balance validation for Story 7.1
- Added port_mass_flows to Component trait and implements for core components.
- Added System::check_mass_balance and integrated it into the solver.
- Restored connect methods for ExpansionValve, Compressor, and Pipe to fix integration tests.
- Updated Python and C bindings for validation errors.
- Updated sprint status and story documentation.
2026-02-21 23:21:34 +01:00

54 lines
1.5 KiB
C

/**
* Test: System lifecycle (create/free cycle)
*
* Verifies that systems can be created and freed without memory leaks.
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "entropyk.h"
int main() {
printf("Test: System lifecycle\n");
/* Test 1: Create and free a system */
printf(" Test 1: Create and free single system... ");
EntropykSystem* sys = entropyk_system_create();
assert(sys != NULL);
entropyk_system_free(sys);
printf("PASS\n");
/* Test 2: Free null pointer (should not crash) */
printf(" Test 2: Free null pointer... ");
entropyk_system_free(NULL);
printf("PASS\n");
/* Test 3: Multiple create/free cycles */
printf(" Test 3: Multiple create/free cycles... ");
for (int i = 0; i < 100; i++) {
EntropykSystem* s = entropyk_system_create();
assert(s != NULL);
entropyk_system_free(s);
}
printf("PASS\n");
/* Test 4: Node count on empty system */
printf(" Test 4: Node count on empty system... ");
sys = entropyk_system_create();
assert(entropyk_system_node_count(sys) == 0);
assert(entropyk_system_edge_count(sys) == 0);
entropyk_system_free(sys);
printf("PASS\n");
/* Test 5: Null pointer handling */
printf(" Test 5: Null pointer handling... ");
assert(entropyk_system_node_count(NULL) == 0);
assert(entropyk_system_edge_count(NULL) == 0);
assert(entropyk_system_state_vector_len(NULL) == 0);
printf("PASS\n");
printf("All lifecycle tests PASSED\n");
return 0;
}