2 #include "cgds/Queue.h"
8 Queue
* q
= queue_new(int);
15 lu_assert(queue_empty(q
));
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()
45 Queue
* q
= queue_new(double);
46 for (int i
= 0; i
< n
; i
++)
47 queue_push(q
, (double) i
);
48 // iterate and check values
50 while (!queue_empty(q
))
54 lu_assert_dbl_eq(d
, ckValue
);
59 lu_assert(queue_empty(q
));
63 void t_queue_push_pop_evolved()
67 Queue
* q
= queue_new(StructTest1
);
68 StructTest1
* st1
= (StructTest1
*) safe_malloc(n
* sizeof (StructTest1
));
69 for (int i
= 0; i
< n
; i
++)
71 st1
[i
].a
= rand() % 42;
72 st1
[i
].b
= (double) rand() / RAND_MAX
;
73 queue_push(q
, *(st1
+ i
));
75 for (int i
= 0; i
< n
; i
++)
78 queue_peek(q
, st1Cell
);
79 lu_assert_int_eq(st1Cell
.a
, st1
[i
].a
);
80 lu_assert_dbl_eq(st1Cell
.b
, st1
[i
].b
);
86 q
= queue_new(StructTest2
*);
87 StructTest2
* st2
= (StructTest2
*) safe_malloc(n
* sizeof (StructTest2
));
88 for (int i
= 0; i
< n
; i
++)
90 st2
[i
].a
= (float) rand() / RAND_MAX
;
91 st2
[i
].b
= (StructTest1
*) safe_malloc(sizeof (StructTest1
));
92 st2
[i
].b
->a
= rand() % 42;
93 st2
[i
].b
->b
= (double) rand() / RAND_MAX
;
94 queue_push(q
, st2
+ i
);
96 for (int i
= 0; i
< n
; i
++)
99 queue_peek(q
, st2Cell
);
100 lu_assert_dbl_eq(st2Cell
->a
, st2
[i
].a
);
101 lu_assert_int_eq(st2Cell
->b
->a
, st2
[i
].b
->a
);
102 lu_assert_dbl_eq(st2Cell
->b
->b
, st2
[i
].b
->b
);
104 safe_free(st2Cell
->b
);
114 Queue
* q
= queue_new(int);
115 for (int i
= 0; i
< n
; i
++)
116 queue_push(q
, rand() % 42);
117 Queue
* qc
= queue_copy(q
);
119 lu_assert_int_eq(queue_size(q
), queue_size(qc
));
121 for (int i
= 0; i
< n
; i
++)
125 lu_assert_int_eq(a
, b
);