bb879f9a2fed0a1adb36ca6f4f15d04125984db1
2 #include "cgds/Stack.h"
3 #include "test/helpers.h"
6 void t_stack_clear() //FTEST
8 Stack
* s
= stack_new(int);
15 lu_assert(stack_empty(s
));
20 void t_stack_size() //FTEST
22 Stack
* s
= stack_new(int);
27 lu_assert_int_eq(stack_size(s
), 3);
31 lu_assert_int_eq(stack_size(s
), 5);
36 lu_assert_int_eq(stack_size(s
), 8);
41 void t_stack_push_pop_basic() //FTEST
46 Stack
* s
= stack_new(double);
47 for (int i
= 0; i
< n
; i
++)
48 stack_push(s
, (double) i
);
49 // iterate and check values
50 double ckValue
= n
- 1;
51 while (!stack_empty(s
))
55 lu_assert_dbl_eq(d
, ckValue
);
60 lu_assert(stack_empty(s
));
64 void t_stack_push_pop_evolved() //FTEST
66 Stack
* s
= stack_new(StructTest1
);
69 StructTest1
* st1
= (StructTest1
*) malloc(n
* sizeof (StructTest1
));
70 for (int i
= n
- 1; i
>= 0; i
--)
72 st1
[i
].a
= rand() % 42;
73 st1
[i
].b
= (double) rand() / RAND_MAX
;
74 stack_push(s
, *(st1
+ i
));
76 for (int i
= 0; i
< n
; i
++)
79 stack_top(s
, st1Cell
);
80 lu_assert_int_eq(st1Cell
.a
, st1
[i
].a
);
81 lu_assert_dbl_eq(st1Cell
.b
, st1
[i
].b
);
87 s
= stack_new(StructTest2
*);
88 StructTest2
* st2
= (StructTest2
*) malloc(n
* sizeof (StructTest2
));
89 for (int i
= n
- 1; i
>= 0; i
--)
91 st2
[i
].a
= (float) rand() / RAND_MAX
;
92 st2
[i
].b
= (StructTest1
*) malloc(sizeof (StructTest1
));
93 st2
[i
].b
->a
= rand() % 42;
94 st2
[i
].b
->b
= (double) rand() / RAND_MAX
;
95 stack_push(s
, st2
+ i
);
97 for (int i
= 0; i
< n
; i
++)
100 stack_top(s
, st2Cell
);
101 lu_assert_dbl_eq(st2Cell
->a
, st2
[i
].a
);
102 lu_assert_int_eq(st2Cell
->b
->a
, st2
[i
].b
->a
);
103 lu_assert_dbl_eq(st2Cell
->b
->b
, st2
[i
].b
->b
);
105 safe_free(st2Cell
->b
);
111 void t_stack_copy() //FTEST
115 Stack
* s
= stack_new(int);
116 for (int i
= 0; i
< n
; i
++)
117 stack_push(s
, rand() % 42);
118 Stack
* sc
= stack_copy(s
);
120 lu_assert_int_eq(stack_size(s
), stack_size(sc
));
122 for (int i
= 0; i
< n
; i
++)
126 lu_assert_int_eq(a
, b
);