[pure-lang-svn] SF.net SVN: pure-lang:[587] pure/trunk/test
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-23 22:10:06
|
Revision: 587 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=587&view=rev Author: agraef Date: 2008-08-23 22:10:16 +0000 (Sat, 23 Aug 2008) Log Message: ----------- Add math.pure exact/inexact/symbolic tests. Added Paths: ----------- pure/trunk/test/test021.log pure/trunk/test/test021.pure Added: pure/trunk/test/test021.log =================================================================== --- pure/trunk/test/test021.log (rev 0) +++ pure/trunk/test/test021.log 2008-08-23 22:10:16 UTC (rev 587) @@ -0,0 +1,295 @@ +let double_format = "%#0.3g"; +test (f/*0:101*/,x/*0:1101*/,y/*0:111*/) = puts$format (f/*0:101*/,x/*0:1101*/,y/*0:111*/,check (f/*0:101*/,x/*0:1101*/,y/*0:111*/) (catch __error__ (f/*1:101*/ x/*1:1101*/ y/*1:111*/))); +test (f/*0:101*/,x/*0:11*/) = puts$format (f/*0:101*/,x/*0:11*/,check (f/*0:101*/,x/*0:11*/) (catch __error__ (f/*1:101*/ x/*1:11*/))); +check _/*0:01*/ z/*0:1*/ = z/*0:1*/ if numberp z/*0:1*/; +check (f/*0:0101*/,_/*0:011*/) (g@_/*0:100*/ _/*0:101*/ _/*0:11*/) = __failed__ if f/*0:0101*/===g/*0:100*/; +check (f/*0:0101*/,_/*0:011*/) (g@_/*0:10*/ _/*0:11*/) = __failed__ if f/*0:0101*/===g/*0:10*/; +check _/*0:01*/ z/*0:1*/ = z/*0:1*/; +format (f/*0:101*/,x/*0:1101*/,y/*0:11101*/,z/*0:1111*/) = str f/*0:101*/+","+show x/*0:1101*/+","+show y/*0:11101*/+","+show z/*0:1111*/; +format (f/*0:101*/,x/*0:1101*/,z/*0:111*/) = str f/*0:101*/+","+show x/*0:1101*/+","+show z/*0:111*/; +show x/*0:1*/::double = sprintf double_format x/*0:1*/; +show (x/*0:101*/+:y/*0:11*/) = show x/*0:101*/+"+:"+show y/*0:11*/; +show (x/*0:101*/<:y/*0:11*/) = show x/*0:101*/+"<:"+show y/*0:11*/; +show x/*0:1*/ = str x/*0:1*/; +{ + rule #0: check _ z = z if numberp z + rule #1: check (f,_) (g@_ _ _) = __failed__ if f===g + rule #2: check (f,_) (g@_ _) = __failed__ if f===g + rule #3: check _ z = z + state 0: #0 #1 #2 #3 + <var> state 1 + <app> state 3 + state 1: #0 #3 + <var> state 2 + state 2: #0 #3 + state 3: #0 #1 #2 #3 + <var> state 4 + <app> state 7 + state 4: #0 #3 + <var> state 5 + state 5: #0 #3 + <var> state 6 + state 6: #0 #3 + state 7: #0 #1 #2 #3 + <var> state 8 + , state 12 + state 8: #0 #3 + <var> state 9 + state 9: #0 #3 + <var> state 10 + state 10: #0 #3 + <var> state 11 + state 11: #0 #3 + state 12: #0 #1 #2 #3 + <var> state 13 + state 13: #0 #1 #2 #3 + <var> state 14 + state 14: #0 #1 #2 #3 + <var> state 15 + <app> state 16 + state 15: #0 #3 + state 16: #0 #1 #2 #3 + <var> state 17 + <app> state 19 + state 17: #0 #2 #3 + <var> state 18 + state 18: #0 #2 #3 + state 19: #0 #1 #2 #3 + <var> state 20 + state 20: #0 #1 #2 #3 + <var> state 21 + state 21: #0 #1 #2 #3 + <var> state 22 + state 22: #0 #1 #2 #3 +} +{ + rule #0: format (f,x,y,z) = str f+","+show x+","+show y+","+show z + rule #1: format (f,x,z) = str f+","+show x+","+show z + state 0: #0 #1 + <app> state 1 + state 1: #0 #1 + <app> state 2 + state 2: #0 #1 + , state 3 + state 3: #0 #1 + <var> state 4 + state 4: #0 #1 + <app> state 5 + state 5: #0 #1 + <app> state 6 + state 6: #0 #1 + , state 7 + state 7: #0 #1 + <var> state 8 + state 8: #0 #1 + <var> state 9 + <app> state 10 + state 9: #1 + state 10: #0 #1 + <var> state 11 + <app> state 13 + state 11: #1 + <var> state 12 + state 12: #1 + state 13: #0 #1 + <var> state 14 + , state 17 + state 14: #1 + <var> state 15 + state 15: #1 + <var> state 16 + state 16: #1 + state 17: #0 #1 + <var> state 18 + state 18: #0 #1 + <var> state 19 + state 19: #0 #1 +} +{ + rule #0: test (f,x,y) = puts$format (f,x,y,check (f,x,y) (catch __error__ (f x y))) + rule #1: test (f,x) = puts$format (f,x,check (f,x) (catch __error__ (f x))) + state 0: #0 #1 + <app> state 1 + state 1: #0 #1 + <app> state 2 + state 2: #0 #1 + , state 3 + state 3: #0 #1 + <var> state 4 + state 4: #0 #1 + <var> state 5 + <app> state 6 + state 5: #1 + state 6: #0 #1 + <var> state 7 + <app> state 9 + state 7: #1 + <var> state 8 + state 8: #1 + state 9: #0 #1 + <var> state 10 + , state 13 + state 10: #1 + <var> state 11 + state 11: #1 + <var> state 12 + state 12: #1 + state 13: #0 #1 + <var> state 14 + state 14: #0 #1 + <var> state 15 + state 15: #0 #1 +} +{ + rule #0: show x::double = sprintf double_format x + rule #1: show (x+:y) = show x+"+:"+show y + rule #2: show (x<:y) = show x+"<:"+show y + rule #3: show x = str x + state 0: #0 #1 #2 #3 + <var> state 1 + <var>::double state 2 + <app> state 3 + state 1: #3 + state 2: #0 #3 + state 3: #1 #2 #3 + <var> state 4 + <app> state 6 + state 4: #3 + <var> state 5 + state 5: #3 + state 6: #1 #2 #3 + <var> state 7 + +: state 10 + <: state 13 + state 7: #3 + <var> state 8 + state 8: #3 + <var> state 9 + state 9: #3 + state 10: #1 #3 + <var> state 11 + state 11: #1 #3 + <var> state 12 + state 12: #1 #3 + state 13: #2 #3 + <var> state 14 + state 14: #2 #3 + <var> state 15 + state 15: #2 #3 +} +*** EXACT/INEXACT *** +(+),2,2+:3,4+:3 +(+),2,2<:3,0.0200+:0.282 +(+),2,2L%3L,8L%3L +(-),2,2+:3,0+:-3 +(-),2,2<:3,3.98+:-0.282 +(-),2,2L%3L,4L%3L +(*),2,2+:3,4+:6 +(*),2,2<:3,4<:3 +(*),2,2L%3L,4L%3L +(%),2,2+:3,4L%13L+:(-6L)%13L +(%),2,2<:3,1L%1L<:-3 +(%),2,2L%3L,3L%1L +(/),2,2+:3,0.308+:-0.462 +(/),2,2<:3,1.00<:-3 +(/),2,2L%3L,3.00 +(^),2,2+:3,-1.95+:3.49 +(^),2,2<:3,0.253<:0.196 +(^),2,2L%3L,1.59 +(+),2+:3,2,4+:3 +(+),2<:3,2,0.0200+:0.282 +(+),2L%3L,2,8L%3L +(-),2+:3,2,0+:3 +(-),2<:3,2,-3.98+:0.282 +(-),2L%3L,2,(-4L)%3L +(*),2+:3,2,4+:6 +(*),2<:3,2,4<:3 +(*),2L%3L,2,4L%3L +(%),2+:3,2,1L%1L+:3L%2L +(%),2<:3,2,1L%1L<:3 +(%),2L%3L,2,1L%3L +(/),2+:3,2,1.00+:1.50 +(/),2<:3,2,1.00<:3 +(/),2L%3L,2,0.333 +(^),2+:3,2,-5.00+:12.0 +(^),2<:3,2,4.00<:-0.283 +(^),2L%3L,2,0.444 +*** SYMBOLIC *** +(+),x,2+:3,__failed__ +(+),x,2<:3,__failed__ +(+),x,2L%3L,__failed__ +(-),x,2+:3,__failed__ +(-),x,2<:3,__failed__ +(-),x,2L%3L,__failed__ +(*),x,2+:3,__failed__ +(*),x,2<:3,__failed__ +(*),x,2L%3L,__failed__ +(%),x,2+:3,__failed__ +(%),x,2<:3,__failed__ +(%),x,2L%3L,__failed__ +(/),x,2+:3,__failed__ +(/),x,2<:3,__failed__ +(/),x,2L%3L,__failed__ +(^),x,2+:3,__failed__ +(^),x,2<:3,__failed__ +(^),x,2L%3L,__failed__ +(+),2+:3,x,__failed__ +(+),2<:3,x,__failed__ +(+),2L%3L,x,__failed__ +(-),2+:3,x,__failed__ +(-),2<:3,x,__failed__ +(-),2L%3L,x,__failed__ +(*),2+:3,x,__failed__ +(*),2<:3,x,__failed__ +(*),2L%3L,x,__failed__ +(%),2+:3,x,__failed__ +(%),2<:3,x,__failed__ +(%),2L%3L,x,__failed__ +(/),2+:3,x,__failed__ +(/),2<:3,x,__failed__ +(/),2L%3L,x,__failed__ +(^),2+:3,x,__failed__ +(^),2<:3,x,__failed__ +(^),2L%3L,x,__failed__ +puts "*** EXACT/INEXACT ***"$$do test (catmap (\op/*0:*/ -> catmap (\a/*0:*/ -> [(op/*1:*/,2,a/*0:*/)] { + rule #0: a = [(op,2,a)] + state 0: #0 + <var> state 1 + state 1: #0 +}) [2+:3,2<:3,2%3] { + rule #0: op = catmap (\a -> [(op,2,a)]) [2+:3,2<:3,2%3] + state 0: #0 + <var> state 1 + state 1: #0 +}) [(+),(-),(*),(%),(/),(^)])$$do test (catmap (\op/*0:*/ -> catmap (\a/*0:*/ -> [(op/*1:*/,a/*0:*/,2)] { + rule #0: a = [(op,a,2)] + state 0: #0 + <var> state 1 + state 1: #0 +}) [2+:3,2<:3,2%3] { + rule #0: op = catmap (\a -> [(op,a,2)]) [2+:3,2<:3,2%3] + state 0: #0 + <var> state 1 + state 1: #0 +}) [(+),(-),(*),(%),(/),(^)])$$puts "*** SYMBOLIC ***"$$do test (catmap (\op/*0:*/ -> catmap (\a/*0:*/ -> [(op/*1:*/,x,a/*0:*/)] { + rule #0: a = [(op,x,a)] + state 0: #0 + <var> state 1 + state 1: #0 +}) [2+:3,2<:3,2%3] { + rule #0: op = catmap (\a -> [(op,x,a)]) [2+:3,2<:3,2%3] + state 0: #0 + <var> state 1 + state 1: #0 +}) [(+),(-),(*),(%),(/),(^)])$$do test (catmap (\op/*0:*/ -> catmap (\a/*0:*/ -> [(op/*1:*/,a/*0:*/,x)] { + rule #0: a = [(op,a,x)] + state 0: #0 + <var> state 1 + state 1: #0 +}) [2+:3,2<:3,2%3] { + rule #0: op = catmap (\a -> [(op,a,x)]) [2+:3,2<:3,2%3] + state 0: #0 + <var> state 1 + state 1: #0 +}) [(+),(-),(*),(%),(/),(^)]); +() Added: pure/trunk/test/test021.pure =================================================================== --- pure/trunk/test/test021.pure (rev 0) +++ pure/trunk/test/test021.pure 2008-08-23 22:10:16 UTC (rev 587) @@ -0,0 +1,37 @@ +// math.pure tests for exact/inexact and symbolic results + +using math, system; + +/* This will print out each operation, arguments and result as a single + line. Exceptions are flagged with '__error__', evaluation failures with + '__failed__'. Floating point values are rounded in the output to 3 + significant digits by default, to prevent 'make check' from failing due to + rounding discrepancies. */ + +let double_format = "%#0.3g"; // modify as needed, to get more accuracy + +test (f,x,y) = puts $ format (f,x,y,check (f,x,y) (catch __error__ (f x y))); +test (f,x) = puts $ format (f,x,check (f,x) (catch __error__ (f x))); + +check _ z = z if numberp z; +check (f,_) (g@_ _ _) | +check (f,_) (g@_ _) = __failed__ if f===g; +check _ z = z otherwise; + +format (f,x,y,z) = str f+","+show x+","+show y+","+show z; +format (f,x,z) = str f+","+show x+","+show z; + +show x::double = sprintf double_format x; +show (x+:y) = show x+"+:"+show y; +show (x<:y) = show x+"<:"+show y; +show x = str x otherwise; + +puts "*** EXACT/INEXACT ***" $$ +// These should all return exact results, except +/- with polar operands, as +// well as / and ^ which always return inexact results. +do test [op,2,a;op=[(+),(-),(*),(%),(/),(^)];a=[2+:3,2<:3,2%3]] $$ +do test [op,a,2;op=[(+),(-),(*),(%),(/),(^)];a=[2+:3,2<:3,2%3]] $$ +puts "*** SYMBOLIC ***" $$ +// If everything is all right here, these should all print __failed__. +do test [op,x,a;op=[(+),(-),(*),(%),(/),(^)];a=[2+:3,2<:3,2%3]] $$ +do test [op,a,x;op=[(+),(-),(*),(%),(/),(^)];a=[2+:3,2<:3,2%3]]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |