summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/regress/lib/libc/gcvt/Makefile5
-rw-r--r--src/regress/lib/libc/gcvt/gcvt_test.c56
2 files changed, 61 insertions, 0 deletions
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 @@
1# $OpenBSD: Makefile,v 1.1 2010/09/17 19:51:38 millert Exp $
2
3PROG= gcvt_test
4
5.include <bsd.regress.mk>
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 @@
1/* Public domain */
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6
7static struct test_vector {
8 double d;
9 int ndig;
10 char *expect;
11} test_vectors[] = {
12 { 0.1, 8, "0.1" },
13 { 0.01, 8, "0.01" },
14 { 0.001, 8, "0.001" },
15 { 0.0001, 8, "0.0001" },
16 { 0.00009, 8, "9e-05" },
17 { 1.0, 8, "1" },
18 { 1.1, 8, "1.1" },
19 { 1.01, 8, "1.01" },
20 { 1.001, 8, "1.001" },
21 { 1.0001, 8, "1.0001" },
22 { 1.00001, 8, "1.00001" },
23 { 1.000001, 8, "1.000001" },
24 { 0.0, 8, "0" },
25 { -1.0, 8, "-1" },
26 { 100000.0, 8, "100000" },
27 { -100000.0, 8, "-100000" },
28 { 123.456, 8, "123.456" },
29 { 1e34, 8, "1e+34" },
30 { 0.0, 0, NULL }
31};
32
33static int
34dotest(struct test_vector *tv)
35{
36 char buf[64];
37
38 gcvt(tv->d, tv->ndig, buf);
39 if (strcmp(tv->expect, buf) != 0) {
40 fprintf(stderr, "gcvt: expected %s, got %s\n", tv->expect, buf);
41 return 1;
42 }
43 return 0;
44}
45
46int
47main(int argc, char *argv[])
48{
49 int i, failures = 0;
50
51 for (i = 0; test_vectors[i].expect != NULL; i++) {
52 failures += dotest(&test_vectors[i]);
53 }
54
55 return failures;
56}