diff options
Diffstat (limited to 'test.c')
-rw-r--r-- | test.c | 105 |
1 files changed, 62 insertions, 43 deletions
@@ -5,6 +5,7 @@ #include <stdio.h> #include <zap/math.h> #include <zap/mem.h> +#include <zap/str.h> #define test(_expr,_val,_cmp) \ fprintf(stderr,"(" #_expr "): %" PRIXMAX "\n(" #_val "): %" PRIXMAX "\n",(uintmax_t)(_expr),(uintmax_t)(_val)); \ @@ -17,56 +18,55 @@ int main(void) { test(zap_bytelen,CHAR_BIT,==) test(sizeof (zap_i8),sizeof (unsigned char),==) - /* bs */ { - /* standard */ - /* maximum */ - test(zap_minval_c, CHAR_MIN, ==) - test(zap_minval_sc,SCHAR_MIN,==) - test(zap_minval_s, SHRT_MIN, ==) - test(zap_minval_i, INT_MIN, ==) - test(zap_minval_l, LONG_MIN, ==) - test(zap_minval_ll,LLONG_MIN,==) - /* minimum */ - test(zap_maxval_c, CHAR_MAX, ==) - test(zap_maxval_sc,SCHAR_MAX,==) - test(zap_maxval_uc,UCHAR_MAX,==) - test(zap_maxval_s, SHRT_MAX, ==) - test(zap_maxval_i, INT_MAX, ==) - test(zap_maxval_l, LONG_MAX, ==) - test(zap_maxval_ll,LLONG_MAX,==) - /* minimum-width */ - /* minimum */ - test(zap_minval_i8s, INT_LEAST8_MIN, ==) - test(zap_minval_i01s,INT_LEAST16_MIN,==) - test(zap_minval_i02s,INT_LEAST32_MIN,==) - test(zap_minval_i04s,INT_LEAST64_MIN,==) - /* maximum */ - test(zap_maxval_i8, UINT_LEAST8_MAX, ==) - test(zap_maxval_i01, UINT_LEAST16_MAX,==) - test(zap_maxval_i02, UINT_LEAST32_MAX,==) - test(zap_maxval_i04, UINT_LEAST64_MAX,==) - test(zap_maxval_i8s, INT_LEAST8_MAX, ==) - test(zap_maxval_i01s,INT_LEAST16_MAX, ==) - test(zap_maxval_i02s,INT_LEAST32_MAX, ==) - test(zap_maxval_i04s,INT_LEAST64_MAX, ==) + // standard + // minimum + test(zap_minvalc, CHAR_MIN, ==) + test(zap_minvalsc,SCHAR_MIN,==) + test(zap_minvals, SHRT_MIN, ==) + test(zap_minvali, INT_MIN, ==) + test(zap_minvall, LONG_MIN, ==) + test(zap_minvalll,LLONG_MIN,==) + // maximum + test(zap_maxvalc, CHAR_MAX, ==) + test(zap_maxvalsc,SCHAR_MAX,==) + test(zap_maxvaluc,UCHAR_MAX,==) + test(zap_maxvals, SHRT_MAX, ==) + test(zap_maxvali, INT_MAX, ==) + test(zap_maxvall, LONG_MAX, ==) + test(zap_maxvalll,LLONG_MAX,==) + // minimum-width + // minimum + test(zap_minval8s, INT_LEAST8_MIN, ==) + test(zap_minval01s,INT_LEAST16_MIN,==) + test(zap_minval02s,INT_LEAST32_MIN,==) + test(zap_minval04s,INT_LEAST64_MIN,==) + // maximum + test(zap_maxval8, UINT_LEAST8_MAX, ==) + test(zap_maxval01, UINT_LEAST16_MAX,==) + test(zap_maxval02, UINT_LEAST32_MAX,==) + test(zap_maxval04, UINT_LEAST64_MAX,==) + test(zap_maxval8s, INT_LEAST8_MAX, ==) + test(zap_maxval01s,INT_LEAST16_MAX, ==) + test(zap_maxval02s,INT_LEAST32_MAX, ==) + test(zap_maxval04s,INT_LEAST64_MAX, ==) } - /* math */ + // math { - zap_i8 const val = zap_abs8(-0x80); - test(val,0x80u,==) + unsigned int const val = zap_absi(zap_minvali); + test(val,(unsigned int)zap_maxvali + 0x1u,==) } { - zap_quotrem8 const quotrem = zap_divmod8(0x45u,0x5u); - test(quotrem.quot,0xDu,==) - test(quotrem.rem, 0x4u,==) + zap_quotremi const quotrem = zap_divmodi(0x45,0x5); + test(quotrem.quot,0xD,==) + test(quotrem.rem, 0x4,==) } { - test(zap_divmod02(0x10000u,zap_exp8(0x3u,0x3u)).quot,0x97Bu,==) /* 3^(-3) */ - test(zap_exp8(0x0u,0x0u),0x1u,==) - test(zap_exp8(0x0u,0x1u),0x0u,==) + test(zap_divmodl(0x10000,zap_expsc(0x3,0x3)).quot,0x97B,==) /* 3^(-3) */ + test(zap_expsc(0x0,0x0),0x1,==) + test(zap_expsc(0x0,0x1),0x0,==) } - /* mem */ + // mem { zap_i8 const src[0x3Fu] = { 0x02u,0x03u,0x05u,0x07u,0x0Bu,0x0Du,0x11u,0x13u, @@ -117,7 +117,7 @@ int main(void) { } { zap_i04 val = 0x0u; - zap_fill(&val,~(zap_i8)0x0u,sizeof (val)); + zap_fill(&val,(zap_i8)-0x1u,sizeof (val)); test(val,~(zap_i04)0x0u,==) } { @@ -136,6 +136,7 @@ int main(void) { }; test(zap_srch(arr,0x7Fu,sizeof (arr)),&arr[0x2u],==) } + // str { zap_i8 const utf8[] = { 0x26u, @@ -372,4 +373,22 @@ int main(void) { test(cmp0,0x0u,>); test(cmp1,0x0u,==); } + { + int val = -0x4560; + zap_i8 len = zap_fmtleni(val,0x10u); + test(len,0x5u,==); + zap_i02 str[0x5u]; + zap_fmti(str,val,0x10u,0x1u); + test(str[0x0u],0x2212u,==); + test(str[0x1u],0x0034u,==); + test(str[0x2u],0x0035u,==); + test(str[0x3u],0x0036u,==); + test(str[0x4u],0x0030u,==); + val = 0x8E; + len = zap_fmtleni(val,0xCu); + test(len,0x2u,==); + zap_fmti(str,val,0xCu,0x0u); + test(str[0x0u],0x218Au,==); + test(str[0x1u],0x218Bu,==); + } } |