diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2010-09-17 19:51:39 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2010-09-17 19:51:39 +0000 |
commit | 2ff2770fbdcae70accbd9fa16a2bc8cd10350905 (patch) | |
tree | 88cc6a010673348bdca67d80e63b3db3bb4852c1 /regress/lib | |
parent | 08c474e95b8320edbce1cea23cac624ec9fb7e83 (diff) |
Add gcvt() regress with test vectors derived from perl regress.
Does not currently pass, which is why perl can't use it to format
doubles.
Diffstat (limited to 'regress/lib')
-rw-r--r-- | regress/lib/libc/gcvt/Makefile | 5 | ||||
-rw-r--r-- | regress/lib/libc/gcvt/gcvt_test.c | 56 |
2 files changed, 61 insertions, 0 deletions
diff --git a/regress/lib/libc/gcvt/Makefile b/regress/lib/libc/gcvt/Makefile new file mode 100644 index 00000000000..d8efaa9362f --- /dev/null +++ b/regress/lib/libc/gcvt/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2010/09/17 19:51:38 millert Exp $ + +PROG= gcvt_test + +.include <bsd.regress.mk> diff --git a/regress/lib/libc/gcvt/gcvt_test.c b/regress/lib/libc/gcvt/gcvt_test.c new file mode 100644 index 00000000000..743b467d183 --- /dev/null +++ b/regress/lib/libc/gcvt/gcvt_test.c @@ -0,0 +1,56 @@ +/* Public domain */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static struct test_vector { + double d; + int ndig; + char *expect; +} test_vectors[] = { + { 0.1, 8, "0.1" }, + { 0.01, 8, "0.01" }, + { 0.001, 8, "0.001" }, + { 0.0001, 8, "0.0001" }, + { 0.00009, 8, "9e-05" }, + { 1.0, 8, "1" }, + { 1.1, 8, "1.1" }, + { 1.01, 8, "1.01" }, + { 1.001, 8, "1.001" }, + { 1.0001, 8, "1.0001" }, + { 1.00001, 8, "1.00001" }, + { 1.000001, 8, "1.000001" }, + { 0.0, 8, "0" }, + { -1.0, 8, "-1" }, + { 100000.0, 8, "100000" }, + { -100000.0, 8, "-100000" }, + { 123.456, 8, "123.456" }, + { 1e34, 8, "1e+34" }, + { 0.0, 0, NULL } +}; + +static int +dotest(struct test_vector *tv) +{ + char buf[64]; + + gcvt(tv->d, tv->ndig, buf); + if (strcmp(tv->expect, buf) != 0) { + fprintf(stderr, "gcvt: expected %s, got %s\n", tv->expect, buf); + return 1; + } + return 0; +} + +int +main(int argc, char *argv[]) +{ + int i, failures = 0; + + for (i = 0; test_vectors[i].expect != NULL; i++) { + failures += dotest(&test_vectors[i]); + } + + return failures; +} |