2 #include "cgds/Queue.h"
3 #include "test/helpers.h"
6 void t_queue_clear() //FTEST
8 Queue
* q
= queue_new(int);
15 lu_assert(queue_empty(q
));
20 void t_queue_size() //FTEST
22 Queue
* q
= queue_new(int);
27 lu_assert_int_eq(queue_size(q
), 3);
31 lu_assert_int_eq(queue_size(q
), 5);
36 lu_assert_int_eq(queue_size(q
), 8);
41 void t_queue_push_pop_basic() //FTEST
45 Queue
* q
= queue_new(double);
46 for (int i
= 0; i
< n
; i
++) queue_push(q
, (double) i
);
47 // iterate and check values
49 while (!queue_empty(q
))
53 lu_assert_dbl_eq(d
, ckValue
);
58 lu_assert(queue_empty(q
));
62 void t_queue_push_pop_evolved() //FTEST
66 Queue
* q
= queue_new(StructTest1
);
67 StructTest1
* st1
= (StructTest1
*) safe_malloc(n
* sizeof (StructTest1
));
68 for (int i
= 0; i
< n
; i
++)
70 st1
[i
].a
= rand() % 42;
71 st1
[i
].b
= (double) rand() / RAND_MAX
;
72 queue_push(q
, *(st1
+ i
));
74 for (int i
= 0; i
< n
; i
++)
77 queue_peek(q
, st1Cell
);
78 lu_assert_int_eq(st1Cell
.a
, st1
[i
].a
);
79 lu_assert_dbl_eq(st1Cell
.b
, st1
[i
].b
);
85 q
= queue_new(StructTest2
*);
86 StructTest2
* st2
= (StructTest2
*) safe_malloc(n
* sizeof (StructTest2
));
87 for (int i
= 0; i
< n
; i
++)
89 st2
[i
].a
= (float) rand() / RAND_MAX
;
90 st2
[i
].b
= (StructTest1
*) safe_malloc(sizeof (StructTest1
));
91 st2
[i
].b
->a
= rand() % 42;
92 st2
[i
].b
->b
= (double) rand() / RAND_MAX
;
93 queue_push(q
, st2
+ i
);
95 for (int i
= 0; i
< n
; i
++)
98 queue_peek(q
, st2Cell
);
99 lu_assert_dbl_eq(st2Cell
->a
, st2
[i
].a
);
100 lu_assert_int_eq(st2Cell
->b
->a
, st2
[i
].b
->a
);
101 lu_assert_dbl_eq(st2Cell
->b
->b
, st2
[i
].b
->b
);
103 safe_free(st2Cell
->b
);
109 void t_queue_copy() //FTEST
113 Queue
* q
= queue_new(int);
114 for (int i
= 0; i
< n
; i
++)
115 queue_push(q
, rand() % 42);
116 Queue
* qc
= queue_copy(q
);
118 lu_assert_int_eq(queue_size(q
), queue_size(qc
));
120 for (int i
= 0; i
< n
; i
++)
124 lu_assert_int_eq(a
, b
);