-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.c
69 lines (55 loc) · 1.46 KB
/
tests.c
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
#include <glib.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "layout.h"
#include "utils.h"
void test_runs() {
g_assert(1 == 1);
}
void test_find_empty_grid() {
Agraph_t *maze = agopen("maze", Agstrictundirected, NULL);
struct maze_grid grid = maze_read_grid(maze);
g_assert(0 == grid.nodes_count);
struct maze_pt3 target = {
.x = 0,
.y = 0,
.z = 0
};
Agnode_t * found = maze_find_in_grid_at_pt(maze, grid, target);
g_assert(NULL == found);
target.x = 1;
target.y = 2;
found = maze_find_in_grid_at_pt(maze, grid, target);
g_assert(NULL == found);
maze_destroy_grid(grid);
agclose(maze);
}
void test_grid_order() {
FILE *maze_in = popen("./grid --width=4 --height=4", "r");
if (NULL == maze_in) {
ERROR_EXIT("Can't load test fixture");
}
Agraph_t *maze = agread(maze_in, NULL);
pclose(maze_in);
struct maze_grid grid = maze_read_grid(maze);
g_assert(16 == grid.nodes_count);
for (size_t i = 0; i < grid.nodes_count; i++) {
struct maze_pt3 target = {
.x = i % 4,
.y = i / 4,
.z = 0
};
Agnode_t * found = maze_find_in_grid_at_pt(maze, grid, target);
g_assert(found == grid.nodes[i]);
}
maze_destroy_grid(grid);
agclose(maze);
}
int main(int argc, char** argv) {
g_test_init(&argc, &argv, NULL);
g_test_add_func("/maze/test_runs", test_runs);
g_test_add_func("/maze/grid_order", test_grid_order);
g_test_add_func("/maze/find_empty_grid", test_find_empty_grid);
return g_test_run();
}