summaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c76
1 files changed, 64 insertions, 12 deletions
diff --git a/test.c b/test.c
index 71a0942..423ae58 100644
--- a/test.c
+++ b/test.c
@@ -1,5 +1,6 @@
#include <assert.h>
#include <inttypes.h>
+#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <zap/math.h>
@@ -14,7 +15,42 @@
fputs("\x1B[92mSuccess\x1B[0m (" #_cmp ")\n\n",stderr);
int main(void) {
- test(sizeof (zap_byte),sizeof (unsigned char),==)
+ 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, ==)
+ }
/* math */
{
zap_i8 const val = zap_abs8(-0x80);
@@ -81,15 +117,15 @@ int main(void) {
}
{
zap_i04 val = 0x0u;
- zap_fill(&val,~(zap_byte)0x0u,sizeof (val));
+ zap_fill(&val,~(zap_i8)0x0u,sizeof (val));
test(val,~(zap_i04)0x0u,==)
}
{
zap_i01 const val0 = 0x4545u;
zap_i01 const val1 = 0x4545u;
zap_i01 const val2 = 0x4560u;
- test(zap_eq(&val0,&val1,sizeof (val0)),zap_true,==)
- test(zap_eq(&val0,&val2,sizeof (val0)),zap_false,==)
+ test(zap_eq(&val0,&val1,sizeof (val0)),0x1u,==)
+ test(zap_eq(&val0,&val2,sizeof (val0)),0x0u,==)
}
{
zap_i8 const arr[] = {
@@ -101,7 +137,7 @@ int main(void) {
test(zap_srch(arr,0x7Fu,sizeof (arr)),&arr[0x2u],==)
}
{
- zap_chr8 const utf8[] = {
+ zap_i8 const utf8[] = {
0x26u,
0xC3u,
0xB0u,
@@ -122,7 +158,7 @@ int main(void) {
};
zap_sz const enclen = zap_utf8declen(utf8);
test(enclen,0x6u,==)
- zap_chr02 * const utf02 = malloc(sizeof (zap_chr02) * (enclen + 0x1u));
+ zap_i02 * const utf02 = malloc(sizeof (zap_i02) * (enclen + 0x1u));
if (utf02 == zap_nullptr) {
fputs("Memory allocation failed!\n",stderr);
return EXIT_FAILURE;
@@ -138,7 +174,7 @@ int main(void) {
free(utf02);
}
{
- zap_chr02 const utf02[] = {
+ zap_i02 const utf02[] = {
0x26u,
0xF0u,
0xD9Eu,
@@ -149,7 +185,7 @@ int main(void) {
};
zap_sz const enclen = zap_utf8enclen(utf02);
test(enclen,0x10u,==)
- zap_chr8 * const utf8 = malloc(enclen + 0x1u);
+ zap_i8 * const utf8 = malloc(enclen + 0x1u);
if (utf8 == zap_nullptr) {
fputs("Memory allocation failed!\n",stderr);
return EXIT_FAILURE;
@@ -175,7 +211,7 @@ int main(void) {
free(utf8);
}
{
- zap_chr8 const win1252[] = {
+ zap_i8 const win1252[] = {
0x26u,
0xF0u,
0x80u,
@@ -209,7 +245,7 @@ int main(void) {
};
zap_sz const enclen = sizeof (win1252) - 0x1u;
test(enclen,0x1Du,==)
- zap_chr02 * const utf02 = malloc(sizeof (zap_chr02) * (enclen + 0x1u));
+ zap_i02 * const utf02 = malloc(sizeof (zap_i02) * (enclen + 0x1u));
if (utf02 == zap_nullptr) {
fputs("Memory allocation failed!\n",stderr);
return EXIT_FAILURE;
@@ -248,7 +284,7 @@ int main(void) {
free(utf02);
}
{
- zap_chr02 const utf02[] = {
+ zap_i02 const utf02[] = {
0x26u,
0xF0u,
0x20ACu,
@@ -282,7 +318,7 @@ int main(void) {
};
zap_sz const enclen = sizeof (utf02) / sizeof (utf02[0x0u]) - 0x1u;
test(enclen,0x1Du,==)
- zap_chr8 * const win1252 = malloc(enclen + 0x1u);
+ zap_i8 * const win1252 = malloc(enclen + 0x1u);
if (win1252 == zap_nullptr) {
fputs("Memory allocation failed!\n",stderr);
return EXIT_FAILURE;
@@ -320,4 +356,20 @@ int main(void) {
test(win1252[0x1Du],0x0u, ==);
free(win1252);
}
+ {
+ char const * str0 = "Hello there!";
+ char const * str1 = "";
+ zap_sz const len0 = zap_strlen(str0);
+ zap_sz const len1 = zap_strlen(str1);
+ test(len0,0xCu,==);
+ test(len1,0x0u,==);
+ }
+ {
+ char const * str0 = "Cogito";
+ char const * str1 = "Sum";
+ zap_i8 const cmp0 = zap_streq(str0,str0);
+ zap_i8 const cmp1 = zap_streq(str0,str1);
+ test(cmp0,0x0u,>);
+ test(cmp1,0x0u,==);
+ }
}