5 #include "config_test.h"
6 #include <JM/jm_vector.h>
7 #include <JM/jm_stack.h>
9 void print_int(int i,void* data) {
13 void print_dbl(double d,void* data) {
17 int compar_int(int* a, int* b) {
21 int return_code = CTEST_RETURN_SUCCESS;
23 void log_error(const char* fmt, ...) {
28 return_code = CTEST_RETURN_FAIL;
35 jm_vector(int) stackv;
38 jm_vector(int)* v = &stackv;
40 s = jm_stack_alloc(double)(100, 0 );
42 jm_vector_init(int)(v,VINIT_SIZE,0);
43 jm_vector_zero(int)(v);
44 jm_vector_set_item(int)(v, 2, TESTVAL);
45 for( i = 0; i < 32; i++) {
48 jm_vector_push_back(int)(v,x);
49 jm_stack_push(double)(s,x);
50 top = (int)jm_stack_top(double)(s);
51 printf("pushed item %d=%d (stack top %g), vector size: %d, capacity: %d\n", i, x, jm_stack_top(double)(s), jm_vector_get_size(int)(v), jm_vector_reserve(int)(v,0));
52 if(top != x) log_error("Stack top does not match the pushed value \n");
53 if(jm_vector_get_size(int)(v) != VINIT_SIZE+i+1) log_error("Vector size %d is not as expected %d\n", jm_vector_get_size(int)(v), VINIT_SIZE+i+1);
56 size_t index = jm_vector_find_index(int)(v, &k,jm_compare_int);
58 if( index != 2) log_error("Index of '%d' should be '2' but got %d\n", TESTVAL, k );
60 for( i = 0; i < 22; i++) {
61 jm_stack_pop(double)(s);
63 jm_vector_resize_int(v,10);
64 printf("Printing the vector \n");
65 jm_vector_foreach_c(int)(v,print_int,0);
66 jm_vector_qsort(int)(v, jm_compare_int);
67 printf("Printing sorted vector \n");
68 jm_vector_foreach_c(int)(v,print_int,0);
69 printf("Index of %d is %d\n", k, jm_vector_bsearch_index(int)(v, &k, jm_compare_int));
70 printf("Printing the stack \n");
71 jm_stack_foreach(double)(s,print_dbl,0);
73 jm_vector_free_data(int)(v);
74 jm_stack_free(double)(s);