bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
1 |
#include "SimpleTypeSystem.h" |
2 |
#include "test_macros.h" |
|
3 |
#include <stdlib.h> |
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
4 |
#include <stdint.h> |
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
5 |
#include <time.h> |
6 |
||
7 |
int test_dynamic_array (void) { |
|
8 |
setup_unit (); |
|
9 |
|
|
10 |
SDynamicArray * array = NULL; |
|
11 |
array = s_dynamic_array_new (20, NULL); |
|
12 |
|
|
13 |
test_case (array != NULL, "Array is not null"); |
|
14 |
|
|
15 |
test_case (s_dynamic_array_size (array) == 20, "The array maximum size is 20"); |
|
16 |
|
|
17 |
s_print ("Adding a random number to a random possision in the array" |
|
18 |
" (bettween 0 and 20).\n"); |
|
19 |
|
|
20 |
srand(time(NULL)); |
|
21 |
|
|
22 |
int r_n = rand (); |
|
23 |
int r_p = rand () % 20; |
|
24 |
|
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
25 |
s_dynamic_array_set (array, r_p, (spointer)(intptr_t) r_n); |
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
26 |
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
27 |
test_case ((intptr_t) s_dynamic_array_get (array, r_p) == r_n, |
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
28 |
"The the inserted random number matches the generated number."); |
29 |
|
|
30 |
s_print ("Adding a number (12345) to index 21\n"); |
|
31 |
|
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
32 |
s_dynamic_array_set (array, 21, (spointer)(intptr_t) 12345); |
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
33 |
|
34 |
test_case (s_dynamic_array_size (array) > 20, "The new size is larger then the old size."); |
|
35 |
|
|
36 |
s_print ("Filling array with numbers: 0-32\n"); |
|
37 |
|
|
38 |
for (int i = 0; i < s_dynamic_array_size (array); i++) { |
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
39 |
s_dynamic_array_set (array, i, (spointer)(intptr_t) i); |
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
40 |
} |
41 |
for (int i = 0; i < s_dynamic_array_size (array); i++) { |
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
42 |
int got_val = (intptr_t) s_dynamic_array_get(array, i); |
43 |
test_case (got_val == i, "The stored value (%d) matches the expected value (%d).", (int) i, got_val); |
|
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
44 |
} |
45 |
|
|
|
48
by Gustav Hartvigsson
* Finnished SLinkedList. |
46 |
s_dynamic_array_free (array, FALSE); |
47 |
|
|
|
47
by Gustav Hartvigsson
* Added a few skeletal functions to Callback.h |
48 |
end_unit (); |
49 |
}
|