28 void test(
int test_condition,
char* function_tested,
char* test_name) {
29 printf(
"%s %s", function_tested, test_name);
30 if (!test_condition) {
41 char* function_tested =
"vector_alloc";
43 test(vec_zero == NULL, function_tested,
"0 size object");
46 test(vec_no_data != NULL, function_tested,
"0 length vector alloc");
47 test(vec_no_data->
data != NULL, function_tested,
"0 length vector data");
48 test(vec_no_data->
data_length == 0, function_tested,
"0 length vector data_length");
49 test(vec_no_data->
allocd_length == 1, function_tested,
"0 length vector allocd_length");
50 test(vec_no_data->
object_size == 2, function_tested,
"0 length vector object_size");
54 test(vec_normal != NULL, function_tested,
"Standard vector alloc");
55 test(vec_normal->
data != NULL, function_tested,
"Standard vector data");
56 test(vec_normal->
data_length == 6, function_tested,
"Standard vector data_length");
57 test(vec_normal->
allocd_length == 7, function_tested,
"Standard vector allocd_length");
58 test(vec_normal->
object_size == 2, function_tested,
"Standard vector object_size");
63 char* function_tested =
"vector_realloc";
68 test(vec_normal != NULL, function_tested,
"Normal vector");
69 test(vec_normal->
data != NULL, function_tested,
"Normal vector data");
70 test(vec_normal->
data_length == 2, function_tested,
"Normal vector data_length");
71 test(vec_normal->
allocd_length == 3, function_tested,
"Normal vector allocd_length");
72 test(vec_normal->
object_size == 2, function_tested,
"Normal vector object_size");
75 test(vec_normal != NULL, function_tested,
"Normal vector");
76 test(vec_normal->
data != NULL, function_tested,
"Normal vector data");
77 test(vec_normal->
data_length == 10, function_tested,
"Normal vector data_length");
78 test(vec_normal->
allocd_length == 11, function_tested,
"Normal vector allocd_length");
79 test(vec_normal->
object_size == 2, function_tested,
"Normal vector object_size");
83 test(vec_no_data != NULL, function_tested,
"no_data vector");
84 test(vec_no_data->
data != NULL, function_tested,
"no_data vector data");
85 test(vec_no_data->
data_length == 10, function_tested,
"no_data vector data_length");
86 test(vec_no_data->
allocd_length == 11, function_tested,
"no_data vector allocd_length");
87 test(vec_no_data->
object_size == 2, function_tested,
"no_data vector object_size");
92 char* function_tested =
"vector_init";
93 double* data = malloc(
sizeof(
double[3]));
94 vector* vec_init =
vector_init(data,
sizeof(
double)*2,
sizeof(
double)*3,
sizeof(
double));
95 test(vec_init != NULL, function_tested,
"vec_init vector");
96 test(vec_init->
data != NULL, function_tested,
"vec_init vector data");
97 test(vec_init->
data_length ==
sizeof(
double)*2, function_tested,
"vec_init vector data_length");
98 test(vec_init->
allocd_length ==
sizeof(
double)*3, function_tested,
"vec_init vector allocd_length");
99 test(vec_init->
object_size ==
sizeof(
double), function_tested,
"vec_init vector object_size");
102 double* no_data = NULL;
104 test(vec_no_length == NULL, function_tested,
"vec_no_length vector");
107 test(vec_no_data != NULL, function_tested,
"vec_no_data vector");
108 test(vec_no_data->
data == NULL, function_tested,
"vec_no_data vector data");
109 test(vec_no_data->
data_length == 0, function_tested,
"vec_no_data vector data_length");
110 test(vec_no_data->
allocd_length == 0, function_tested,
"vec_no_data vector allocd_length");
111 test(vec_no_data->
object_size ==
sizeof(
double), function_tested,
"vec_no_data vector object_size");
116 char* function_tested =
"vector_insert";
119 double* data_1 = malloc(
sizeof(
double[3]));
120 vector* vector_1 =
vector_init(data_1,
sizeof(
double)*3,
sizeof(
double)*3,
sizeof(
double));
121 double insert_1[2] = {0.,1.};
122 vector_insert(vector_1, insert_1, insert_1+
sizeof(insert_1), 0, &ierr);
124 test(p_1[0] == 0., function_tested,
"vec_insert data 0");
125 test(p_1[1] == 1., function_tested,
"vec_insert data 1");
130 double insert_2[2] = {0., 1.};
132 vector_insert(vector_2, insert_2, insert_2+
sizeof(insert_2), 0, &ierr);
133 test(p_2[0] == 0., function_tested,
"vec_insert data 0");
134 test(p_2[1] == 1., function_tested,
"vec_insert data 1");
137 double* data_3 = malloc(
sizeof(
double[3]));
138 vector* vector_3 =
vector_init(data_3,
sizeof(
double)*3,
sizeof(
double)*3,
sizeof(
double));
139 double insert_3[6] = {0., 1., 2., 3., 4., 5.};
140 vector_insert(vector_3, insert_3, insert_3+
sizeof(insert_3),
sizeof(
double)*3, &ierr);
142 test(p_3[3] == 0., function_tested,
"vec_insert data 3");
143 test(p_3[4] == 1., function_tested,
"vec_insert data 4");
144 test(p_3[8] == 5., function_tested,
"vec_insert data 8");