6 static void dtor(void *ptr
)
8 a_u32
*obj
= a_u32_(*, ptr
);
9 printf("%" PRIu32
" ", *obj
);
12 static void back(void)
15 a_u32 buf
[10], i
, *it
, *at
;
16 a_buf_ctor(&ctx
, buf
, sizeof(a_u32
), 10);
18 for (i
= 0; i
!= 20; ++i
)
20 a_u32
*obj
= A_BUF_PUSH_BACK(a_u32
, &ctx
);
21 if (obj
) { *obj
= i
; }
24 A_BUF_FOREACH(a_u32
*, it
, at
, &ctx
)
26 printf("%" PRIu32
" ", *it
);
30 for (i
= 0; i
!= 20; ++i
)
32 a_u32
*obj
= A_BUF_PULL_BACK(a_u32
, &ctx
);
33 if (obj
) { printf("%" PRIu32
" ", *obj
); }
37 a_buf_dtor(&ctx
, dtor
);
40 static void fore(void)
43 a_u32 buf
[10], i
, *it
, *at
;
44 a_buf_ctor(&ctx
, buf
, sizeof(a_u32
), 10);
46 for (i
= 0; i
!= 20; ++i
)
48 a_u32
*obj
= A_BUF_PUSH_FORE(a_u32
, &ctx
);
49 if (obj
) { *obj
= i
; }
52 A_BUF_FOREACH_REVERSE(a_u32
*, it
, at
, &ctx
)
54 printf("%" PRIu32
" ", *it
);
58 for (i
= 0; i
!= 20; ++i
)
60 a_u32
*obj
= A_BUF_PULL_FORE(a_u32
, &ctx
);
61 if (obj
) { printf("%" PRIu32
" ", *obj
); }
65 a_buf_dtor(&ctx
, dtor
);
71 static int small(void const *lhs
, void const *rhs
)
73 int a
= *a_int_(const *, lhs
);
74 int b
= *a_int_(const *, rhs
);
75 return (a
> b
) - (a
< b
);
78 static int large(void const *lhs
, void const *rhs
)
80 int a
= *a_int_(const *, lhs
);
81 int b
= *a_int_(const *, rhs
);
82 return (a
< b
) - (a
> b
);
85 static int rand10(void)
87 return a_cast_s(int, rand() / a_cast_s(double, RAND_MAX
) * 10); /* NOLINT */
90 static void test_sort(void)
94 int buf
[10], *it
, *at
;
95 unsigned int t
= a_cast_s(unsigned int, time(A_NULL
));
96 a_buf_ctor(&ctx
, buf
, sizeof(int), 10);
100 a_buf_drop(&ctx
, A_NULL
);
101 for (i
= 0; i
!= 10; ++i
)
103 int *obj
= A_BUF_PUSH_FORE(int, &ctx
);
108 a_buf_sort_fore(&ctx
, small
);
112 A_BUF_FOREACH(int *, it
, at
, &ctx
)
114 if (x
>= 0) { TEST_BUG(x
<= *it
); }
122 a_buf_drop(&ctx
, A_NULL
);
123 for (i
= 0; i
!= 10; ++i
)
125 int *obj
= A_BUF_PUSH_BACK(int, &ctx
);
130 a_buf_sort_back(&ctx
, small
);
134 A_BUF_FOREACH(int *, it
, at
, &ctx
)
136 if (x
>= 0) { TEST_BUG(x
<= *it
); }
144 a_buf_drop(&ctx
, A_NULL
);
145 for (i
= 0; i
!= 10; ++i
)
148 int *obj
= A_BUF_PUSH_SORT(int, &ctx
, &key
, small
);
156 A_BUF_FOREACH(int *, it
, at
, &ctx
)
158 if (x
>= 0) { TEST_BUG(x
<= *it
); }
166 A_BUF_FOREACH(int *, it
, at
, &ctx
)
172 a_buf_sort(&ctx
, small
);
173 A_BUF_FOREACH(int *, it
, at
, &ctx
)
175 if (x
>= 0) { TEST_BUG(x
<= *it
); }
183 A_BUF_FOREACH(int *, it
, at
, &ctx
)
189 a_buf_sort(&ctx
, large
);
190 A_BUF_FOREACH(int *, it
, at
, &ctx
)
192 if (x
>= 0) { TEST_BUG(x
>= *it
); }
199 a_str
*ok
= a_str_new();
200 a_str
*no
= a_str_new();
201 a_str_puts(ok
, "finding ");
202 a_str_puts(no
, "missing ");
203 for (i
= 0; i
!= 10; ++i
)
205 int *obj
= A_BUF_SEARCH(int, &ctx
, &i
, large
);
208 a_str_putf(ok
, "%i ", *obj
);
212 a_str_putf(no
, "%i ", i
);
215 printf("%s\n%s\n", a_str_ptr(ok
), a_str_ptr(no
));
220 a_buf_dtor(&ctx
, A_NULL
);
223 int main(int argc
, char *argv
[]) /* NOLINT(misc-definitions-in-headers) */