5 static void test_sq(void)
7 A_BUILD_ASSERT(A_SQ(+2) == 4);
8 A_BUILD_ASSERT(A_SQ(-2) == 4);
11 static void test_abs(void)
13 A_BUILD_ASSERT(A_ABS(+1) > 0);
14 A_BUILD_ASSERT(A_ABS(-1) > 0);
15 A_BUILD_ASSERT(A_ABS_(+1, -1) > 0);
16 A_BUILD_ASSERT(A_ABS_(-1, +1) > 0);
19 static void test_min(void)
21 A_BUILD_ASSERT(A_MIN(0, 1) == 0);
22 A_BUILD_ASSERT(A_MIN(1, 0) == 0);
25 static void test_max(void)
27 A_BUILD_ASSERT(A_MAX(0, 1) == 1);
28 A_BUILD_ASSERT(A_MAX(1, 0) == 1);
31 static void test_sgn(void)
33 A_BUILD_ASSERT(A_SGN(0) == 0);
34 A_BUILD_ASSERT(A_SGN(+10) == +1);
35 A_BUILD_ASSERT(A_SGN(-10) == -1);
36 A_BUILD_ASSERT(A_SGN_(0, 0) == 0);
37 A_BUILD_ASSERT(A_SGN_(+1, -1) == +1);
38 A_BUILD_ASSERT(A_SGN_(-1, +1) == -1);
41 static void test_sat(void)
43 A_BUILD_ASSERT(A_SAT(0, -10, +10) == 0);
44 A_BUILD_ASSERT(A_SAT(+100, -10, +10) <= +10);
45 A_BUILD_ASSERT(A_SAT(-100, -10, +10) >= -10);
48 static void test_for(int argc
, char *argv
[])
51 unsigned int i
, n
= 10;
55 char *endptr
= A_NULL
;
56 unsigned long u
= strtoul(argv
[1], &endptr
, 0);
57 if (u
> n
) { n
= a_cast_s(unsigned int, u
); }
60 p
= a_new(int, A_NULL
, n
);
66 A_FORENUM(unsigned int, i
, n
)
68 p
[i
] = a_cast_s(int, i
);
73 A_FOREACH(int *, it
, at
, p
, n
) { debug("%i ", *it
); }
76 A_ITERATE(int *, it
, at
, p
, d
) { debug("%i ", *it
); }
79 A_FORENUM_REVERSE(unsigned int, i
, n
)
81 p
[i
] = a_cast_s(int, i
);
86 A_FOREACH_REVERSE(int *, it
, at
, p
, n
) { debug("%i ", *it
); }
89 A_ITERATE_REVERSE(int *, it
, at
, p
, d
) { debug("%i ", *it
); }
95 static void test_swap(int argc
, char *argv
[])
98 a_u64 rhs
= A_U64_MAX
;
99 debug("0x%016" PRIX64
" 0x%016" PRIX64
" -> ", lhs
, rhs
);
100 a_swap(&lhs
, &rhs
, 1);
101 debug("0x%016" PRIX64
" 0x%016" PRIX64
" \n", lhs
, rhs
);
102 debug("0x%016" PRIX64
" 0x%016" PRIX64
" -> ", lhs
, rhs
);
103 a_swap(&lhs
, &rhs
, 2);
104 debug("0x%016" PRIX64
" 0x%016" PRIX64
" \n", lhs
, rhs
);
105 debug("0x%016" PRIX64
" 0x%016" PRIX64
" -> ", lhs
, rhs
);
106 a_swap(&lhs
, &rhs
, 4);
107 debug("0x%016" PRIX64
" 0x%016" PRIX64
" \n", lhs
, rhs
);
108 debug("0x%016" PRIX64
" 0x%016" PRIX64
" -> ", lhs
, rhs
);
109 a_swap(&lhs
, &rhs
, 8);
110 debug("0x%016" PRIX64
" 0x%016" PRIX64
" \n", lhs
, rhs
);
117 int main(int argc
, char *argv
[]) /* NOLINT(misc-definitions-in-headers) */
127 test_for(argc
, argv
);
128 test_swap(argc
, argv
);
131 switch (a_hash_bkdr(argv
[1], 0))
133 case 0x001AEED5: /* for */
134 test_for(argc
- 1, argv
+ 1);
136 case 0x0F8837E3: /* swap */
137 test_swap(argc
- 1, argv
+ 1);