diff options
-rw-r--r-- | src/regress/lib/libc/gcvt/gcvt_test.c | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/src/regress/lib/libc/gcvt/gcvt_test.c b/src/regress/lib/libc/gcvt/gcvt_test.c index 743b467d18..b976a7dfe6 100644 --- a/src/regress/lib/libc/gcvt/gcvt_test.c +++ b/src/regress/lib/libc/gcvt/gcvt_test.c | |||
@@ -9,6 +9,7 @@ static struct test_vector { | |||
9 | int ndig; | 9 | int ndig; |
10 | char *expect; | 10 | char *expect; |
11 | } test_vectors[] = { | 11 | } test_vectors[] = { |
12 | /* adapted from perl's Configure test */ | ||
12 | { 0.1, 8, "0.1" }, | 13 | { 0.1, 8, "0.1" }, |
13 | { 0.01, 8, "0.01" }, | 14 | { 0.01, 8, "0.01" }, |
14 | { 0.001, 8, "0.001" }, | 15 | { 0.001, 8, "0.001" }, |
@@ -27,17 +28,70 @@ static struct test_vector { | |||
27 | { -100000.0, 8, "-100000" }, | 28 | { -100000.0, 8, "-100000" }, |
28 | { 123.456, 8, "123.456" }, | 29 | { 123.456, 8, "123.456" }, |
29 | { 1e34, 8, "1e+34" }, | 30 | { 1e34, 8, "1e+34" }, |
30 | { 0.0, 0, NULL } | 31 | /* adapted from emx */ |
32 | { 0.0, -1, "0" }, | ||
33 | { 0.0, 0, "0" }, | ||
34 | { 0.0, 1, "0" }, | ||
35 | { 0.0, 2, "0" }, | ||
36 | { 1.0, -1, "1" }, | ||
37 | { 1.0, 0, "1" }, | ||
38 | { 1.0, 2, "1" }, | ||
39 | { 1.0, 10, "1" }, | ||
40 | { 1.236, 0, "1" }, | ||
41 | { 1.236, 1, "1" }, | ||
42 | { 1.236, 2, "1.2" }, | ||
43 | { 1.236, 3, "1.24" }, | ||
44 | { 1.236, 4, "1.236" }, | ||
45 | { 1.236, 5, "1.236" }, | ||
46 | { 1.236, 6, "1.236" }, | ||
47 | { 12.36, 0, "1e+01" }, | ||
48 | { 12.36, 1, "1e+01" }, | ||
49 | { 12.36, 2, "12" }, | ||
50 | { 12.36, 3, "12.4" }, | ||
51 | { 12.36, 4, "12.36" }, | ||
52 | { 12.36, 5, "12.36" }, | ||
53 | { 12.36, 6, "12.36" }, | ||
54 | { 123.6, 0, "1e+02" }, | ||
55 | { 123.6, 1, "1e+02" }, | ||
56 | { 123.6, 2, "1.2e+02" }, | ||
57 | { 123.6, 3, "124" }, | ||
58 | { 123.6, 4, "123.6" }, | ||
59 | { 123.6, 5, "123.6" }, | ||
60 | { 123.6, 6, "123.6" }, | ||
61 | { 1236.0, 0, "1e+03" }, | ||
62 | { 1236.0, 1, "1e+03" }, | ||
63 | { 1236.0, 2, "1.2e+03" }, | ||
64 | { 1236.0, 3, "1.24e+03" }, | ||
65 | { 1236.0, 4, "1236" }, | ||
66 | { 1236.0, 5, "1236" }, | ||
67 | { 1236.0, 6, "1236" }, | ||
68 | { 1e100, 10, "1e+100" }, | ||
69 | { 1e100, 20, "1.0000000000000000159e+100" }, | ||
70 | { 0.01236, 0, "0.01" }, | ||
71 | { 0.01236, 1, "0.01" }, | ||
72 | { 0.01236, 2, "0.012" }, | ||
73 | { 0.01236, 3, "0.0124" }, | ||
74 | { 0.01236, 4, "0.01236" }, | ||
75 | { 1e-100, 20, "1.00000000000000002e-100" }, | ||
76 | { -1.2, 5, "-1.2" }, | ||
77 | { -0.03, 5, "-0.03" }, | ||
78 | { 0.1, 1, "0.1" }, | ||
79 | { 0.1, 0, "0.1" }, | ||
80 | { 0.099999, 10, "0.099999" }, | ||
81 | { 0.99999, 10, "0.99999" }, | ||
31 | }; | 82 | }; |
32 | 83 | ||
84 | #define NTESTVEC (sizeof(test_vectors) / sizeof(test_vectors[0])) | ||
85 | |||
33 | static int | 86 | static int |
34 | dotest(struct test_vector *tv) | 87 | dotest(struct test_vector *tv) |
35 | { | 88 | { |
36 | char buf[64]; | 89 | char buf[256], *got; |
37 | 90 | ||
38 | gcvt(tv->d, tv->ndig, buf); | 91 | got = gcvt(tv->d, tv->ndig, buf); |
39 | if (strcmp(tv->expect, buf) != 0) { | 92 | if (strcmp(tv->expect, got) != 0) { |
40 | fprintf(stderr, "gcvt: expected %s, got %s\n", tv->expect, buf); | 93 | fprintf(stderr, "%g @ %d: expected %s, got %s\n", |
94 | tv->d, tv->ndig, tv->expect, got); | ||
41 | return 1; | 95 | return 1; |
42 | } | 96 | } |
43 | return 0; | 97 | return 0; |
@@ -48,7 +102,7 @@ main(int argc, char *argv[]) | |||
48 | { | 102 | { |
49 | int i, failures = 0; | 103 | int i, failures = 0; |
50 | 104 | ||
51 | for (i = 0; test_vectors[i].expect != NULL; i++) { | 105 | for (i = 0; i < NTESTVEC; i++) { |
52 | failures += dotest(&test_vectors[i]); | 106 | failures += dotest(&test_vectors[i]); |
53 | } | 107 | } |
54 | 108 | ||