mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
Add tests for swapping vars and triangle area.
Triangle area was meant just to check Kahan's equation, but it found a problem with swapping vars. swap.r currently fails.
This commit is contained in:
parent
0f279cd3f0
commit
f250065003
4 changed files with 65 additions and 2 deletions
|
@ -32,6 +32,8 @@ test_progs_dat=\
|
|||
state.dat \
|
||||
structlive.dat \
|
||||
structptr.dat \
|
||||
swap.dat \
|
||||
triangle.dat \
|
||||
vecinit.dat \
|
||||
while.dat \
|
||||
voidfor.dat
|
||||
|
@ -139,6 +141,20 @@ structptr.dat$(EXEEXT): $(structptr_obj) $(QFCC_DEP)
|
|||
structptr.run: Makefile build-run
|
||||
$(srcdir)/build-run $@
|
||||
|
||||
swap_dat_SOURCES=swap.r
|
||||
swap_obj=$(swap_dat_SOURCES:.r=.qfo)
|
||||
swap.dat$(EXEEXT): $(swap_obj) $(QFCC_DEP)
|
||||
$(QFCC) $(QCFLAGS) -o $@ $(swap_obj)
|
||||
swap.run: Makefile build-run
|
||||
$(srcdir)/build-run $@
|
||||
|
||||
triangle_dat_SOURCES=triangle.r
|
||||
triangle_obj=$(triangle_dat_SOURCES:.r=.qfo)
|
||||
triangle.dat$(EXEEXT): $(triangle_obj) $(QFCC_DEP)
|
||||
$(QFCC) $(QCFLAGS) -o $@ $(triangle_obj)
|
||||
triangle.run: Makefile build-run
|
||||
$(srcdir)/build-run $@ 1 2 3
|
||||
|
||||
vecinit_dat_SOURCES=vecinit.r
|
||||
vecinit_obj=$(vecinit_dat_SOURCES:.r=.qfo)
|
||||
vecinit.dat$(EXEEXT): $(vecinit_obj) $(QFCC_DEP)
|
||||
|
@ -163,4 +179,4 @@ voidfor.run: Makefile build-run
|
|||
include ./$(DEPDIR)/*.Qo
|
||||
|
||||
EXTRA_DIST= test-bi.h build-run
|
||||
CLEANFILES= *.dat *.sym *.qfo *.run
|
||||
CLEANFILES= *.dat *.sym *.qfo *.run *.frame
|
||||
|
|
|
@ -6,6 +6,6 @@ shift
|
|||
|
||||
cat > $script <<EOF
|
||||
#! /bin/sh
|
||||
./test-harness $TEST_HARNESS_OPTS $progs "\$@"
|
||||
./test-harness $TEST_HARNESS_OPTS $progs $@
|
||||
EOF
|
||||
chmod +x $script
|
||||
|
|
15
tools/qfcc/test/swap.r
Normal file
15
tools/qfcc/test/swap.r
Normal file
|
@ -0,0 +1,15 @@
|
|||
void printf (string fmt, ...) = #0;
|
||||
|
||||
float
|
||||
swap (float a, float b)
|
||||
{
|
||||
float t;
|
||||
if (a < b) { t = a; a = b; b = t; }
|
||||
return a - b;
|
||||
}
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return swap (1, 2) > 0 ? 0 : 1;
|
||||
}
|
32
tools/qfcc/test/triangle.r
Normal file
32
tools/qfcc/test/triangle.r
Normal file
|
@ -0,0 +1,32 @@
|
|||
void printf (string fmt, ...) = #0;
|
||||
float (string s) stof = #0;
|
||||
float (float x) sqrt = #0;
|
||||
|
||||
float
|
||||
heron (float a, float b, float c)
|
||||
{
|
||||
float s = (a + b + c) / 2;
|
||||
return sqrt (s*(s-a)*(s-b)*(s-c));
|
||||
}
|
||||
|
||||
float
|
||||
kahan (float a, float b, float c)
|
||||
{
|
||||
float t;
|
||||
if (a < b) { t = a; a = b; b = t; }
|
||||
if (b < c) { t = b; b = c; c = t; }
|
||||
if (a < b) { t = a; a = b; b = t; }
|
||||
printf ("%f %f %f\n", a, b, c);
|
||||
return sqrt ((a+(b+c))*(c-(a-b))*(c+(a-b))*(a+(b-c)))/4;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, string *argv)
|
||||
{
|
||||
float a = stof(argv[1]);
|
||||
float b = stof(argv[2]);
|
||||
float c = stof(argv[3]);
|
||||
printf ("%.9g %.9g %.9g\n", a, b, c);
|
||||
printf ("%.9g %.9g\n", heron (a, b, c), kahan (a, b, c));
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue