bzr branch
http://gegoxaren.bato24.eu/bzr/%2Bjunk/c_sdl_joypad_ducktape
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
1 |
#include <stdio.h> |
2 |
#include <assert.h> |
|
|
19
by Gustav Hatvigsson
* Started working on some tests, they do not work... yet. |
3 |
#include "../../src/DynamicArray.h" |
4 |
||
5 |
void test_for_each (DynamicArray * self, void * item, void * data) { |
|
|
20
by Gustav Hatvigsson
* removed an assert and added an other... |
6 |
/* We do not care for the array at all, rely. Why it can be passed to the |
|
19
by Gustav Hatvigsson
* Started working on some tests, they do not work... yet. |
7 |
* for_each is becouse it may be useful when dealing with recursive cases,
|
8 |
* or something...
|
|
9 |
*/
|
|
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
10 |
int * m_item = item; |
11 |
fprintf (stdout,"%d\n", *m_item); |
|
|
19
by Gustav Hatvigsson
* Started working on some tests, they do not work... yet. |
12 |
}
|
13 |
||
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
14 |
int main (int argc, char ** argv) { |
|
19
by Gustav Hatvigsson
* Started working on some tests, they do not work... yet. |
15 |
|
16 |
int initial_size = 5; |
|
17 |
|
|
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
18 |
DynamicArray * array = dynamic_array_new (initial_size, NULL); |
|
19
by Gustav Hatvigsson
* Started working on some tests, they do not work... yet. |
19 |
|
20 |
assert (dynamic_array_size (array) == initial_size); |
|
21 |
assert (dynamic_array_len (array) == 0); |
|
22 |
|
|
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
23 |
int num_itt = 1000; |
|
19
by Gustav Hatvigsson
* Started working on some tests, they do not work... yet. |
24 |
for (int i = 0; i < num_itt; i++) { |
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
25 |
int * data = malloc (sizeof (int)); |
26 |
*data = i; |
|
27 |
dynamic_array_add (array, data); |
|
28 |
|
|
29 |
int * i_n = dynamic_array_get (array, i); |
|
30 |
assert ( *i_n == i); |
|
|
19
by Gustav Hatvigsson
* Started working on some tests, they do not work... yet. |
31 |
} |
32 |
|
|
33 |
assert (dynamic_array_size (array) != initial_size); |
|
|
26
by Gustav Hartvigsson
* Fixed the DynamicArray |
34 |
assert (dynamic_array_len (array) == num_itt); |
35 |
|
|
36 |
dynamic_array_for_each (array, (ForEachFunc) test_for_each, NULL); |
|
37 |
|
|
38 |
dynamic_array_free (array); |
|
39 |
|
|
40 |
return 0; |
|
|
19
by Gustav Hatvigsson
* Started working on some tests, they do not work... yet. |
41 |
}
|