From 24a8b613ae3340e738673d42cf61af6e0c1e95b4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 4 Dec 1990 16:40:21 +0000 Subject: [PATCH] Added test program --- modules/src/flt_arith/Makefile | 4 +- modules/src/flt_arith/test.c | 84 ++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 modules/src/flt_arith/test.c diff --git a/modules/src/flt_arith/Makefile b/modules/src/flt_arith/Makefile index c1d5ebbcf..65cf43298 100644 --- a/modules/src/flt_arith/Makefile +++ b/modules/src/flt_arith/Makefile @@ -27,8 +27,8 @@ OBJ = flt_ar2flt.$(SUF) flt_div.$(SUF) flt_flt2ar.$(SUF) flt_modf.$(SUF) \ all: $(LIBFLT) test: $(LIBFLT) test.c - $(CC) -o test test.c $(LIBFLT) - ./test + $(CC) -o tst test.c $(LIBFLT) + ./tst $(LIBFLT): $(OBJ) rm -f $(LIBFLT) diff --git a/modules/src/flt_arith/test.c b/modules/src/flt_arith/test.c new file mode 100644 index 000000000..cc50c942d --- /dev/null +++ b/modules/src/flt_arith/test.c @@ -0,0 +1,84 @@ +#include "flt_arith.h" + +struct tests { + char *op1, *op2; + int oper; + char *result; +} tests[] = { + { "1.0", 0, 0, "1.0000000000000000000" }, + { "-1.0", 0, 0, "-1.0000000000000000000" }, + { "0.0", 0, 0, "0.0000000000000000000" }, + { "1.234567", 0, 0, "1.2345670000000000000" }, + { "1.234567", 0, 'D', "1.0000000000000000000" }, + { "1.234567", 0, 'R', "2.3456700000000000000e-1" }, + { "32768", "32768", '+', "6.5536000000000000000e+4" }, + { "32768", "32767", '-', "1.0000000000000000000" }, + { "32768", "32768", '*', "1.0737418240000000000e+9" }, + { "32768", "32768", '/', "1.0000000000000000000" }, + { "1.234567e20", "-1.234567e20", '+', "0.0000000000000000000" }, + { 0, 0, 0, 0} +}; + +main() +{ + register struct tests *p = tests; + int exit_status = 0; + + while (p->op1) { + if (! dotest(p)) exit_status = 1; + p++; + } + exit(exit_status); +} + +int +dotest(p) + register struct tests *p; +{ + char buf[128]; + flt_arith e1, e2, e; + static int testno = 0; + + testno++; + flt_str2flt(p->op1, &e1); + switch(p->oper) { + case '+': + flt_str2flt(p->op2, &e2); + flt_add(&e1, &e2, &e); + break; + case '-': + flt_str2flt(p->op2, &e2); + flt_sub(&e1, &e2, &e); + break; + case '*': + flt_str2flt(p->op2, &e2); + flt_mul(&e1, &e2, &e); + break; + case '/': + flt_str2flt(p->op2, &e2); + flt_div(&e1, &e2, &e); + break; + case 'D': + /* integer part of flt_modf */ + flt_modf(&e1, &e, &e2); + break; + case 'R': + /* fraction part of flt_modf */ + flt_modf(&e1, &e2, &e); + break; + case 'U': + /* unary minus */ + e = e1; + flt_umin(&e); + break; + default: + e = e1; + break; + } + flt_flt2str(&e, buf, 128); + + if (! strcmp(buf, p->result)) return 1; + + printf("Test number %d failed\n", testno); + return 0; +} -- 2.34.1