aboutsummaryrefslogtreecommitdiff
path: root/src/test.c
blob: 858aa741d71cd7ae03c6749ec3fb4f986eaef938 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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;
}