From 07b6e4dad0ffe550b5f6b4f5552fb275dd8f4a41 Mon Sep 17 00:00:00 2001 From: millert <> Date: Fri, 17 Sep 2010 19:51:38 +0000 Subject: 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. --- src/regress/lib/libc/gcvt/Makefile | 5 ++++ src/regress/lib/libc/gcvt/gcvt_test.c | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/regress/lib/libc/gcvt/Makefile create mode 100644 src/regress/lib/libc/gcvt/gcvt_test.c diff --git a/src/regress/lib/libc/gcvt/Makefile b/src/regress/lib/libc/gcvt/Makefile new file mode 100644 index 0000000000..d8efaa9362 --- /dev/null +++ b/src/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 diff --git a/src/regress/lib/libc/gcvt/gcvt_test.c b/src/regress/lib/libc/gcvt/gcvt_test.c new file mode 100644 index 0000000000..743b467d18 --- /dev/null +++ b/src/regress/lib/libc/gcvt/gcvt_test.c @@ -0,0 +1,56 @@ +/* Public domain */ + +#include +#include +#include + +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; +} -- cgit v1.2.3-55-g6feb