-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld_test.c
149 lines (144 loc) · 5.15 KB
/
world_test.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
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
#include <assert.h>
#include <stdlib.h>
#include "world_test.h"
#include "world.h"
#include "unit.h"
World world;
int test_world_iterate_entities_iterator_callback_called;
void test_world_initialize();
void test_world_entity_allocate();
void test_world_entity_deallocate();
void test_world_iterate_entities();
void test_world_update();
void test_world_deinitialize();
void test_world_entity_allocate_single();
void test_world_entity_allocate_multiple();
void test_world_entity_allocate_after_deallocate();
void test_world_entity_allocate_after_deallocate_once();
void test_world_entity_allocate_after_deallocate_many_times();
void allocate_and_deallocate_entity_once();
void assert_allocated_entity(Entity *, int type);
void test_world_iterate_entities_iterator_callback(Entity *, void *);
void test_world() {
// test_world_initialize();
// test_world_entity_allocate();
// test_world_entity_deallocate();
// test_world_entity_allocate_after_deallocate();
// test_world_update();
}
// void test_world_initialize() {
// world_initialize(&world);
// assert(world.entity_count == 0);
// assert(world.entity_pool_size == 0);
// assert(world.time == 0);
// world_deinitialize(&world);
// }
//
// void test_world_entity_allocate() {
// test_world_entity_allocate_single();
// test_world_entity_allocate_multiple();
// }
//
// void test_world_entity_allocate_single() {
// world_initialize(&world);
// Entity * entity = world_entity_allocate(&world, ENTITY_UNIT);
// assert_allocated_entity(entity, ENTITY_UNIT);
// assert(world.entity_pool_size >= 1);
// assert(world.entity_count == 1);
// assert(&world.entities[0] == entity);
// world_deinitialize(&world);
// }
//
// void test_world_entity_allocate_multiple() {
// world_initialize(&world);
// Entity * a = world_entity_allocate(&world, ENTITY_UNIT);
// assert_allocated_entity(a, ENTITY_UNIT);
// Entity * b = world_entity_allocate(&world, ENTITY_UNIT);
// assert_allocated_entity(b, ENTITY_UNIT);
// Entity * c = world_entity_allocate(&world, ENTITY_UNIT);
// assert_allocated_entity(c, ENTITY_UNIT);
// assert(a != b);
// assert(b != c);
// assert(world.entity_pool_size >= 3);
// assert(world.entity_count == 3);
// world_deinitialize(&world);
// }
//
// void test_world_entity_deallocate() {
// world_initialize(&world);
// Entity * entity_foo = world_entity_allocate(&world, ENTITY_UNIT);
// unit_initialize(&entity_foo->unit);
// Entity * entity_bar = world_entity_allocate(&world, ENTITY_UNIT);
// unit_initialize(&entity_bar->unit);
// world_entity_deallocate(&world, entity_foo);
// assert(entity_foo->type == ENTITY_NONE);
// assert(world.entity_pool_size >= 1);
// assert(world.entity_count == 1);
// world_deinitialize(&world);
// }
//
// void test_world_entity_allocate_after_deallocate() {
// test_world_entity_allocate_after_deallocate_once();
// test_world_entity_allocate_after_deallocate_many_times();
// }
//
// void test_world_entity_allocate_after_deallocate_once() {
// world_initialize(&world);
// allocate_and_deallocate_entity_once();
// assert_allocated_entity(world_entity_allocate(&world, ENTITY_UNIT), ENTITY_UNIT);
// assert(world.entity_count == 1);
// world_deinitialize(&world);
// }
//
// void test_world_entity_allocate_after_deallocate_many_times() {
// const int allocate_deallocate_cycle_count = 1024;
// const int max_expected_pool_size = 512;
// world_initialize(&world);
// for(int i=0; i<allocate_deallocate_cycle_count; i++)
// allocate_and_deallocate_entity_once();
// assert_allocated_entity(world_entity_allocate(&world, ENTITY_UNIT), ENTITY_UNIT);
// assert(world.entity_count == 1);
// assert(world.entity_pool_size < max_expected_pool_size);
// world_deinitialize(&world);
// }
//
// void test_world_update() {
// const float delta = 0.6f;
// const float throttle = 0.8f;
// world_initialize(&world);
// Entity * entity = world_entity_allocate(&world, ENTITY_UNIT);
// unit_initialize(&entity->unit);
// entity->unit.throttle = throttle;
// assert(entity->unit.throttle == throttle);
// world_update(&world, delta);
// Unit unit;
// unit_initialize(&unit);
// unit.throttle = throttle;
// unit_update(&unit, delta);
// assert(unit.position.x == entity->unit.position.x);
// assert(unit.position.y == entity->unit.position.y);
// world_deinitialize(&world);
// }
//
// void test_world_iterate_entities() {
// world_initialize(&world);
// test_world_iterate_entities_iterator_callback_called = 0;
// world_entity_allocate(&world, ENTITY_UNIT);
// world_entity_allocate(&world, ENTITY_UNIT);
// world_iterate_entities(&world, NULL, test_world_iterate_entities_iterator_callback);
// assert(test_world_iterate_entities_iterator_callback_called == 2);
// world_deinitialize(&world);
// }
//
// void allocate_and_deallocate_entity_once() {
// world_entity_deallocate(&world, world_entity_allocate(&world, ENTITY_UNIT));
// }
//
// void test_world_iterate_entities_iterator_callback(Entity * entity, void * arg) {
// ++test_world_iterate_entities_iterator_callback_called;
// }
//
// void assert_allocated_entity(Entity * entity, int type) {
// assert(entity != NULL);
// assert(entity->type == type);
// }