diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-19 12:54:29 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-19 12:54:29 +0200 |
| commit | 00ea2943c81d2b3a8531e8b7b591de3443b1250c (patch) | |
| tree | d3fd1d87f52388a062e42ddbd49fb8dece2dc9df /src/test.c | |
Initial commit
Diffstat (limited to 'src/test.c')
| -rw-r--r-- | src/test.c | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..858aa74 --- /dev/null +++ b/src/test.c @@ -0,0 +1,162 @@ +#include "wmap_parser.h" +#include <time.h> + +void print_component(const wmap_component_t* comp) { + const char* shape_names[] = {"", "X", "Square", "Triangle", "Circle"}; + printf("Component: %s (%.2f, %.2f)", comp->name, comp->x, comp->y); + if (comp->shape != WMAP_SHAPE_NONE) { + printf(" [%s]", shape_names[comp->shape]); + } + printf("\n"); +} + +void print_dependency(const wmap_dependency_t* dep) { + printf("Dependency: %s %s %s\n", dep->from, dep->is_arrow ? "->" : "--", dep->to); +} + +void print_note(const wmap_note_t* note) { + printf("Note: (%.2f, %.2f) %s\n", note->x, note->y, note->text); +} + +void print_stage(const wmap_stage_data_t* stage) { + const char* stage_names[] = {"", "I", "II", "III", "IV"}; + printf("Stage: [%s] %.2f\n", stage_names[stage->stage], stage->value); +} + +void print_group(const wmap_group_t* group) { + int i; + printf("Group: "); + for (i = 0; i < group->member_count; i++) { + printf("%s", group->members[i]); + if (i < group->member_count - 1) printf(", "); + } + printf("\n"); +} + +void print_inertia(const wmap_inertia_t* inertia) { + printf("Inertia: %s\n", inertia->name); +} + +void print_evolution(const wmap_evolution_t* evolution) { + printf("Evolution: %s %+.2f\n", evolution->name, evolution->change); +} + +void print_map_stats(const wmap_map_t* map) { + printf("\n=== Map Statistics ===\n"); + printf("Components: %d\n", map->component_count); + printf("Dependencies: %d\n", map->dependency_count); + printf("Notes: %d\n", map->note_count); + printf("Stages: %d\n", map->stage_count); + printf("Groups: %d\n", map->group_count); + printf("Inertias: %d\n", map->inertia_count); + printf("Evolutions: %d\n", map->evolution_count); + printf("\n"); +} + +void print_map_contents(const wmap_map_t* map) { + int i; + + printf("=== Components ===\n"); + for (i = 0; i < map->component_count; i++) { + print_component(&map->components[i]); + } + + printf("\n=== Dependencies ===\n"); + for (i = 0; i < map->dependency_count; i++) { + print_dependency(&map->dependencies[i]); + } + + printf("\n=== Notes ===\n"); + for (i = 0; i < map->note_count; i++) { + print_note(&map->notes[i]); + } + + printf("\n=== Stages ===\n"); + for (i = 0; i < map->stage_count; i++) { + print_stage(&map->stages[i]); + } + + printf("\n=== Groups ===\n"); + for (i = 0; i < map->group_count; i++) { + print_group(&map->groups[i]); + } + + printf("\n=== Inertias ===\n"); + for (i = 0; i < map->inertia_count; i++) { + print_inertia(&map->inertias[i]); + } + + printf("\n=== Evolutions ===\n"); + for (i = 0; i < map->evolution_count; i++) { + print_evolution(&map->evolutions[i]); + } +} + +int benchmark_parser(const char* filename, int iterations) { + clock_t start, end; + double total_time, avg_time; + int i; + + printf("=== Benchmarking Parser ===\n"); + printf("File: %s\n", filename); + printf("Iterations: %d\n", iterations); + + start = clock(); + + for (i = 0; i < iterations; i++) { + wmap_map_t* map = wmap_parse_file(filename); + if (!map) { + printf("Error: Failed to parse file on iteration %d\n", i); + return 1; + } + wmap_map_free(map); + } + + end = clock(); + total_time = ((double)(end - start)) / CLOCKS_PER_SEC; + avg_time = total_time / iterations; + + printf("Total time: %.4f seconds\n", total_time); + printf("Average time per parse: %.4f seconds\n", avg_time); + printf("Parses per second: %.2f\n", 1.0 / avg_time); + + return 0; +} + +int main(int argc, char* argv[]) { + const char* filename; + wmap_map_t* map; + + if (argc < 2) { + printf("Usage: %s <wmap_file> [benchmark_iterations]\n", argv[0]); + return 1; + } + + filename = argv[1]; + + printf("=== WMAP Parser Test ===\n"); + printf("Parsing file: %s\n", filename); + + map = wmap_parse_file(filename); + if (!map) { + printf("Error: Failed to parse file %s\n", filename); + return 1; + } + + print_map_stats(map); + + if (argc > 2 && strcmp(argv[2], "benchmark") == 0) { + int iterations = 1000; + if (argc > 3) { + iterations = atoi(argv[3]); + } + benchmark_parser(filename, iterations); + } else { + print_map_contents(map); + } + + wmap_map_free(map); + + printf("=== Test Complete ===\n"); + return 0; +} |