1 |
/* |
2 |
* Unit test functions for ASCEND: solver/slv_common.c |
3 |
* |
4 |
* Copyright (C) 2005 Jerry St.Clair |
5 |
* |
6 |
* This file is part of the Ascend Environment. |
7 |
* |
8 |
* The Ascend Environment is free software; you can redistribute it |
9 |
* and/or modify it under the terms of the GNU General Public License as |
10 |
* published by the Free Software Foundation; either version 2 of the |
11 |
* License, or (at your option) any later version. |
12 |
* |
13 |
* The Ascend Environment is distributed in hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 |
* General Public License for more details. |
17 |
* |
18 |
* You should have received a copy of the GNU General Public License |
19 |
* along with the program; if not, write to the Free Software Foundation, |
20 |
* Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named |
21 |
* COPYING. |
22 |
*/ |
23 |
|
24 |
#include <stdio.h> |
25 |
#ifdef __WIN32__ |
26 |
#include <io.h> |
27 |
#endif |
28 |
#include "utilities/ascConfig.h" |
29 |
#include "utilities/ascMalloc.h" |
30 |
#include "solver/slv_types.h" |
31 |
#include "solver/rel.h" |
32 |
#include "solver/logrel.h" |
33 |
#include "solver/mtx.h" |
34 |
#include "general/list.h" |
35 |
#include "solver/slv_common.h" |
36 |
#include "CUnit/CUnit.h" |
37 |
#include "test_slv_common.h" |
38 |
#include "assertimpl.h" |
39 |
#include "printutil.h" |
40 |
|
41 |
/* |
42 |
* Independent calculation of a vector dot product. |
43 |
* Nothing fancy, no validation of input. Assumes valid vectors. |
44 |
*/ |
45 |
static real64 slow_inner_product(struct vector_data *vec1, struct vector_data *vec2) |
46 |
{ |
47 |
int32 i; |
48 |
real64 product = 0.0; |
49 |
real64 *p1 = vec1->vec + vec1->rng->low; |
50 |
real64 *p2 = vec2->vec + vec2->rng->low; |
51 |
int32 len = vec1->rng->high - vec1->rng->low + 1; |
52 |
|
53 |
for (i=0 ; i<len ; ++i, ++p1, ++p2) |
54 |
product += *p1 * *p2; |
55 |
|
56 |
return product; |
57 |
} |
58 |
|
59 |
/* |
60 |
* Independent calculation of an array dot product. |
61 |
* Nothing fancy, no validation of input. |
62 |
* Assumes valid arrays of length at least len. |
63 |
*/ |
64 |
static real64 slow_dot_product(int32 len, real64 *array1, real64 *array2) |
65 |
{ |
66 |
int32 i; |
67 |
real64 product = 0.0; |
68 |
|
69 |
for (i=0 ; i<len ; ++i, ++array1, ++array2) |
70 |
product += *array1 * *array2; |
71 |
|
72 |
return product; |
73 |
} |
74 |
|
75 |
/* |
76 |
* Independent calculation of a vector-matrix product. |
77 |
* Nothing fancy, no validation of input. Assumes valid vector & matrix. |
78 |
*/ |
79 |
static void slow_vector_matrix_product(mtx_matrix_t mtx, |
80 |
struct vector_data *vec, |
81 |
struct vector_data *prod, |
82 |
real64 scale) |
83 |
{ |
84 |
int32 row, col; |
85 |
mtx_coord_t coord; |
86 |
int32 limit = vec->rng->high; |
87 |
|
88 |
coord.row = vec->rng->low; |
89 |
for (row=vec->rng->low ; row<=limit ; ++row) { |
90 |
coord.col = vec->rng->low; |
91 |
prod->vec[coord.row] = 0.0; |
92 |
for (col=vec->rng->low ; col<=limit ; ++col) { |
93 |
prod->vec[coord.row] += vec->vec[coord.col] * mtx_value(mtx, &coord); |
94 |
++coord.col; |
95 |
} |
96 |
prod->vec[coord.row] *= scale; |
97 |
++coord.row; |
98 |
} |
99 |
} |
100 |
|
101 |
/* int comparison function for list searches */ |
102 |
static int compare_int32s(CONST VOIDPTR p1, CONST VOIDPTR p2) |
103 |
{ |
104 |
assert((NULL != p1) && (NULL != p2)); |
105 |
return *((int32*)p1) - *((int32*)p2); |
106 |
} |
107 |
|
108 |
|
109 |
/* |
110 |
* This function tests the slv_common.c functions and data structures. |
111 |
* Note that some of the implementation declarated in slv_common.h is |
112 |
* defined in slv.c rather than slv_common.c. This subset of slv_common.h |
113 |
* will be tested along with slv.c elsewhere. |
114 |
*/ |
115 |
static void test_slv_common(void) |
116 |
{ |
117 |
struct vector_data *pvec1; |
118 |
struct vector_data *pvec2; |
119 |
struct vector_data *pvec3; |
120 |
mtx_matrix_t mtx; |
121 |
mtx_coord_t coord; |
122 |
mtx_region_t region; |
123 |
real64 rarray[100]; |
124 |
real64 rarray2[100]; |
125 |
int i; |
126 |
FILE *file_normal; |
127 |
int32 hi[11]; |
128 |
int32 hj[11]; |
129 |
int32 **lnkmap; |
130 |
int32 *lnkvars; |
131 |
struct gl_list_t *col_list; |
132 |
struct gl_list_t *lnkindex_list; |
133 |
int32 lnkindexes[11]; |
134 |
unsigned int pos; |
135 |
unsigned long prior_meminuse; |
136 |
unsigned long cur_meminuse; |
137 |
unsigned long test_meminuse; |
138 |
int i_initialized_lists = FALSE; |
139 |
int i_enabled_printing = FALSE; |
140 |
|
141 |
#ifdef NDEBUG |
142 |
CU_FAIL("test_slv_common() compiled with NDEBUG - some features not tested."); |
143 |
#endif |
144 |
#ifndef MALLOC_DEBUG |
145 |
CU_FAIL("test_slv_common() compiled without MALLOC_DEBUG - memory management not tested."); |
146 |
#endif |
147 |
|
148 |
prior_meminuse = ascmeminuse(); |
149 |
|
150 |
/* set up pooling & recycling */ |
151 |
if (FALSE == gl_pool_initialized()) { |
152 |
gl_init(); |
153 |
gl_init_pool(); |
154 |
i_initialized_lists = TRUE; |
155 |
} |
156 |
|
157 |
for (i=0 ; i<100 ; ++i) { /* create some reals to use later */ |
158 |
rarray[i] = 7/2 * i; |
159 |
} |
160 |
|
161 |
/* test slv_create_vector(), slv_destroy_vector() */ |
162 |
|
163 |
test_meminuse = ascmeminuse(); |
164 |
|
165 |
cur_meminuse = ascmeminuse(); |
166 |
pvec1 = slv_create_vector(-1, 0); /* error - low < 0 */ |
167 |
CU_TEST(NULL == pvec1); |
168 |
|
169 |
slv_destroy_vector(pvec1); |
170 |
CU_TEST(cur_meminuse == ascmeminuse()); |
171 |
|
172 |
cur_meminuse = ascmeminuse(); |
173 |
pvec1 = slv_create_vector(0, -1); /* error - high < 0 */ |
174 |
CU_TEST(NULL == pvec1); |
175 |
|
176 |
slv_destroy_vector(pvec1); |
177 |
CU_TEST(cur_meminuse == ascmeminuse()); |
178 |
|
179 |
cur_meminuse = ascmeminuse(); |
180 |
pvec1 = slv_create_vector(10, 0); /* error - low > high */ |
181 |
CU_TEST(NULL == pvec1); |
182 |
|
183 |
slv_destroy_vector(pvec1); |
184 |
CU_TEST(cur_meminuse == ascmeminuse()); |
185 |
|
186 |
cur_meminuse = ascmeminuse(); |
187 |
pvec1 = slv_create_vector(0, 0); /* ok - low == high */ |
188 |
CU_TEST_FATAL(NULL != pvec1); |
189 |
CU_TEST_FATAL(NULL != pvec1->rng); |
190 |
CU_TEST(0 == pvec1->rng->low); |
191 |
CU_TEST(0 == pvec1->rng->high); |
192 |
CU_TEST(NULL != pvec1->vec); |
193 |
CU_TEST(FALSE == pvec1->accurate); |
194 |
#ifdef MALLOC_DEBUG |
195 |
CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
196 |
CU_TEST(2 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t))); |
197 |
CU_TEST(2 == AllocatedMemory(pvec1->vec, sizeof(real64))); |
198 |
#else |
199 |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
200 |
CU_TEST(1 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t))); |
201 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, sizeof(real64))); |
202 |
#endif |
203 |
|
204 |
slv_destroy_vector(pvec1); |
205 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
206 |
CU_TEST(cur_meminuse == ascmeminuse()); |
207 |
|
208 |
cur_meminuse = ascmeminuse(); |
209 |
pvec1 = slv_create_vector(0, 10); /* ok - low < high */ |
210 |
CU_TEST_FATAL(NULL != pvec1); |
211 |
CU_TEST_FATAL(NULL != pvec1->rng); |
212 |
CU_TEST(0 == pvec1->rng->low); |
213 |
CU_TEST(10 == pvec1->rng->high); |
214 |
CU_TEST(NULL != pvec1->vec); |
215 |
CU_TEST(FALSE == pvec1->accurate); |
216 |
#ifdef MALLOC_DEBUG |
217 |
CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
218 |
CU_TEST(2 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t))); |
219 |
CU_TEST(2 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
220 |
#else |
221 |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
222 |
CU_TEST(1 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t))); |
223 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
224 |
#endif |
225 |
|
226 |
slv_destroy_vector(pvec1); |
227 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
228 |
CU_TEST(cur_meminuse == ascmeminuse()); |
229 |
|
230 |
CU_TEST(test_meminuse == ascmeminuse()); |
231 |
|
232 |
/* test slv_init_vector() */ |
233 |
|
234 |
test_meminuse = ascmeminuse(); |
235 |
|
236 |
cur_meminuse = ascmeminuse(); |
237 |
CU_TEST(2 == slv_init_vector(NULL, 0, 10)); /* error - NULL vec */ |
238 |
CU_TEST(cur_meminuse == ascmeminuse()); |
239 |
|
240 |
cur_meminuse = ascmeminuse(); |
241 |
pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng, vec */ |
242 |
CU_TEST_FATAL(NULL != pvec1); |
243 |
pvec1->rng = NULL; |
244 |
pvec1->vec = NULL; |
245 |
pvec1->accurate = TRUE; |
246 |
|
247 |
CU_TEST(1 == slv_init_vector(pvec1, -1, 10)); /* error - low < 0 */ |
248 |
CU_TEST(NULL == pvec1->rng); |
249 |
CU_TEST(NULL == pvec1->vec); |
250 |
CU_TEST(TRUE == pvec1->accurate); |
251 |
#ifdef MALLOC_DEBUG |
252 |
CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
253 |
#else |
254 |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
255 |
#endif |
256 |
|
257 |
slv_destroy_vector(pvec1); |
258 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
259 |
CU_TEST(cur_meminuse == ascmeminuse()); |
260 |
|
261 |
cur_meminuse = ascmeminuse(); |
262 |
pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng, vec */ |
263 |
CU_TEST_FATAL(NULL != pvec1); |
264 |
pvec1->rng = NULL; |
265 |
pvec1->vec = NULL; |
266 |
pvec1->accurate = TRUE; |
267 |
|
268 |
CU_TEST(1 == slv_init_vector(pvec1, 10, -1)); /* error - high < 0 */ |
269 |
CU_TEST(NULL == pvec1->rng); |
270 |
CU_TEST(NULL == pvec1->vec); |
271 |
CU_TEST(TRUE == pvec1->accurate); |
272 |
#ifdef MALLOC_DEBUG |
273 |
CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
274 |
#else |
275 |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
276 |
#endif |
277 |
|
278 |
slv_destroy_vector(pvec1); |
279 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
280 |
CU_TEST(cur_meminuse == ascmeminuse()); |
281 |
|
282 |
cur_meminuse = ascmeminuse(); |
283 |
pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng, vec */ |
284 |
CU_TEST_FATAL(NULL != pvec1); |
285 |
pvec1->rng = NULL; |
286 |
pvec1->vec = NULL; |
287 |
pvec1->accurate = TRUE; |
288 |
|
289 |
CU_TEST(0 == slv_init_vector(pvec1, 10, 10)); /* ok - low == high */ |
290 |
CU_TEST_FATAL(NULL != pvec1->rng); |
291 |
CU_TEST(10 == pvec1->rng->low); |
292 |
CU_TEST(10 == pvec1->rng->high); |
293 |
CU_TEST(NULL != pvec1->vec); |
294 |
CU_TEST(FALSE == pvec1->accurate); |
295 |
#ifdef MALLOC_DEBUG |
296 |
CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
297 |
CU_TEST(2 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t))); |
298 |
CU_TEST(2 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
299 |
#else |
300 |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
301 |
CU_TEST(1 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t))); |
302 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
303 |
#endif |
304 |
|
305 |
slv_destroy_vector(pvec1); |
306 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
307 |
CU_TEST(cur_meminuse == ascmeminuse()); |
308 |
|
309 |
cur_meminuse = ascmeminuse(); |
310 |
pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng, vec */ |
311 |
CU_TEST_FATAL(NULL != pvec1); |
312 |
pvec1->rng = NULL; |
313 |
pvec1->vec = NULL; |
314 |
pvec1->accurate = TRUE; |
315 |
|
316 |
CU_TEST(0 == slv_init_vector(pvec1, 10, 100)); /* ok - low < high */ |
317 |
CU_TEST_FATAL(NULL != pvec1->rng); |
318 |
CU_TEST(10 == pvec1->rng->low); |
319 |
CU_TEST(100 == pvec1->rng->high); |
320 |
CU_TEST(NULL != pvec1->vec); |
321 |
CU_TEST(FALSE == pvec1->accurate); |
322 |
#ifdef MALLOC_DEBUG |
323 |
CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
324 |
CU_TEST(2 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t))); |
325 |
CU_TEST(2 == AllocatedMemory(pvec1->vec, 101 * sizeof(real64))); |
326 |
#else |
327 |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
328 |
CU_TEST(1 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t))); |
329 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 101 * sizeof(real64))); |
330 |
#endif |
331 |
|
332 |
slv_destroy_vector(pvec1); |
333 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
334 |
CU_TEST(cur_meminuse == ascmeminuse()); |
335 |
|
336 |
cur_meminuse = ascmeminuse(); |
337 |
pvec1 = slv_create_vector(0,0); /* create a vector with data */ |
338 |
CU_TEST_FATAL(NULL != pvec1); |
339 |
#ifdef MALLOC_DEBUG |
340 |
CU_TEST(2 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
341 |
CU_TEST(2 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t))); |
342 |
CU_TEST(2 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64))); |
343 |
#else |
344 |
CU_TEST(1 == AllocatedMemory(pvec1, sizeof(struct vector_data))); |
345 |
CU_TEST(1 == AllocatedMemory(pvec1->rng, sizeof(mtx_range_t))); |
346 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64))); |
347 |
#endif |
348 |
|
349 |
pvec1->accurate = TRUE; |
350 |
pvec1->vec[0] = rarray[0]; |
351 |
|
352 |
CU_TEST(1 == slv_init_vector(pvec1, -1, 100)); /* error - low < 0 */ |
353 |
CU_TEST_FATAL(NULL != pvec1->rng); |
354 |
CU_TEST(0 == pvec1->rng->low); |
355 |
CU_TEST(0 == pvec1->rng->high); |
356 |
CU_TEST_FATAL(NULL != pvec1->vec); |
357 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
358 |
CU_TEST(TRUE == pvec1->accurate); |
359 |
#ifdef MALLOC_DEBUG |
360 |
CU_TEST(2 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64))); |
361 |
#else |
362 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64))); |
363 |
#endif |
364 |
|
365 |
CU_TEST(1 == slv_init_vector(pvec1, 1, 0)); /* error - high < low */ |
366 |
CU_TEST_FATAL(NULL != pvec1->rng); |
367 |
CU_TEST(0 == pvec1->rng->low); |
368 |
CU_TEST(0 == pvec1->rng->high); |
369 |
CU_TEST_FATAL(NULL != pvec1->vec); |
370 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
371 |
CU_TEST(TRUE == pvec1->accurate); |
372 |
#ifdef MALLOC_DEBUG |
373 |
CU_TEST(2 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64))); |
374 |
#else |
375 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 1 * sizeof(real64))); |
376 |
#endif |
377 |
|
378 |
CU_TEST(0 == slv_init_vector(pvec1, 0, 1)); /* ok - high > low */ |
379 |
CU_TEST_FATAL(NULL != pvec1->rng); |
380 |
CU_TEST(0 == pvec1->rng->low); |
381 |
CU_TEST(1 == pvec1->rng->high); |
382 |
CU_TEST_FATAL(NULL != pvec1->vec); |
383 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
384 |
CU_TEST(FALSE == pvec1->accurate); |
385 |
#ifdef MALLOC_DEBUG |
386 |
CU_TEST(2 == AllocatedMemory(pvec1->vec, 2 * sizeof(real64))); |
387 |
#else |
388 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 2 * sizeof(real64))); |
389 |
#endif |
390 |
|
391 |
pvec1->accurate = TRUE; |
392 |
pvec1->vec[1] = rarray[1]; |
393 |
|
394 |
CU_TEST(0 == slv_init_vector(pvec1, 9, 10)); /* ok - high > low */ |
395 |
CU_TEST_FATAL(NULL != pvec1->rng); |
396 |
CU_TEST(9 == pvec1->rng->low); |
397 |
CU_TEST(10 == pvec1->rng->high); |
398 |
CU_TEST_FATAL(NULL != pvec1->vec); |
399 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
400 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[1], rarray[1], 0.00001); |
401 |
CU_TEST(FALSE == pvec1->accurate); |
402 |
#ifdef MALLOC_DEBUG |
403 |
CU_TEST(2 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
404 |
#else |
405 |
CU_TEST(1 == AllocatedMemory(pvec1->vec, 11 * sizeof(real64))); |
406 |
#endif |
407 |
|
408 |
slv_destroy_vector(pvec1); |
409 |
CU_TEST(0 == AllocatedMemory(pvec1, 0)); |
410 |
CU_TEST(cur_meminuse == ascmeminuse()); |
411 |
|
412 |
CU_TEST(test_meminuse == ascmeminuse()); |
413 |
|
414 |
/* test slv_zero_vector() */ |
415 |
|
416 |
test_meminuse = ascmeminuse(); |
417 |
|
418 |
#ifndef ASC_NO_ASSERTIONS |
419 |
asc_assert_catch(TRUE); /* prepare to test assertions */ |
420 |
|
421 |
asc_assert_reset(); |
422 |
if (0 == setjmp(g_asc_test_env)) |
423 |
slv_zero_vector(NULL); /* error - NULL vec */ |
424 |
CU_TEST(TRUE == asc_assert_failed()); |
425 |
|
426 |
pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
427 |
CU_TEST_FATAL(NULL != pvec1); |
428 |
pvec1->rng = NULL; |
429 |
pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
430 |
|
431 |
asc_assert_reset(); |
432 |
if (0 == setjmp(g_asc_test_env)) |
433 |
slv_zero_vector(pvec1); /* error - NULL vec->rng */ |
434 |
CU_TEST(TRUE == asc_assert_failed()); |
435 |
|
436 |
pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
437 |
ascfree(pvec1->vec); |
438 |
pvec1->vec = NULL; |
439 |
|
440 |
asc_assert_reset(); |
441 |
if (0 == setjmp(g_asc_test_env)) |
442 |
slv_zero_vector(pvec1); /* error - NULL vec->vec */ |
443 |
CU_TEST(TRUE == asc_assert_failed()); |
444 |
|
445 |
pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
446 |
pvec1->rng->low = -1; |
447 |
pvec1->rng->high = 10; |
448 |
|
449 |
asc_assert_reset(); |
450 |
if (0 == setjmp(g_asc_test_env)) |
451 |
slv_zero_vector(pvec1); /* error - low < 0 */ |
452 |
CU_TEST(TRUE == asc_assert_failed()); |
453 |
|
454 |
pvec1->rng->low = 11; |
455 |
|
456 |
asc_assert_reset(); |
457 |
if (0 == setjmp(g_asc_test_env)) |
458 |
slv_zero_vector(pvec1); /* error - low > high */ |
459 |
CU_TEST(TRUE == asc_assert_failed()); |
460 |
|
461 |
slv_destroy_vector(pvec1); |
462 |
|
463 |
asc_assert_catch(FALSE); /* done testing assertions */ |
464 |
#endif /* !ASC_NO_ASSERTIONS */ |
465 |
|
466 |
pvec1 = slv_create_vector(0,0); /* create & initialize a 1-element vector */ |
467 |
CU_TEST_FATAL(NULL != pvec1); |
468 |
|
469 |
pvec1->vec[0] = rarray[0]; |
470 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
471 |
|
472 |
slv_zero_vector(pvec1); |
473 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], 0.0, 0.00001); |
474 |
|
475 |
CU_TEST_FATAL(0 == slv_init_vector(pvec1, 0, 9)); /* redimension to larger vector */ |
476 |
|
477 |
for (i=0 ; i<10 ; ++i) { |
478 |
pvec1->vec[i] = rarray[i]; /* initialize & check the data */ |
479 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); |
480 |
} |
481 |
|
482 |
slv_zero_vector(pvec1); |
483 |
for (i=0 ; i<10 ; ++i) { |
484 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], 0.0, 0.00001); /* all data should now be 0.0 */ |
485 |
} |
486 |
|
487 |
for (i=0 ; i<10 ; ++i) { |
488 |
pvec1->vec[i] = rarray[i]; /* initialize again */ |
489 |
} |
490 |
|
491 |
pvec1->rng->low = 5; |
492 |
pvec1->rng->high = 7; |
493 |
|
494 |
slv_zero_vector(pvec1); |
495 |
for (i=0 ; i<5 ; ++i) { |
496 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); |
497 |
} |
498 |
for (i=5 ; i<8 ; ++i) { |
499 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], 0.0, 0.00001); |
500 |
} |
501 |
for (i=8 ; i<10 ; ++i) { |
502 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); |
503 |
} |
504 |
|
505 |
slv_destroy_vector(pvec1); |
506 |
|
507 |
CU_TEST(test_meminuse == ascmeminuse()); |
508 |
|
509 |
/* test slv_copy_vector() */ |
510 |
|
511 |
test_meminuse = ascmeminuse(); |
512 |
|
513 |
#ifndef ASC_NO_ASSERTIONS |
514 |
asc_assert_catch(TRUE); /* prepare to test assertions */ |
515 |
|
516 |
pvec1 = slv_create_vector(0,10); |
517 |
CU_TEST_FATAL(NULL != pvec1); |
518 |
|
519 |
asc_assert_reset(); |
520 |
if (0 == setjmp(g_asc_test_env)) |
521 |
slv_copy_vector(NULL, pvec1); /* error - NULL srcvec */ |
522 |
CU_TEST(TRUE == asc_assert_failed()); |
523 |
|
524 |
asc_assert_reset(); |
525 |
if (0 == setjmp(g_asc_test_env)) |
526 |
slv_copy_vector(pvec1, NULL); /* error - NULL destvec */ |
527 |
CU_TEST(TRUE == asc_assert_failed()); |
528 |
|
529 |
pvec2 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
530 |
CU_TEST_FATAL(NULL != pvec2); |
531 |
pvec2->rng = NULL; |
532 |
pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
533 |
|
534 |
asc_assert_reset(); |
535 |
if (0 == setjmp(g_asc_test_env)) |
536 |
slv_copy_vector(pvec2, pvec1); /* error - NULL srcvec->rng */ |
537 |
CU_TEST(TRUE == asc_assert_failed()); |
538 |
|
539 |
asc_assert_reset(); |
540 |
if (0 == setjmp(g_asc_test_env)) |
541 |
slv_copy_vector(pvec1, pvec2); /* error - NULL destvec->rng */ |
542 |
CU_TEST(TRUE == asc_assert_failed()); |
543 |
|
544 |
pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
545 |
ascfree(pvec2->vec); |
546 |
pvec2->vec = NULL; |
547 |
|
548 |
asc_assert_reset(); |
549 |
if (0 == setjmp(g_asc_test_env)) |
550 |
slv_copy_vector(pvec2, pvec1); /* error - NULL srcvec->vec */ |
551 |
CU_TEST(TRUE == asc_assert_failed()); |
552 |
|
553 |
asc_assert_reset(); |
554 |
if (0 == setjmp(g_asc_test_env)) |
555 |
slv_copy_vector(pvec1, pvec2); /* error - NULL destvec->vec */ |
556 |
CU_TEST(TRUE == asc_assert_failed()); |
557 |
|
558 |
pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
559 |
pvec2->rng->low = -1; |
560 |
pvec2->rng->high = 10; |
561 |
|
562 |
asc_assert_reset(); |
563 |
if (0 == setjmp(g_asc_test_env)) |
564 |
slv_copy_vector(pvec2, pvec1); /* error - srcvec->rng->low < 0 */ |
565 |
CU_TEST(TRUE == asc_assert_failed()); |
566 |
|
567 |
asc_assert_reset(); |
568 |
if (0 == setjmp(g_asc_test_env)) |
569 |
slv_copy_vector(pvec1, pvec2); /* error - destvec->rng->low < 0 */ |
570 |
CU_TEST(TRUE == asc_assert_failed()); |
571 |
|
572 |
pvec2->rng->low = 11; |
573 |
|
574 |
asc_assert_reset(); |
575 |
if (0 == setjmp(g_asc_test_env)) |
576 |
slv_copy_vector(pvec2, pvec1); /* error - srcvec low > high */ |
577 |
CU_TEST(TRUE == asc_assert_failed()); |
578 |
|
579 |
slv_destroy_vector(pvec1); |
580 |
slv_destroy_vector(pvec2); |
581 |
|
582 |
asc_assert_catch(FALSE); /* done testing assertions */ |
583 |
#endif /* !ASC_NO_ASSERTIONS */ |
584 |
|
585 |
pvec1 = slv_create_vector(0,0); /* create & initialize a 1-element vectors */ |
586 |
pvec2 = slv_create_vector(0,0); |
587 |
CU_TEST_FATAL(NULL != pvec1); |
588 |
|
589 |
pvec1->vec[0] = rarray[0]; |
590 |
pvec2->vec[0] = rarray[5]; |
591 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
592 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[5], 0.00001); |
593 |
|
594 |
slv_copy_vector(pvec1, pvec2); |
595 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
596 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[0], 0.00001); |
597 |
|
598 |
CU_TEST_FATAL(0 == slv_init_vector(pvec1, 0, 9)); /* redimension pvec1 to larger vector */ |
599 |
|
600 |
for (i=0 ; i<10 ; ++i) { |
601 |
pvec1->vec[i] = rarray[i]; /* initialize & check the data */ |
602 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); |
603 |
} |
604 |
|
605 |
pvec2->vec[0] = rarray[8]; |
606 |
slv_copy_vector(pvec2, pvec1); /* copy 1 element*/ |
607 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[8], 0.00001); |
608 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[8], 0.00001); |
609 |
for (i=1 ; i<10 ; ++i) { |
610 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* rest of data should be intact */ |
611 |
} |
612 |
|
613 |
pvec2->vec[0] = rarray[3]; |
614 |
pvec1->rng->low = 9; |
615 |
pvec1->rng->high = 9; |
616 |
slv_copy_vector(pvec1, pvec2); /* copy 1 element other way*/ |
617 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[9], 0.00001); |
618 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[8], 0.00001); |
619 |
for (i=1 ; i<10 ; ++i) { |
620 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in src should be intact */ |
621 |
} |
622 |
|
623 |
CU_TEST_FATAL(0 == slv_init_vector(pvec2, 0, 9)); /* redimension pvec2 to larger vector */ |
624 |
slv_zero_vector(pvec2); /* zero the destvec */ |
625 |
pvec1->rng->low = 0; |
626 |
pvec1->rng->high = 9; |
627 |
slv_copy_vector(pvec1, pvec2); /* copy all elements */ |
628 |
for (i=0 ; i<10 ; ++i) { |
629 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], pvec2->vec[i], 0.00001); /* data should be the same */ |
630 |
} |
631 |
|
632 |
for (i=0 ; i<10 ; ++i) { |
633 |
pvec2->vec[i] = rarray[9-i]; /* reinitialize & check the data */ |
634 |
} |
635 |
pvec2->rng->low = 3; |
636 |
pvec2->rng->high = 6; |
637 |
slv_copy_vector(pvec2, pvec1); /* copy a subset of elements to start of destvec */ |
638 |
for (i=3 ; i<7 ; ++i) { |
639 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i-3], rarray[9-i], 0.00001); /* data should be the same */ |
640 |
} |
641 |
for (i=4 ; i<10 ; ++i) { |
642 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data should be the same */ |
643 |
} |
644 |
|
645 |
slv_destroy_vector(pvec1); |
646 |
slv_destroy_vector(pvec2); |
647 |
|
648 |
CU_TEST(test_meminuse == ascmeminuse()); |
649 |
|
650 |
/* test slv_inner_product() */ |
651 |
|
652 |
test_meminuse = ascmeminuse(); |
653 |
|
654 |
#ifndef ASC_NO_ASSERTIONS |
655 |
asc_assert_catch(TRUE); /* prepare to test assertions */ |
656 |
|
657 |
pvec1 = slv_create_vector(0,10); |
658 |
CU_TEST_FATAL(NULL != pvec1); |
659 |
|
660 |
asc_assert_reset(); |
661 |
if (0 == setjmp(g_asc_test_env)) |
662 |
slv_inner_product(NULL, pvec1); /* error - NULL vec1 */ |
663 |
CU_TEST(TRUE == asc_assert_failed()); |
664 |
|
665 |
asc_assert_reset(); |
666 |
if (0 == setjmp(g_asc_test_env)) |
667 |
slv_inner_product(pvec1, NULL); /* error - NULL vec2 */ |
668 |
CU_TEST(TRUE == asc_assert_failed()); |
669 |
|
670 |
pvec2 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
671 |
CU_TEST_FATAL(NULL != pvec2); |
672 |
pvec2->rng = NULL; |
673 |
pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
674 |
|
675 |
asc_assert_reset(); |
676 |
if (0 == setjmp(g_asc_test_env)) |
677 |
slv_inner_product(pvec2, pvec1); /* error - NULL vec1->rng */ |
678 |
CU_TEST(TRUE == asc_assert_failed()); |
679 |
|
680 |
asc_assert_reset(); |
681 |
if (0 == setjmp(g_asc_test_env)) |
682 |
slv_inner_product(pvec1, pvec2); /* error - NULL vec2->rng */ |
683 |
CU_TEST(TRUE == asc_assert_failed()); |
684 |
|
685 |
pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
686 |
ascfree(pvec2->vec); |
687 |
pvec2->vec = NULL; |
688 |
|
689 |
asc_assert_reset(); |
690 |
if (0 == setjmp(g_asc_test_env)) |
691 |
slv_inner_product(pvec2, pvec1); /* error - NULL vec1->vec */ |
692 |
CU_TEST(TRUE == asc_assert_failed()); |
693 |
|
694 |
asc_assert_reset(); |
695 |
if (0 == setjmp(g_asc_test_env)) |
696 |
slv_inner_product(pvec1, pvec2); /* error - NULL vec2->vec */ |
697 |
CU_TEST(TRUE == asc_assert_failed()); |
698 |
|
699 |
pvec2->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
700 |
pvec2->rng->low = -1; |
701 |
pvec2->rng->high = 10; |
702 |
|
703 |
asc_assert_reset(); |
704 |
if (0 == setjmp(g_asc_test_env)) |
705 |
slv_inner_product(pvec2, pvec1); /* error - vec1->rng->low < 0 */ |
706 |
CU_TEST(TRUE == asc_assert_failed()); |
707 |
|
708 |
asc_assert_reset(); |
709 |
if (0 == setjmp(g_asc_test_env)) |
710 |
slv_inner_product(pvec1, pvec2); /* error - vec2->rng->low < 0 */ |
711 |
CU_TEST(TRUE == asc_assert_failed()); |
712 |
|
713 |
pvec2->rng->low = 11; |
714 |
|
715 |
asc_assert_reset(); |
716 |
if (0 == setjmp(g_asc_test_env)) |
717 |
slv_inner_product(pvec2, pvec1); /* error - vec1 low > high */ |
718 |
CU_TEST(TRUE == asc_assert_failed()); |
719 |
|
720 |
slv_destroy_vector(pvec1); |
721 |
slv_destroy_vector(pvec2); |
722 |
|
723 |
asc_assert_catch(FALSE); /* done testing assertions */ |
724 |
#endif /* !ASC_NO_ASSERTIONS */ |
725 |
|
726 |
pvec1 = slv_create_vector(0,0); /* create & initialize a 1-element vectors */ |
727 |
pvec2 = slv_create_vector(0,0); |
728 |
CU_TEST_FATAL(NULL != pvec1); |
729 |
CU_TEST_FATAL(NULL != pvec2); |
730 |
|
731 |
pvec1->vec[0] = rarray[0]; |
732 |
pvec2->vec[0] = rarray[5]; |
733 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
734 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[5], 0.00001); |
735 |
|
736 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_inner_product(pvec1, pvec2), 0.00001); |
737 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_inner_product(pvec1, pvec2), 0.00001); |
738 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[0], 0.00001); |
739 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], rarray[5], 0.00001); |
740 |
|
741 |
CU_TEST_FATAL(0 == slv_init_vector(pvec1, 0, 9)); /* redimension vectors larger */ |
742 |
CU_TEST_FATAL(0 == slv_init_vector(pvec2, 0, 9)); |
743 |
|
744 |
for (i=0 ; i<10 ; ++i) { |
745 |
pvec1->vec[i] = rarray[i]; /* initialize & check the data */ |
746 |
pvec2->vec[i] = 2.0; |
747 |
} |
748 |
/* check entire vectors */ |
749 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_inner_product(pvec1, pvec2), 0.00001); |
750 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_inner_product(pvec1, pvec2), 0.00001); |
751 |
|
752 |
pvec1->rng->low = 9; |
753 |
pvec1->rng->high = 9; |
754 |
pvec2->rng->low = 5; |
755 |
pvec2->rng->high = 5; /* check 1 element subrange */ |
756 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_inner_product(pvec1, pvec2), 0.00001); |
757 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_inner_product(pvec1, pvec2), 0.00001); |
758 |
|
759 |
pvec1->rng->low = 0; |
760 |
pvec1->rng->high = 3; |
761 |
pvec2->rng->low = 2; |
762 |
pvec2->rng->high = 5; /* check 4 element subrange */ |
763 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_inner_product(pvec1, pvec2), 0.00001); |
764 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_inner_product(pvec1, pvec2), 0.00001); |
765 |
|
766 |
for (i=1 ; i<10 ; ++i) { |
767 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in vecs should be intact */ |
768 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[i], 2.0, 0.00001); |
769 |
} |
770 |
|
771 |
for (i=0 ; i<10 ; ++i) { |
772 |
pvec1->vec[i] = rarray[i]; /* initialize & check the data */ |
773 |
pvec2->vec[i] = rarray[9-i]; |
774 |
} |
775 |
/* check entire vectors */ |
776 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec1, pvec2), slow_inner_product(pvec1, pvec2), 0.00001); |
777 |
CU_ASSERT_DOUBLE_EQUAL(slv_inner_product(pvec2, pvec1), slow_inner_product(pvec1, pvec2), 0.00001); |
778 |
|
779 |
slv_destroy_vector(pvec1); |
780 |
slv_destroy_vector(pvec2); |
781 |
|
782 |
CU_TEST(test_meminuse == ascmeminuse()); |
783 |
|
784 |
/* test slv_square_norm() */ |
785 |
|
786 |
test_meminuse = ascmeminuse(); |
787 |
|
788 |
#ifndef ASC_NO_ASSERTIONS |
789 |
asc_assert_catch(TRUE); /* prepare to test assertions */ |
790 |
|
791 |
asc_assert_reset(); |
792 |
if (0 == setjmp(g_asc_test_env)) |
793 |
slv_square_norm(NULL); /* error - NULL vec */ |
794 |
CU_TEST(TRUE == asc_assert_failed()); |
795 |
|
796 |
pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); /* create a vector with NULL rng */ |
797 |
CU_TEST_FATAL(NULL != pvec1); |
798 |
pvec1->rng = NULL; |
799 |
pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
800 |
|
801 |
asc_assert_reset(); |
802 |
if (0 == setjmp(g_asc_test_env)) |
803 |
slv_square_norm(pvec1); /* error - NULL vec->rng */ |
804 |
CU_TEST(TRUE == asc_assert_failed()); |
805 |
|
806 |
pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
807 |
ascfree(pvec1->vec); |
808 |
pvec1->vec = NULL; |
809 |
|
810 |
asc_assert_reset(); |
811 |
if (0 == setjmp(g_asc_test_env)) |
812 |
slv_square_norm(pvec1); /* error - NULL vec->vec */ |
813 |
CU_TEST(TRUE == asc_assert_failed()); |
814 |
|
815 |
pvec1->vec = (real64 *)ascmalloc(10 * sizeof(real64)); |
816 |
pvec1->rng->low = -1; |
817 |
pvec1->rng->high = 10; |
818 |
|
819 |
asc_assert_reset(); |
820 |
if (0 == setjmp(g_asc_test_env)) |
821 |
slv_square_norm(pvec1); /* error - vec->rng->low < 0 */ |
822 |
CU_TEST(TRUE == asc_assert_failed()); |
823 |
|
824 |
pvec1->rng->low = 11; |
825 |
|
826 |
asc_assert_reset(); |
827 |
if (0 == setjmp(g_asc_test_env)) |
828 |
slv_square_norm(pvec1); /* error - vec low > high */ |
829 |
CU_TEST(TRUE == asc_assert_failed()); |
830 |
|
831 |
slv_destroy_vector(pvec1); |
832 |
|
833 |
asc_assert_catch(FALSE); /* done testing assertions */ |
834 |
#endif /* !ASC_NO_ASSERTIONS */ |
835 |
|
836 |
pvec1 = slv_create_vector(0,0); /* create & initialize a 1-element vector */ |
837 |
CU_TEST_FATAL(NULL != pvec1); |
838 |
|
839 |
pvec1->vec[0] = 0.0; |
840 |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_inner_product(pvec1, pvec1), 0.00001); |
841 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], 0.0, 0.00001); |
842 |
|
843 |
pvec1->vec[0] = rarray[7]; |
844 |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_inner_product(pvec1, pvec1), 0.00001); |
845 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[0], rarray[7], 0.00001); |
846 |
|
847 |
CU_TEST_FATAL(0 == slv_init_vector(pvec1, 0, 9)); /* redimension vectors larger */ |
848 |
|
849 |
for (i=0 ; i<10 ; ++i) { |
850 |
pvec1->vec[i] = rarray[i]; /* initialize the data */ |
851 |
} |
852 |
/* check entire vectors */ |
853 |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_inner_product(pvec1, pvec1), 0.00001); |
854 |
|
855 |
pvec1->rng->low = 9; |
856 |
pvec1->rng->high = 9; |
857 |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_inner_product(pvec1, pvec1), 0.00001); |
858 |
|
859 |
pvec1->rng->low = 0; |
860 |
pvec1->rng->high = 3; |
861 |
CU_ASSERT_DOUBLE_EQUAL(slv_square_norm(pvec1), slow_inner_product(pvec1, pvec1), 0.00001); |
862 |
|
863 |
for (i=1 ; i<10 ; ++i) { |
864 |
CU_ASSERT_DOUBLE_EQUAL(pvec1->vec[i], rarray[i], 0.00001); /* data in vecs should be intact */ |
865 |
} |
866 |
|
867 |
slv_destroy_vector(pvec1); |
868 |
|
869 |
CU_TEST(test_meminuse == ascmeminuse()); |
870 |
|
871 |
/* test slv_matrix_product() */ |
872 |
|
873 |
test_meminuse = ascmeminuse(); |
874 |
|
875 |
#ifndef ASC_NO_ASSERTIONS |
876 |
asc_assert_catch(TRUE); /* prepare to test assertions */ |
877 |
|
878 |
mtx = mtx_create(); |
879 |
CU_TEST_FATAL(NULL != mtx); |
880 |
mtx_set_order(mtx, 10); |
881 |
pvec1 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); |
882 |
CU_TEST_FATAL(NULL != pvec1); |
883 |
pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
884 |
pvec1->rng->low = 0; |
885 |
pvec1->rng->high = 10; |
886 |
pvec1->vec = (real64 *)ascmalloc(11 * sizeof(real64)); |
887 |
pvec2 = (struct vector_data *)ascmalloc(sizeof(struct vector_data)); |
888 |
CU_TEST_FATAL(NULL != pvec2); |
889 |
pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
890 |
pvec2->rng->low = 0; |
891 |
pvec2->rng->high = 10; |
892 |
pvec2->vec = (real64 *)ascmalloc(11 * sizeof(real64)); |
893 |
|
894 |
asc_assert_reset(); |
895 |
if (0 == setjmp(g_asc_test_env)) |
896 |
slv_matrix_product(NULL, pvec1, pvec2, 1.0, FALSE); /* error - NULL mtx */ |
897 |
CU_TEST(TRUE == asc_assert_failed()); |
898 |
|
899 |
asc_assert_reset(); |
900 |
if (0 == setjmp(g_asc_test_env)) |
901 |
slv_matrix_product(mtx, NULL, pvec2, 1.0, FALSE); /* error - NULL vec */ |
902 |
CU_TEST(TRUE == asc_assert_failed()); |
903 |
|
904 |
asc_assert_reset(); |
905 |
if (0 == setjmp(g_asc_test_env)) |
906 |
slv_matrix_product(mtx, pvec1, NULL, 1.0, FALSE); /* error - NULL prod */ |
907 |
CU_TEST(TRUE == asc_assert_failed()); |
908 |
|
909 |
ascfree(pvec1->rng); |
910 |
pvec1->rng = NULL; |
911 |
|
912 |
asc_assert_reset(); |
913 |
if (0 == setjmp(g_asc_test_env)) |
914 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - NULL vec->rng */ |
915 |
CU_TEST(TRUE == asc_assert_failed()); |
916 |
|
917 |
pvec1->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
918 |
pvec1->rng->low = 0; |
919 |
pvec1->rng->high = 10; |
920 |
ascfree(pvec2->rng); |
921 |
pvec2->rng = NULL; |
922 |
|
923 |
asc_assert_reset(); |
924 |
if (0 == setjmp(g_asc_test_env)) |
925 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - NULL prod->rng */ |
926 |
CU_TEST(TRUE == asc_assert_failed()); |
927 |
|
928 |
pvec2->rng = (mtx_range_t *)ascmalloc(sizeof(mtx_range_t)); |
929 |
pvec2->rng->low = 0; |
930 |
pvec2->rng->high = 10; |
931 |
ascfree(pvec1->vec); |
932 |
pvec1->vec = NULL; |
933 |
|
934 |
asc_assert_reset(); |
935 |
if (0 == setjmp(g_asc_test_env)) |
936 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - NULL vec->vec */ |
937 |
CU_TEST(TRUE == asc_assert_failed()); |
938 |
|
939 |
pvec1->vec = (real64 *)ascmalloc(11 * sizeof(real64)); |
940 |
ascfree(pvec2->vec); |
941 |
pvec2->vec = NULL; |
942 |
|
943 |
asc_assert_reset(); |
944 |
if (0 == setjmp(g_asc_test_env)) |
945 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - NULL prod->vec */ |
946 |
CU_TEST(TRUE == asc_assert_failed()); |
947 |
|
948 |
pvec2->vec = (real64 *)ascmalloc(11 * sizeof(real64)); |
949 |
pvec1->rng->low = -1; |
950 |
pvec1->rng->high = 10; |
951 |
|
952 |
asc_assert_reset(); |
953 |
if (0 == setjmp(g_asc_test_env)) |
954 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - vec low < 0 */ |
955 |
CU_TEST(TRUE == asc_assert_failed()); |
956 |
|
957 |
pvec1->rng->low = 11; |
958 |
|
959 |
asc_assert_reset(); |
960 |
if (0 == setjmp(g_asc_test_env)) |
961 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - vec low > high */ |
962 |
CU_TEST(TRUE == asc_assert_failed()); |
963 |
|
964 |
pvec1->rng->low = 0; |
965 |
pvec1->rng->high = 10; |
966 |
pvec2->rng->low = -1; |
967 |
pvec2->rng->high = 10; |
968 |
|
969 |
asc_assert_reset(); |
970 |
if (0 == setjmp(g_asc_test_env)) |
971 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - prod low < 0 */ |
972 |
CU_TEST(TRUE == asc_assert_failed()); |
973 |
|
974 |
pvec2->rng->low = 11; |
975 |
|
976 |
asc_assert_reset(); |
977 |
if (0 == setjmp(g_asc_test_env)) |
978 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* error - prod low > high */ |
979 |
CU_TEST(TRUE == asc_assert_failed()); |
980 |
|
981 |
mtx_destroy(mtx); |
982 |
slv_destroy_vector(pvec1); |
983 |
slv_destroy_vector(pvec2); |
984 |
|
985 |
asc_assert_catch(FALSE); /* done testing assertions */ |
986 |
#endif /* !ASC_NO_ASSERTIONS */ |
987 |
|
988 |
mtx = mtx_create(); |
989 |
mtx_set_order(mtx, 10); |
990 |
|
991 |
pvec1 = slv_create_vector(0,0); |
992 |
pvec1->vec[0] = 10.0; |
993 |
|
994 |
pvec2 = slv_create_vector(0,0); |
995 |
pvec3 = slv_create_vector(0,0); |
996 |
|
997 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* mtx with all zero's */ |
998 |
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* 1-element vector */ |
999 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1000 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1001 |
|
1002 |
mtx_fill_value(mtx, mtx_coord(&coord,0,0), 20.0); |
1003 |
|
1004 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* normal mtx */ |
1005 |
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* 1-element vector */ |
1006 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1007 |
CU_ASSERT_DOUBLE_EQUAL(200.0, pvec2->vec[0], 0.000001); |
1008 |
|
1009 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, TRUE); /* transpose should have no effect */ |
1010 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1011 |
CU_ASSERT_DOUBLE_EQUAL(200.0, pvec2->vec[0], 0.000001); |
1012 |
|
1013 |
mtx_clear(mtx); |
1014 |
|
1015 |
slv_init_vector(pvec1,0,1); |
1016 |
pvec1->vec[0] = 10.0; |
1017 |
pvec1->vec[1] = 20.5; |
1018 |
|
1019 |
slv_init_vector(pvec2, 0,1); |
1020 |
slv_init_vector(pvec3, 0,1); |
1021 |
|
1022 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* empty mtx */ |
1023 |
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* 2-element vector */ |
1024 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1025 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[1], pvec3->vec[1], 0.000001); |
1026 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1027 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[1], 0.000001); |
1028 |
|
1029 |
mtx_fill_value(mtx, mtx_coord(&coord,0,0), 20.0); |
1030 |
mtx_fill_value(mtx, mtx_coord(&coord,0,1), 0.5); |
1031 |
mtx_fill_value(mtx, mtx_coord(&coord,1,1), -0.455); |
1032 |
|
1033 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* normal mtx, but not all non-zeros */ |
1034 |
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* 2-element vector */ |
1035 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1036 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[1], pvec3->vec[1], 0.000001); |
1037 |
|
1038 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, TRUE); /* transpose of normal mtx, not all non-zeros */ |
1039 |
|
1040 |
mtx_clear(mtx); |
1041 |
mtx_fill_value(mtx, mtx_coord(&coord,0,0), 20.0); |
1042 |
mtx_fill_value(mtx, mtx_coord(&coord,1,0), 0.5); |
1043 |
mtx_fill_value(mtx, mtx_coord(&coord,1,1), -0.455); |
1044 |
|
1045 |
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* confirm transpose works */ |
1046 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[0], pvec3->vec[0], 0.000001); |
1047 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[1], pvec3->vec[1], 0.000001); |
1048 |
|
1049 |
slv_init_vector(pvec1,0,10); |
1050 |
pvec1->vec[0] = 10.0; |
1051 |
pvec1->vec[1] = 20.0; |
1052 |
pvec1->vec[2] = 30.0; |
1053 |
pvec1->vec[3] = 40.0; |
1054 |
pvec1->vec[4] = 50.0; |
1055 |
pvec1->vec[5] = 60.0; |
1056 |
pvec1->vec[6] = 70.0; |
1057 |
pvec1->vec[7] = 80.0; |
1058 |
pvec1->vec[8] = 90.0; |
1059 |
pvec1->vec[9] = 100.0; |
1060 |
pvec1->vec[10] = 110.0; |
1061 |
pvec1->rng->low = 2; /* only use a subset of vector */ |
1062 |
pvec1->rng->high = 4; |
1063 |
|
1064 |
slv_init_vector(pvec2, 0,10); |
1065 |
slv_init_vector(pvec3, 0,10); |
1066 |
for (i=0 ; i<11 ; ++i) { /* zero product vecs so can detect subset */ |
1067 |
pvec2->vec[i] = 0.0; |
1068 |
pvec3->vec[i] = 0.0; |
1069 |
} |
1070 |
|
1071 |
mtx_clear(mtx); |
1072 |
mtx_fill_value(mtx, mtx_coord(&coord,2,2), 1.0); /* only give values in vector range */ |
1073 |
mtx_fill_value(mtx, mtx_coord(&coord,2,3), 1.0); |
1074 |
mtx_fill_value(mtx, mtx_coord(&coord,2,4), 1.0); |
1075 |
mtx_fill_value(mtx, mtx_coord(&coord,3,2), 2.0); |
1076 |
mtx_fill_value(mtx, mtx_coord(&coord,3,3), 2.0); |
1077 |
mtx_fill_value(mtx, mtx_coord(&coord,3,4), 2.0); |
1078 |
mtx_fill_value(mtx, mtx_coord(&coord,4,2), 3.0); |
1079 |
mtx_fill_value(mtx, mtx_coord(&coord,4,3), 3.0); |
1080 |
mtx_fill_value(mtx, mtx_coord(&coord,4,4), 3.0); |
1081 |
|
1082 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, FALSE); /* normal mtx */ |
1083 |
slow_vector_matrix_product(mtx, pvec1, pvec3, 1.0); /* vector subset*/ |
1084 |
|
1085 |
for (i=0 ; i<11 ; ++i) { |
1086 |
CU_ASSERT_DOUBLE_EQUAL(pvec2->vec[i], pvec3->vec[i], 0.000001); |
1087 |
} |
1088 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1089 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[1], 0.000001); |
1090 |
CU_ASSERT_DOUBLE_EQUAL(120.0, pvec2->vec[2], 0.000001); |
1091 |
CU_ASSERT_DOUBLE_EQUAL(240.0, pvec2->vec[3], 0.000001); |
1092 |
CU_ASSERT_DOUBLE_EQUAL(360.0, pvec2->vec[4], 0.000001); |
1093 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[5], 0.000001); |
1094 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[6], 0.000001); |
1095 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[7], 0.000001); |
1096 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[8], 0.000001); |
1097 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[9], 0.000001); |
1098 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[10], 0.000001); |
1099 |
|
1100 |
slv_matrix_product(mtx, pvec1, pvec2, 0.5, FALSE); /* different scale */ |
1101 |
|
1102 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1103 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[1], 0.000001); |
1104 |
CU_ASSERT_DOUBLE_EQUAL(60.0, pvec2->vec[2], 0.000001); |
1105 |
CU_ASSERT_DOUBLE_EQUAL(120.0, pvec2->vec[3], 0.000001); |
1106 |
CU_ASSERT_DOUBLE_EQUAL(180.0, pvec2->vec[4], 0.000001); |
1107 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[5], 0.000001); |
1108 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[6], 0.000001); |
1109 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[7], 0.000001); |
1110 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[8], 0.000001); |
1111 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[9], 0.000001); |
1112 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[10], 0.000001); |
1113 |
|
1114 |
slv_matrix_product(mtx, pvec1, pvec2, 1.0, TRUE); /* transpose */ |
1115 |
|
1116 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1117 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[1], 0.000001); |
1118 |
CU_ASSERT_DOUBLE_EQUAL(260.0, pvec2->vec[2], 0.000001); |
1119 |
CU_ASSERT_DOUBLE_EQUAL(260.0, pvec2->vec[3], 0.000001); |
1120 |
CU_ASSERT_DOUBLE_EQUAL(260.0, pvec2->vec[4], 0.000001); |
1121 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[5], 0.000001); |
1122 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[6], 0.000001); |
1123 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[7], 0.000001); |
1124 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[8], 0.000001); |
1125 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[9], 0.000001); |
1126 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[10], 0.000001); |
1127 |
|
1128 |
slv_matrix_product(mtx, pvec1, pvec2, 2.0, TRUE); /* transpose */ |
1129 |
|
1130 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[0], 0.000001); |
1131 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[1], 0.000001); |
1132 |
CU_ASSERT_DOUBLE_EQUAL(520.0, pvec2->vec[2], 0.000001); |
1133 |
CU_ASSERT_DOUBLE_EQUAL(520.0, pvec2->vec[3], 0.000001); |
1134 |
CU_ASSERT_DOUBLE_EQUAL(520.0, pvec2->vec[4], 0.000001); |
1135 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[5], 0.000001); |
1136 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[6], 0.000001); |
1137 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[7], 0.000001); |
1138 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[8], 0.000001); |
1139 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[9], 0.000001); |
1140 |
CU_ASSERT_DOUBLE_EQUAL(0.0, pvec2->vec[10], 0.000001); |
1141 |
|
1142 |
mtx_destroy(mtx); |
1143 |
slv_destroy_vector(pvec1); |
1144 |
slv_destroy_vector(pvec2); |
1145 |
slv_destroy_vector(pvec3); |
1146 |
|
1147 |
CU_TEST(test_meminuse == ascmeminuse()); |
1148 |
|
1149 |
/* test slv_write_vector() - not much to do but make sure something gets written */ |
1150 |
|
1151 |
test_meminuse = ascmeminuse(); |
1152 |
|
1153 |
pvec1 = slv_create_vector(0,10); |
1154 |
|
1155 |
if (FALSE == test_printing_enabled()) { |
1156 |
test_enable_printing(); |
1157 |
i_enabled_printing = TRUE; |
1158 |
} |
1159 |
|
1160 |
if (NULL != (file_normal = fopen("slvcommontempfile1.tmp", "w+"))) { |
1161 |
|
1162 |
slv_write_vector(file_normal, pvec1);/* write to normal open file */ |
1163 |
rewind(file_normal); |
1164 |
CU_TEST(EOF != fgetc(file_normal)); /* test that file is not empty */ |
1165 |
fclose(file_normal); |
1166 |
} |
1167 |
else { |
1168 |
CU_FAIL("Error opening output file 1 in test_slv_common.c"); |
1169 |
} |
1170 |
|
1171 |
if (TRUE == i_enabled_printing) { |
1172 |
test_disable_printing(); |
1173 |
i_enabled_printing = FALSE; |
1174 |
} |
1175 |
|
1176 |
slv_destroy_vector(pvec1); |
1177 |
|
1178 |
CU_TEST(test_meminuse == ascmeminuse()); |
1179 |
|
1180 |
/* test slv_dot() */ |
1181 |
|
1182 |
test_meminuse = ascmeminuse(); |
1183 |
|
1184 |
#ifndef ASC_NO_ASSERTIONS |
1185 |
asc_assert_catch(TRUE); /* prepare to test assertions */ |
1186 |
|
1187 |
asc_assert_reset(); |
1188 |
if (0 == setjmp(g_asc_test_env)) |
1189 |
slv_dot(10, NULL, rarray2); /* error - NULL a1 */ |
1190 |
CU_TEST(TRUE == asc_assert_failed()); |
1191 |
|
1192 |
asc_assert_reset(); |
1193 |
if (0 == setjmp(g_asc_test_env)) |
1194 |
slv_dot(10, rarray, NULL); /* error - NULL a2 */ |
1195 |
CU_TEST(TRUE == asc_assert_failed()); |
1196 |
|
1197 |
asc_assert_reset(); |
1198 |
if (0 == setjmp(g_asc_test_env)) |
1199 |
slv_dot(-10, rarray, rarray2); /* error - len < 0 */ |
1200 |
CU_TEST(TRUE == asc_assert_failed()); |
1201 |
|
1202 |
asc_assert_catch(FALSE); /* done testing assertions */ |
1203 |
#endif /* !ASC_NO_ASSERTIONS */ |
1204 |
|
1205 |
rarray2[0] = rarray[5]; |
1206 |
|
1207 |
CU_ASSERT_DOUBLE_EQUAL(slv_dot(1, rarray, rarray2), slow_dot_product(1, rarray, rarray2), 0.00001); |
1208 |
CU_ASSERT_DOUBLE_EQUAL(slv_dot(1, rarray2, rarray), slow_dot_product(1, rarray, rarray2), 0.00001); |
1209 |
|
1210 |
for (i=0 ; i<10 ; ++i) { |
1211 |
rarray2[i] = 2.0; |
1212 |
} |
1213 |
|
1214 |
CU_ASSERT_DOUBLE_EQUAL(slv_dot(11, rarray, rarray2), slow_dot_product(11, rarray, rarray2), 0.00001); |
1215 |
CU_ASSERT_DOUBLE_EQUAL(slv_dot(11, rarray2, rarray), slow_dot_product(11, rarray, rarray2), 0.00001); |
1216 |
|
1217 |
CU_ASSERT_DOUBLE_EQUAL(slv_dot(5, rarray, rarray2), slow_dot_product(5, rarray, rarray2), 0.00001); |
1218 |
CU_ASSERT_DOUBLE_EQUAL(slv_dot(5, rarray2, rarray), slow_dot_product(5, rarray, rarray2), 0.00001); |
1219 |
|
1220 |
CU_ASSERT_DOUBLE_EQUAL(slv_dot(0, rarray, rarray2), slow_dot_product(0, rarray, rarray2), 0.00001); |
1221 |
CU_ASSERT_DOUBLE_EQUAL(slv_dot(0, rarray2, rarray), slow_dot_product(0, rarray, rarray2), 0.00001); |
1222 |
|
1223 |
for (i=1 ; i<10 ; ++i) { |
1224 |
CU_ASSERT_DOUBLE_EQUAL(7/2 * i, rarray[i], 0.00001); /* data in arrays should be intact */ |
1225 |
CU_ASSERT_DOUBLE_EQUAL(rarray2[i], 2.0, 0.00001); |
1226 |
} |
1227 |
|
1228 |
for (i=0 ; i<10 ; ++i) { |
1229 |
rarray2[i] = rarray[9-i]; |
1230 |
} |
1231 |
|
1232 |
CU_ASSERT_DOUBLE_EQUAL(slv_dot(11, rarray, rarray2), slow_dot_product(11, rarray, rarray2), 0.00001); |
1233 |
CU_ASSERT_DOUBLE_EQUAL(slv_dot(11, rarray2, rarray), slow_dot_product(11, rarray, rarray2), 0.00001); |
1234 |
|
1235 |
CU_TEST(test_meminuse == ascmeminuse()); |
1236 |
|
1237 |
/* test slv_get_output_file() */ |
1238 |
|
1239 |
test_meminuse = ascmeminuse(); |
1240 |
|
1241 |
file_normal = (FILE *)100; |
1242 |
CU_TEST(file_normal == slv_get_output_file(file_normal)); /* non-NULL fp */ |
1243 |
CU_TEST(NULL != slv_get_output_file(NULL)); /* NULL fp */ |
1244 |
fprintf(slv_get_output_file(NULL), "\n If you see this then test_slv_common:slv_get_output_file() failed!"); |
1245 |
|
1246 |
/* MIF(), LIF(), PMIF(), PLIF() - macros accessing members - not tested */ |
1247 |
|
1248 |
/* not tested - revisit later: |
1249 |
* - slv_print_obj_name() |
1250 |
* - slv_print_rel_name() |
1251 |
* - slv_print_var_name() |
1252 |
* - slv_print_logrel_name() |
1253 |
* - slv_print_dis_name() |
1254 |
* - slv_print_obj_index() |
1255 |
* - slv_print_rel_sindex() |
1256 |
* - slv_print_var_sindex() |
1257 |
* - slv_print_logrel_sindex() |
1258 |
* - slv_print_dis_sindex() |
1259 |
* - slv_print_obj_index() |
1260 |
*/ |
1261 |
|
1262 |
test_meminuse = ascmeminuse(); |
1263 |
|
1264 |
CU_FAIL("slv_print_*_name() and slv_print_*_sindex() not tested."); |
1265 |
|
1266 |
CU_TEST(test_meminuse == ascmeminuse()); |
1267 |
|
1268 |
/* test slv_direct_solve() */ |
1269 |
|
1270 |
test_meminuse = ascmeminuse(); |
1271 |
|
1272 |
CU_FAIL("slv_direct_solve() test not implemented."); |
1273 |
|
1274 |
CU_TEST(test_meminuse == ascmeminuse()); |
1275 |
|
1276 |
/* test slv_direct_log_solve() */ |
1277 |
|
1278 |
test_meminuse = ascmeminuse(); |
1279 |
|
1280 |
CU_FAIL("slv_direct_log_solve() test not implemented."); |
1281 |
|
1282 |
CU_TEST(test_meminuse == ascmeminuse()); |
1283 |
|
1284 |
/* test slv_create_lnkmap(), slv_write_lnkmap(), slv_destroy_lnkmap() */ |
1285 |
|
1286 |
test_meminuse = ascmeminuse(); |
1287 |
|
1288 |
hi[0] = 100; |
1289 |
hj[0] = 1; |
1290 |
|
1291 |
CU_TEST(NULL == slv_create_lnkmap(10, 10, 1, hi, hj)); /* error - hi contains invalid index */ |
1292 |
|
1293 |
hi[0] = 1; |
1294 |
hj[0] = 100; |
1295 |
|
1296 |
CU_TEST(NULL == slv_create_lnkmap(10, 10, 1, hi, hj)); /* error - hj contains invalid index */ |
1297 |
|
1298 |
lnkmap = slv_create_lnkmap(10, 10, 0, hi, hj); /* 0 element arrays */ |
1299 |
CU_TEST_FATAL(NULL != lnkmap); |
1300 |
for (i=0 ; i<10 ; ++i) { |
1301 |
CU_TEST(0 == *lnkmap[i]); |
1302 |
} |
1303 |
|
1304 |
CU_TEST(0 != AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1305 |
|
1306 |
slv_destroy_lnkmap(lnkmap); |
1307 |
|
1308 |
#ifdef MALLOC_DEBUG |
1309 |
CU_TEST(0 == AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1310 |
#else |
1311 |
CU_TEST(1 == AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1312 |
#endif |
1313 |
|
1314 |
hi[0] = 1; |
1315 |
hj[0] = 1; |
1316 |
|
1317 |
lnkmap = slv_create_lnkmap(10, 10, 1, hi, hj); /* 1 element arrays */ |
1318 |
CU_TEST_FATAL(NULL != lnkmap); |
1319 |
for (i=0 ; i<10 ; ++i) { |
1320 |
lnkvars = lnkmap[i]; |
1321 |
if (i == 1) { |
1322 |
CU_TEST_FATAL(1 == lnkvars[0]); /* number of non-zero elements */ |
1323 |
CU_TEST(1 == lnkvars[1]); /* column # of 1st element */ |
1324 |
CU_TEST(0 == lnkvars[2]); /* link map index */ |
1325 |
} else { |
1326 |
CU_TEST(0 == lnkvars[0]); |
1327 |
} |
1328 |
} |
1329 |
|
1330 |
CU_TEST(0 != AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1331 |
|
1332 |
slv_destroy_lnkmap(lnkmap); |
1333 |
|
1334 |
#ifdef MALLOC_DEBUG |
1335 |
CU_TEST(0 == AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1336 |
#else |
1337 |
CU_TEST(1 == AllocatedMemory((VOIDPTR)lnkmap, 0)); |
1338 |
#endif |
1339 |
|
1340 |
/* link map order: (5,1) (3,0) (3,8) (2,10) (2,0) (2,4) (2,7) (2,2) (1,10) (1,5) (1,1) */ |
1341 |
hi[0] = 5; /* row 5: (5,1) */ |
1342 |
hj[0] = 1; |
1343 |
hi[1] = 3; /* row 3: (3,0) (3,8) */ |
1344 |
hj[1] = 0; |
1345 |
hi[2] = 3; |
1346 |
hj[2] = 8; |
1347 |
hi[3] = 2; /* row 2: (2,0) (2,2) (2,4) (2,7) (2,10) */ |
1348 |
hj[3] = 10; |
1349 |
hi[4] = 2; |
1350 |
hj[4] = 0; |
1351 |
hi[5] = 2; |
1352 |
hj[5] = 4; |
1353 |
hi[6] = 2; |
1354 |
hj[6] = 7; |
1355 |
hi[7] = 2; |
1356 |
hj[7] = 2; |
1357 |
hi[8] = 1; /* row 1: (1,1) (1,5) (1,10) */ |
1358 |
hj[8] = 10; |
1359 |
hi[9] = 1; |
1360 |
hj[9] = 5; |
1361 |
hi[10] = 1; |
1362 |
hj[10] = 1; |
1363 |
|
1364 |
lnkindex_list = gl_create(11); |
1365 |
for (i=0 ; i<11 ; ++i) { |
1366 |
lnkindexes[i] = i; |
1367 |
gl_append_ptr(lnkindex_list, &lnkindexes[i]); |
1368 |
} |
1369 |
|
1370 |
lnkmap = slv_create_lnkmap(6, 11, 11, hi, hj); /* multi element arrays */ |
1371 |
CU_TEST_FATAL(NULL != lnkmap); |
1372 |
|
1373 |
lnkvars = lnkmap[0]; |
1374 |
CU_TEST(0 == lnkvars[0]); /* number of non-zero elements */ |
1375 |
|
1376 |
col_list = gl_create(10); |
1377 |
CU_TEST_FATAL(NULL != col_list); |
1378 |
gl_append_ptr(col_list, &hj[8]); |
1379 |
gl_append_ptr(col_list, &hj[9]); |
1380 |
gl_append_ptr(col_list, &hj[10]); |
1381 |
|
1382 |
lnkvars = lnkmap[1]; |
1383 |
CU_TEST(3 == lnkvars[0]); /* number of non-zero elements */ |
1384 |
for (i=0 ; i<lnkvars[0] ; ++i) { |
1385 |
CU_TEST(0 != (pos = gl_search(col_list, &lnkvars[2*i+1], compare_int32s))); |
1386 |
gl_delete(col_list, pos, FALSE); |
1387 |
CU_TEST(0 != (pos = gl_search(lnkindex_list, &lnkvars[2*i+2], compare_int32s))); |
1388 |
gl_delete(lnkindex_list, pos, FALSE); |
1389 |
} |
1390 |
|
1391 |
gl_reset(col_list); |
1392 |
gl_append_ptr(col_list, &hj[3]); |
1393 |
gl_append_ptr(col_list, &hj[4]); |
1394 |
gl_append_ptr(col_list, &hj[5]); |
1395 |
gl_append_ptr(col_list, &hj[6]); |
1396 |
gl_append_ptr(col_list, &hj[7]); |
1397 |
|
1398 |
lnkvars = lnkmap[2]; |
1399 |
CU_TEST(5 == lnkvars[0]); /* number of non-zero elements */ |
1400 |
for (i=0 ; i<lnkvars[0] ; ++i) { |
1401 |
CU_TEST(0 != (pos = gl_search(col_list, &lnkvars[2*i+1], compare_int32s))); |
1402 |
gl_delete(col_list, pos, FALSE); |
1403 |
CU_TEST(0 != (pos = gl_search(lnkindex_list, &lnkvars[2*i+2], compare_int32s))); |
1404 |
gl_delete(lnkindex_list, pos, FALSE); |
1405 |
} |
1406 |
|
1407 |
gl_reset(col_list); |
1408 |
gl_append_ptr(col_list, &hj[1]); |
1409 |
gl_append_ptr(col_list, &hj[2]); |
1410 |
|
1411 |
lnkvars = lnkmap[3]; |
1412 |
CU_TEST(2 == lnkvars[0]); /* number of non-zero elements */ |
1413 |
for (i=0 ; i<lnkvars[0] ; ++i) { |
1414 |
CU_TEST(0 != (pos = gl_search(col_list, &lnkvars[2*i+1], compare_int32s))); |
1415 |
gl_delete(col_list, pos, FALSE); |
1416 |
CU_TEST(0 != (pos = gl_search(lnkindex_list, &lnkvars[2*i+2], compare_int32s))); |
1417 |
gl_delete(lnkindex_list, pos, FALSE); |
1418 |
} |
1419 |
|
1420 |
lnkvars = lnkmap[4]; |
1421 |
CU_TEST(0 == lnkvars[0]); /* number of non-zero elements */ |
1422 |
|
1423 |
gl_reset(col_list); |
1424 |
gl_append_ptr(col_list, &hj[0]); |
1425 |
|
1426 |
lnkvars = lnkmap[5]; |
1427 |
CU_TEST_FATAL(1 == lnkvars[0]); /* number of non-zero elements */ |
1428 |
for (i=0 ; i<lnkvars[0] ; ++i) { |
1429 |
CU_TEST(0 != (pos = gl_search(col_list, &lnkvars[2*i+1], compare_int32s))); |
1430 |
gl_delete(col_list, pos, FALSE); |
1431 |
CU_TEST(0 != (pos = gl_search(lnkindex_list, &lnkvars[2*i+2], compare_int32s))); |
1432 |
gl_delete(lnkindex_list, pos, FALSE); |
1433 |
} |
1434 |
|
1435 |
CU_TEST(0 == gl_length(lnkindex_list)); /* all lnkindexes should have been used */ |
1436 |
|
1437 |
if (FALSE == test_printing_enabled()) { |
1438 |
test_enable_printing(); |
1439 |
i_enabled_printing = TRUE; |
1440 |
} |
1441 |
|
1442 |
if (NULL != (file_normal = fopen("slvcommontempfile2.tmp", "w+"))) { |
1443 |
|
1444 |
slv_write_lnkmap(file_normal, 6, lnkmap); /* write to normal open file */ |
1445 |
rewind(file_normal); |
1446 |
CU_TEST(EOF != fgetc(file_normal)); /* test that file is not empty */ |
1447 |
fclose(file_normal); |
1448 |
} |
1449 |
else { |
1450 |
CU_FAIL("Error opening output file 2 in test_slv_common.c"); |
1451 |
} |
1452 |
|
1453 |
if (TRUE == i_enabled_printing) { |
1454 |
test_disable_printing(); |
1455 |
i_enabled_printing = FALSE; |
1456 |
} |
1457 |
|
1458 |
gl_destroy(col_list); |
1459 |
gl_destroy(lnkindex_list); |
1460 |
slv_destroy_lnkmap(lnkmap); |
1461 |
|
1462 |
gl_emptyrecycler(); |
1463 |
CU_TEST(test_meminuse == ascmeminuse()); |
1464 |
|
1465 |
/* test slv_lnkmap_from_mtx() */ |
1466 |
|
1467 |
test_meminuse = ascmeminuse(); |
1468 |
|
1469 |
mtx = mtx_create(); |
1470 |
CU_TEST_FATAL(NULL != mtx); |
1471 |
mtx_set_order(mtx, 11); |
1472 |
|
1473 |
region.row.low = 0; |
1474 |
region.row.high = 10; |
1475 |
region.col.low = 0; |
1476 |
region.col.high = 10; |
1477 |
|
1478 |
CU_TEST(NULL == slv_lnkmap_from_mtx(NULL, ®ion)); /* error - NULL mtx */ |
1479 |
|
1480 |
region.row.low = -1; |
1481 |
region.row.high = 10; |
1482 |
region.col.low = 0; |
1483 |
region.col.high = 10; |
1484 |
|
1485 |
CU_TEST(NULL == slv_lnkmap_from_mtx(mtx, ®ion)); /* error - region.row.low < 0 */ |
1486 |
|
1487 |
region.row.low = 0; |
1488 |
region.row.high = 11; |
1489 |
|
1490 |
CU_TEST(NULL == slv_lnkmap_from_mtx(mtx, ®ion)); /* error - region.row.high >= order */ |
1491 |
|
1492 |
region.col.low = -1; |
1493 |
region.col.high = 10; |
1494 |
|
1495 |
CU_TEST(NULL == slv_lnkmap_from_mtx(mtx, ®ion)); /* error - region.col.low < 0 */ |
1496 |
|
1497 |
region.col.low = 0; |
1498 |
region.col.high = 11; |
1499 |
|
1500 |
CU_TEST(NULL == slv_lnkmap_from_mtx(mtx, ®ion)); /* error - region.col.high >= order */ |
1501 |
|
1502 |
region.row.low = 0; |
1503 |
region.row.high = 10; |
1504 |
region.col.low = 0; |
1505 |
region.col.high = 10; |
1506 |
|
1507 |
lnkmap = slv_lnkmap_from_mtx(mtx, ®ion); /* empty matrix */ |
1508 |
CU_TEST_FATAL(NULL != lnkmap); |
1509 |
for (i=0 ; i<11 ; ++i) { |
1510 |
CU_TEST(0 == *lnkmap[i]); |
1511 |
} |
1512 |
|
1513 |
slv_destroy_lnkmap(lnkmap); |
1514 |
|
1515 |
mtx_fill_value(mtx, mtx_coord(&coord,5,1),10.0); /* row 5: (5,1) (5,7) */ |
1516 |
mtx_fill_value(mtx, mtx_coord(&coord,2,0),20.1); /* row 2: (2,0) (2,6) */ |
1517 |
mtx_fill_value(mtx, mtx_coord(&coord,6,4),30.2); /* row 6: (6,4) (6,5) */ |
1518 |
mtx_fill_value(mtx, mtx_coord(&coord,2,6),40.3); |
1519 |
mtx_fill_value(mtx, mtx_coord(&coord,0,2),50.4); /* row 0: (0,2) */ |
1520 |
mtx_fill_value(mtx, mtx_coord(&coord,5,7),59.5); |
1521 |
mtx_fill_value(mtx, mtx_coord(&coord,6,5),69.6); |
1522 |
mtx_fill_value(mtx, mtx_coord(&coord,3,8),79.7); /* row 3: (3,8) */ |
1523 |
mtx_fill_value(mtx, mtx_coord(&coord,9,9),89.8); /* row 9: (9,9) (9,10) */ |
1524 |
mtx_fill_value(mtx, mtx_coord(&coord,9,10),99.9); |
1525 |
|
1526 |
region.row.low = 3; |
1527 |
region.row.high = 4; |
1528 |
region.col.low = 0; |
1529 |
region.col.high = 10; |
1530 |
lnkmap = slv_lnkmap_from_mtx(mtx, ®ion); /* region with 1 non-zero */ |
1531 |
CU_TEST_FATAL(NULL != lnkmap); |
1532 |
lnkvars = lnkmap[3]; |
1533 |
CU_TEST(1 == lnkvars[0]); |
1534 |
CU_TEST(8 == lnkvars[1]); |
1535 |
CU_TEST(80 == lnkvars[2]); |
1536 |
for (i=0 ; i<3 ; ++i) { |
1537 |
CU_TEST(0 == *lnkmap[i]); |
1538 |
} |
1539 |
for (i=4 ; i<11 ; ++i) { |
1540 |
CU_TEST(0 == *lnkmap[i]); |
1541 |
} |
1542 |
|
1543 |
slv_destroy_lnkmap(lnkmap); |
1544 |
|
1545 |
lnkmap = slv_lnkmap_from_mtx(mtx, mtx_ENTIRE_MATRIX); /* entire matrix */ |
1546 |
CU_TEST_FATAL(NULL != lnkmap); |
1547 |
CU_TEST(0 == *lnkmap[1]); |
1548 |
CU_TEST(0 == *lnkmap[4]); |
1549 |
CU_TEST(0 == *lnkmap[7]); |
1550 |
CU_TEST(0 == *lnkmap[8]); |
1551 |
CU_TEST(0 == *lnkmap[10]); |
1552 |
|
1553 |
lnkvars = lnkmap[0]; |
1554 |
CU_TEST(1 == lnkvars[0]); |
1555 |
CU_TEST(2 == lnkvars[1]); |
1556 |
CU_TEST(50 == lnkvars[2]); |
1557 |
|
1558 |
lnkvars = lnkmap[2]; |
1559 |
CU_TEST(2 == lnkvars[0]); |
1560 |
if (0 == lnkvars[1]) { |
1561 |
CU_TEST(20 == lnkvars[2]); |
1562 |
CU_TEST(6 == lnkvars[3]); |
1563 |
CU_TEST(40 == lnkvars[4]); |
1564 |
} else if (6 == lnkvars[1]) { |
1565 |
CU_TEST(40 == lnkvars[2]); |
1566 |
CU_TEST(0 == lnkvars[3]); |
1567 |
CU_TEST(20 == lnkvars[4]); |
1568 |
} else { |
1569 |
CU_FAIL("Unexpected col for lnkmap row 2."); |
1570 |
} |
1571 |
|
1572 |
lnkvars = lnkmap[3]; |
1573 |
CU_TEST(1 == lnkvars[0]); |
1574 |
CU_TEST(8 == lnkvars[1]); |
1575 |
CU_TEST(80 == lnkvars[2]); |
1576 |
|
1577 |
lnkvars = lnkmap[5]; |
1578 |
CU_TEST(2 == lnkvars[0]); |
1579 |
if (1 == lnkvars[1]) { |
1580 |
CU_TEST(10 == lnkvars[2]); |
1581 |
CU_TEST(7 == lnkvars[3]); |
1582 |
CU_TEST(60 == lnkvars[4]); |
1583 |
} else if (7 == lnkvars[1]) { |
1584 |
CU_TEST(60 == lnkvars[2]); |
1585 |
CU_TEST(1 == lnkvars[3]); |
1586 |
CU_TEST(10 == lnkvars[4]); |
1587 |
} else { |
1588 |
CU_FAIL("Unexpected col for lnkmap row 5."); |
1589 |
} |
1590 |
|
1591 |
lnkvars = lnkmap[6]; |
1592 |
CU_TEST(2 == lnkvars[0]); |
1593 |
if (4 == lnkvars[1]) { |
1594 |
CU_TEST(30 == lnkvars[2]); |
1595 |
CU_TEST(5 == lnkvars[3]); |
1596 |
CU_TEST(70 == lnkvars[4]); |
1597 |
} else if (5 == lnkvars[1]) { |
1598 |
CU_TEST(70 == lnkvars[2]); |
1599 |
CU_TEST(4 == lnkvars[3]); |
1600 |
CU_TEST(30 == lnkvars[4]); |
1601 |
} else { |
1602 |
CU_FAIL("Unexpected col for lnkmap row 6."); |
1603 |
} |
1604 |
|
1605 |
lnkvars = lnkmap[9]; |
1606 |
CU_TEST(2 == lnkvars[0]); |
1607 |
if (9 == lnkvars[1]) { |
1608 |
CU_TEST(90 == lnkvars[2]); |
1609 |
CU_TEST(10 == lnkvars[3]); |
1610 |
CU_TEST(100 == lnkvars[4]); |
1611 |
} else if (10 == lnkvars[1]) { |
1612 |
CU_TEST(100 == lnkvars[2]); |
1613 |
CU_TEST(9 == lnkvars[3]); |
1614 |
CU_TEST(90 == lnkvars[4]); |
1615 |
} else { |
1616 |
CU_FAIL("Unexpected col for lnkmap row 9."); |
1617 |
} |
1618 |
|
1619 |
slv_destroy_lnkmap(lnkmap); |
1620 |
|
1621 |
mtx_destroy(mtx); |
1622 |
|
1623 |
CU_TEST(test_meminuse == ascmeminuse()); |
1624 |
|
1625 |
/* |
1626 |
|
1627 |
extern int slv_direct_solve(slv_system_t server, |
1628 |
struct rel_relation *rel, |
1629 |
struct var_variable *var, |
1630 |
FILE *file, |
1631 |
real64 epsilon, |
1632 |
int ignore_bounds, |
1633 |
int scaled); |
1634 |
*< |
1635 |
* Attempts to directly solve the given relation (equality constraint) for |
1636 |
* the given variable, leaving the others fixed. Returns an integer |
1637 |
* signifying the status as one of the following three: |
1638 |
* <pre> |
1639 |
* 0 ==> Unable to determine anything. |
1640 |
* Not symbolically invertible. |
1641 |
* 1 ==> Solution(s) found. |
1642 |
* Variable value set to first found if more than one. |
1643 |
* -1 ==> No solution found. |
1644 |
* Function invertible, but no solution exists satisfying |
1645 |
* var bounds (if active) and the epsilon given. |
1646 |
* </pre> |
1647 |
* The variable bounds will be upheld, unless ignore_bounds=FALSE. |
1648 |
* Residual testing will be against epsilon and either scaled or |
1649 |
* unscaled residual according to scaled (no scale -> 0). |
1650 |
* If file != NULL and there are leftover possible solutions, we |
1651 |
* will write about them to file. |
1652 |
* |
1653 |
* @param server The slv_system_t (mostly ignored). |
1654 |
* @param rel The relation to attempt to solve. |
1655 |
* @param var The variable for which to solve. |
1656 |
* @param file File stream to receive other possible solutions. |
1657 |
* @param epsilon Tolerance for testing convergence. |
1658 |
* @param ignore_bounds If TRUE, ignore bounds on variable. |
1659 |
* @param scaled If TRUE, test scaled residuals against epsilon. |
1660 |
|
1661 |
|
1662 |
extern int slv_direct_log_solve(slv_system_t sys, |
1663 |
struct logrel_relation *lrel, |
1664 |
struct dis_discrete *dvar, |
1665 |
FILE *file, |
1666 |
int perturb, |
1667 |
struct gl_list_t *instances); |
1668 |
*< |
1669 |
* Attempt to directly solve the given logrelation for the given |
1670 |
* discrete variable, leaving the others fixed. Returns an integer |
1671 |
* signifying the status as one of the following three: |
1672 |
* <pre> |
1673 |
* 0 ==> Unable to determine anything. Bad logrelation or dvar |
1674 |
* 1 ==> Solution found. |
1675 |
* 2 ==> More than one solution found. It does not modify the value |
1676 |
* of dvar. Conflicting. |
1677 |
* -1 ==> No solution found. Inconsistency |
1678 |
* </pre> |
1679 |
* If file != NULL and there are leftover possible solutions, we |
1680 |
* will write about them to file. |
1681 |
* The flag perturb and the gl_list are used to change the truth |
1682 |
* value of some boundaries. This is sometimes useful in |
1683 |
* conditional modeling. |
1684 |
* |
1685 |
* @param sys The slv_system_t (mostly ignored). |
1686 |
* @param lrel The logical relation to attempt to solve. |
1687 |
* @param dvar The discrete variable for which to solve. |
1688 |
* @param file File stream to receive other possible solutions. |
1689 |
* @param perturb If TRUE, perturbs the truth values if necessary to find the solution. |
1690 |
* @param instances List of instances. |
1691 |
|
1692 |
*/ |
1693 |
|
1694 |
if (TRUE == i_initialized_lists) { /* clean up list system if necessary */ |
1695 |
gl_destroy_pool(); |
1696 |
} |
1697 |
CU_TEST(prior_meminuse == ascmeminuse()); /* make sure we cleaned up after ourselves */ |
1698 |
} |
1699 |
|
1700 |
/*===========================================================================*/ |
1701 |
/* Registration information */ |
1702 |
|
1703 |
static CU_TestInfo slv_common_test_list[] = { |
1704 |
{"test_slv_common", test_slv_common}, |
1705 |
CU_TEST_INFO_NULL |
1706 |
}; |
1707 |
|
1708 |
static CU_SuiteInfo suites[] = { |
1709 |
{"test_solver_slv_common", NULL, NULL, slv_common_test_list}, |
1710 |
CU_SUITE_INFO_NULL |
1711 |
}; |
1712 |
|
1713 |
/*-------------------------------------------------------------------*/ |
1714 |
CU_ErrorCode test_register_solver_slv_common(void) |
1715 |
{ |
1716 |
return CU_register_suites(suites); |
1717 |
} |