/**
 * 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;
}
