diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2010-09-18 12:46:45 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2010-09-18 12:46:45 +0000 |
commit | d15c42cea6997fafd5d6f9beed5355905ed26d2d (patch) | |
tree | eca3fd1a4aabcd272f4d361e84022f860bf076f3 | |
parent | e38ee6279716af32b525e4589618ce67ba093bc1 (diff) |
Add more test vectors.
-rw-r--r-- | regress/lib/libc/gcvt/gcvt_test.c | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/regress/lib/libc/gcvt/gcvt_test.c b/regress/lib/libc/gcvt/gcvt_test.c index 743b467d183..b976a7dfe6d 100644 --- a/regress/lib/libc/gcvt/gcvt_test.c +++ b/regress/lib/libc/gcvt/gcvt_test.c @@ -9,6 +9,7 @@ static struct test_vector { int ndig; char *expect; } test_vectors[] = { + /* adapted from perl's Configure test */ { 0.1, 8, "0.1" }, { 0.01, 8, "0.01" }, { 0.001, 8, "0.001" }, @@ -27,17 +28,70 @@ static struct test_vector { { -100000.0, 8, "-100000" }, { 123.456, 8, "123.456" }, { 1e34, 8, "1e+34" }, - { 0.0, 0, NULL } + /* adapted from emx */ + { 0.0, -1, "0" }, + { 0.0, 0, "0" }, + { 0.0, 1, "0" }, + { 0.0, 2, "0" }, + { 1.0, -1, "1" }, + { 1.0, 0, "1" }, + { 1.0, 2, "1" }, + { 1.0, 10, "1" }, + { 1.236, 0, "1" }, + { 1.236, 1, "1" }, + { 1.236, 2, "1.2" }, + { 1.236, 3, "1.24" }, + { 1.236, 4, "1.236" }, + { 1.236, 5, "1.236" }, + { 1.236, 6, "1.236" }, + { 12.36, 0, "1e+01" }, + { 12.36, 1, "1e+01" }, + { 12.36, 2, "12" }, + { 12.36, 3, "12.4" }, + { 12.36, 4, "12.36" }, + { 12.36, 5, "12.36" }, + { 12.36, 6, "12.36" }, + { 123.6, 0, "1e+02" }, + { 123.6, 1, "1e+02" }, + { 123.6, 2, "1.2e+02" }, + { 123.6, 3, "124" }, + { 123.6, 4, "123.6" }, + { 123.6, 5, "123.6" }, + { 123.6, 6, "123.6" }, + { 1236.0, 0, "1e+03" }, + { 1236.0, 1, "1e+03" }, + { 1236.0, 2, "1.2e+03" }, + { 1236.0, 3, "1.24e+03" }, + { 1236.0, 4, "1236" }, + { 1236.0, 5, "1236" }, + { 1236.0, 6, "1236" }, + { 1e100, 10, "1e+100" }, + { 1e100, 20, "1.0000000000000000159e+100" }, + { 0.01236, 0, "0.01" }, + { 0.01236, 1, "0.01" }, + { 0.01236, 2, "0.012" }, + { 0.01236, 3, "0.0124" }, + { 0.01236, 4, "0.01236" }, + { 1e-100, 20, "1.00000000000000002e-100" }, + { -1.2, 5, "-1.2" }, + { -0.03, 5, "-0.03" }, + { 0.1, 1, "0.1" }, + { 0.1, 0, "0.1" }, + { 0.099999, 10, "0.099999" }, + { 0.99999, 10, "0.99999" }, }; +#define NTESTVEC (sizeof(test_vectors) / sizeof(test_vectors[0])) + static int dotest(struct test_vector *tv) { - char buf[64]; + char buf[256], *got; - gcvt(tv->d, tv->ndig, buf); - if (strcmp(tv->expect, buf) != 0) { - fprintf(stderr, "gcvt: expected %s, got %s\n", tv->expect, buf); + got = gcvt(tv->d, tv->ndig, buf); + if (strcmp(tv->expect, got) != 0) { + fprintf(stderr, "%g @ %d: expected %s, got %s\n", + tv->d, tv->ndig, tv->expect, got); return 1; } return 0; @@ -48,7 +102,7 @@ main(int argc, char *argv[]) { int i, failures = 0; - for (i = 0; test_vectors[i].expect != NULL; i++) { + for (i = 0; i < NTESTVEC; i++) { failures += dotest(&test_vectors[i]); } |