Added test program
This commit is contained in:
parent
df975bc075
commit
24a8b613ae
|
@ -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)
|
||||
|
|
84
modules/src/flt_arith/test.c
Normal file
84
modules/src/flt_arith/test.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Reference in a new issue