diff options
author | Craig Small <csmall@dropbear.xyz> | 2022-08-29 20:28:03 +1000 |
---|---|---|
committer | Craig Small <csmall@dropbear.xyz> | 2022-08-29 20:28:03 +1000 |
commit | 47a8676625bc2204a173f7082f4270cdfe8b423f (patch) | |
tree | 2acab1825cfda76835e960657ed4ea9d637f10c0 /src/tests/test_strtod_nol.c | |
parent | dcce8038bed372141bd97126a71ceee25bf48abf (diff) | |
download | procps-ng-47a8676625bc2204a173f7082f4270cdfe8b423f.tar.gz |
build-sys: Relocate lib/
test files in lib go to src/tests
include/ goes to local/
lib/*.c goes to local/
Signed-off-by: Craig Small <csmall@dropbear.xyz>
Diffstat (limited to 'src/tests/test_strtod_nol.c')
-rw-r--r-- | src/tests/test_strtod_nol.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/tests/test_strtod_nol.c b/src/tests/test_strtod_nol.c new file mode 100644 index 0000000..0be798c --- /dev/null +++ b/src/tests/test_strtod_nol.c @@ -0,0 +1,45 @@ + +#include <stdio.h> +#include <stdlib.h> +#include "strutils.h" + +struct strtod_tests { + char *string; + double result; +}; + +struct strtod_tests tests[] = { + {"123", 123.0}, + {"-123", -123.0}, + {"12.34", 12.34}, + {"-12.34", -12.34}, + {".34", 0.34}, + {"-.34", -0.34}, + {"12,34", 12.34}, + {"-12,34", -12.34}, + {",34", 0.34}, + {"-,34", -0.34}, + {"0", 0.0}, + {".0", 0.0}, + {"0.0", 0.0}, + {NULL, 0.0} +}; + + + +int main(int argc, char *argv[]) +{ + int i; + double val; + + for(i=0; tests[i].string != NULL; i++) { + if(strtod_nol_or_err(tests[i].string, "Cannot parse number") != + tests[i].result) { + fprintf(stderr, "FAIL: strtod_nol_or_err(\"%s\") != %f\n", + tests[i].string, tests[i].result); + return EXIT_FAILURE; + } + //fprintf(stderr, "PASS: strtod_nol for %s\n", tests[i].string); + } + return EXIT_SUCCESS; +} |