diff --git a/GoldfishScheme.tmu b/GoldfishScheme.tmu index a3676447943f9370d0a728bba9a9add5aa4a6f05..4407297936e1e8895069f6ddb9f89cbb41419a0f 100644 --- a/GoldfishScheme.tmu +++ b/GoldfishScheme.tmu @@ -1909,22 +1909,254 @@ \; - + + + 测试+ -函数两个参数的情况。整数,浮点数,分数,复数,无穷大,NaN。 <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> (check (+ 1 2) =\ 3) + (check (- 2 1) =\ 1) + + \; + + (check (\ (abs(- 3.3 (+ 1.1 2.2))) ) =\ #t) + + (check (\ (abs(- 1.08 (- 2.2 1.12))) ) =\ #t) + + \; + + (check (+ 1/3 1/2) =\ 5/6) + + (check (- 2/3 1/3) =\ 1/3) + + \; + + (check (+ 1+i 2+2i) =\ 3.0+3.0i) + + (check (- 2+2i 1+i) =\ 1.0+1.0i) + + \; + + (check (+ +inf.0 0.7) =\ +inf.0) + + (check (+ -inf.0 7) =\ -inf.0) + + (check (+ +inf.0 1+i) =\ +inf.0+1.0i) + + (check (- -inf.0 1) =\ -inf.0) + + (check (- +inf.0 1) =\ +inf.0) + + (check (- +inf.0 1+i) =\ +inf.0-1.0i) + + (check (- 1 +inf.0) =\ -inf.0) + + (check (- 1 -inf.0) =\ +inf.0) + + (check (- 1+i -inf.0) =\ +inf.0+1.0i) + + \; + + (check (nan? (+ +nan.0 1)) =\ #t) + + (check (nan? (- +nan.0 0.5)) =\ #t) + + (check (nan? (+ +nan.0 1+i)) =\ #t) + + + 测试+ -函数多个参数的情况。整数,浮点数,分数,复数,无穷大,NaN。 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + (check (+ 1 2 3) =\ 6) + + (check (- 7 2 1) =\ 4) + + \; + + (check (\ (abs(- 12.7 (+ 1.2 6.7 4.8))) ) =\ #t) + + (check (\ (abs(- 2.7 (- 6.98 2.5 1.78))) ) =\ #t) + + \; + + (check (+ 1/3 1/4 1/5) =\ 47/60) + + (check (- 1/2 1/5 1/7) =\ 11/70) + + \; + + (check (+ 1+2i 2+3i 3+4i) =\ 6.0+9.0i) + + (check (- 3+4i 0+2i 1+i) =\ 2.0+1.0i) + + \; + + (check (+ +inf.0 1 2) =\ +inf.0) + + (check (+ -inf.0 1 2) =\ -inf.0) + + (check (+ 1 2 -inf.0) =\ -inf.0) + + (check (- +inf.0 1 2) =\ +inf.0) + + (check (- -inf.0 1 2) =\ -inf.0) + + (check (- 1 2 -inf.0) =\ +inf.0) + + \; + + (check (nan? (+ 1 2 +nan.0)) =\ #t) + + (check (nan? (- 1 2 -nan.0)) =\ #t) + + + 测试+ - 混合参数的情况。整数,浮点数,分数,复数,无穷大,NaN的混合。 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + (check (\ (abs(- 5.0 (+ 4 1.0))) ) =\ #t) + + (check (+ 1 1/3) =\ 4/3) + + (check (\ (abs(- 1.5 (+ 1.0 1/2))) ) =\ #t) + + (check (\ (abs(- 5.5 (+ 4 1.0 1/2))) ) =\ #t) + + (check (+ 1+i 1) =\ 2.0+1.0i) + + (check (+ 1+i 1/2) =\ 1.5+1.0i) + + <\code> + (check (and (\< (abs (- (real-part (+ 1+1i 1.0)) 2.0)) 1e-10)(\< (abs (- (imag-part (+ 1+1i 1.0)) 1.0)) 1e-10))=\> #t) + + (check (\ (abs(- 3.0 (- 4 1.0))) ) =\ #t) + + + (check (- 1 1/3) =\ 2/3) + + (check (\ (abs(- 0.5 (- 1.0 1/2))) ) =\ #t) + + (check (\ (abs(- 2.5 (- 4 1.0 1/2))) ) =\ #t) + + (check (- 2+i 1) =\ 1.0+1.0i) + + (check (- 1+i 1/2) =\ 0.5+1.0i) + + <\code> + (check (and (\< (abs (- (real-part (- 2+1i 1+0.5i)) 1.0)) 1e-10)(\< (abs (- (imag-part (- 2+1i 1+0.5i)) 0.5)) 1e-10)) =\> #t) + + + \; + + (check (+ 3.0 2 +inf.0) =\ +inf.0) + + (check (+ 1/3 2 -inf.0) =\ -inf.0) + + (check (+ 1+i +inf.0) =\ +inf.0+1.0i) + + (check (- +inf.0 1/3 2.0) =\ +inf.0) + + (check (- -inf.0 3 2.0) =\ -inf.0) + + (check (- 1/3 -inf.0 2.0 4) =\ +inf.0) + + (check (- 1+i +inf.0) =\ -inf.0+1.0i) + + (check (- 1+i -inf.0) =\ +inf.0+1.0i) + + \; + + (check (nan? (+ 1 1.0 +nan.0)) =\ #t) + + (check (nan? (+ +inf.0 +nan.0)) =\ #t) + + (check (nan? (+ +inf.0 -inf.0 +nan.0)) =\ #t) + + (check (nan? (+ 1+i +nan.0)) =\ #t) + + (check (nan? (- 1 1.0 +nan.0)) =\ #t) + + (check (nan? (- +inf.0 +nan.0)) =\ #t) + + (check (nan? (- +inf.0 -inf.0 +nan.0)) =\ #t) + + (check (nan? (- 1+i +nan.0)) =\ #t) + + + 测试+ -函数对于非规格化数,边界条件,接近机器精度的数的情况 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + (check (\ (abs(- 1 (- 1 4.9e-324))) 1e-323) =\ #t) + + (check (\ (abs(- 1 (+ 1 4.9e-324))) 1e-323) =\ #t) + + \; + + (check +inf.0)> + + (check (+ -1.0e308 -1.0e308) =\ -inf.0) + + \; + + (check (\= (abs (- (+ 1.0 1e-16) 1.0000000000000001)) 1e-15) =\ #t) + + (check (\= (abs (- (- 1.0 1e-16) 1.0000000000000001)) 1e-15) =\ #t) + + + 测试+ -函数异常及错误情况。无实参,符号,字符串,布尔,列表,虚数 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> (check (+ ) =\ 0) + (check-catch 'wrong-number-of-args (- )) + + \; + + (check-catch type-error (+ 'hello 7)) + + (check-catch 'type-error (- 'hello 7)) + + \; + + (check-catch 'type-error (+ "world" 7)) + + (check-catch 'type-error (- "world" 7)) + + \; + + (check-catch 'type-error (+ #t 7)) + + (check-catch 'type-error (+ #f 7)) + + (check-catch 'type-error (- #t 7)) + + (check-catch 'type-error (- #f 7)) + + \; + + (check-catch 'type-error (+ '(1 3 5) 7)) + + (check-catch 'type-error (+ '() 7)) + + (check-catch 'type-error (- '(1 3 5) 7)) + + (check-catch 'type-error (- '() 7)) + + \; + + (check-catch 'type-error (+ 1+i 2i)) + + (check-catch unbound-variable (- 1+i 2i)) + \; - \; + 测试+ -运算溢出情况。 <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> (check (+ #x7fffffffffffffff 1) =\ #x8000000000000000) - \; + (check (- #x8000000000000000 1) =\ #x7fffffffffffffff) integer> diff --git a/tests/goldfish/liii/base-test.scm b/tests/goldfish/liii/base-test.scm index fa04def49245cfc67fef383e8e46e51b3cf6b37a..6b650921911754fe918477159baebdad64b41c4f 100755 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -407,10 +407,115 @@ (check-catch 'type-error (min 1+2i 2)) (check (+ 1 2) => 3) +(check (- 2 1) => 1) + +(check (< (abs(- 3.3 (+ 1.1 2.2))) 1e-15) => #t) +(check (< (abs(- 1.08 (- 2.2 1.12))) 1e-15) => #t) + +(check (+ 1/3 1/2) => 5/6) +(check (- 2/3 1/3) => 1/3) + +(check (+ 1+i 2+2i) => 3.0+3.0i) +(check (- 2+2i 1+i) => 1.0+1.0i) + +(check (+ +inf.0 0.7) => +inf.0) +(check (+ -inf.0 7) => -inf.0) +(check (+ +inf.0 1+i) => +inf.0+1.0i) +(check (- -inf.0 1) => -inf.0) +(check (- +inf.0 1) => +inf.0) +(check (- +inf.0 1+i) => +inf.0-1.0i) +(check (- 1 +inf.0) => -inf.0) +(check (- 1 -inf.0) => +inf.0) +(check (- 1+i -inf.0) => +inf.0+1.0i) + +(check (nan? (+ +nan.0 1)) => #t) +(check (nan? (- +nan.0 0.5)) => #t) +(check (nan? (+ +nan.0 1+i)) => #t) +(check (+ 1 2 3) => 6) +(check (- 7 2 1) => 4) + +(check (< (abs(- 12.7 (+ 1.2 6.7 4.8))) 1e-15) => #t) +(check (< (abs(- 2.7 (- 6.98 2.5 1.78))) 1e-15) => #t) + +(check (+ 1/3 1/4 1/5) => 47/60) +(check (- 1/2 1/5 1/7) => 11/70) + +(check (+ 1+2i 2+3i 3+4i) => 6.0+9.0i) +(check (- 3+4i 0+2i 1+i) => 2.0+1.0i) + +(check (+ +inf.0 1 2) => +inf.0) +(check (+ -inf.0 1 2) => -inf.0) +(check (+ 1 2 -inf.0) => -inf.0) +(check (- +inf.0 1 2) => +inf.0) +(check (- -inf.0 1 2) => -inf.0) +(check (- 1 2 -inf.0) => +inf.0) + +(check (nan? (+ 1 2 +nan.0)) => #t) +(check (nan? (- 1 2 -nan.0)) => #t) +(check (< (abs(- 5.0 (+ 4 1.0))) 1e-15) => #t) +(check (+ 1 1/3) => 4/3) +(check (< (abs(- 1.5 (+ 1.0 1/2))) 1e-15) => #t) +(check (< (abs(- 5.5 (+ 4 1.0 1/2))) 1e-15) => #t) +(check (+ 1+i 1) => 2.0+1.0i) +(check (+ 1+i 1/2) => 1.5+1.0i) +(check (and (< (abs (- (real-part (+ 1+1i 1.0)) 2.0)) 1e-10)(< (abs (- (imag-part (+ 1+1i 1.0)) 1.0)) 1e-10))=> #t) +(check (< (abs(- 3.0 (- 4 1.0))) 1e-15) => #t) +(check (- 1 1/3) => 2/3) +(check (< (abs(- 0.5 (- 1.0 1/2))) 1e-15) => #t) +(check (< (abs(- 2.5 (- 4 1.0 1/2))) 1e-15) => #t) +(check (- 2+i 1) => 1.0+1.0i) +(check (- 1+i 1/2) => 0.5+1.0i) +(check (and (< (abs (- (real-part (- 2+1i 1+0.5i)) 1.0)) 1e-10)(< (abs (- (imag-part (- 2+1i 1+0.5i)) 0.5)) 1e-10)) => #t) + +(check (+ 3.0 2 +inf.0) => +inf.0) +(check (+ 1/3 2 -inf.0) => -inf.0) +(check (+ 1+i +inf.0) => +inf.0+1.0i) +(check (- +inf.0 1/3 2.0) => +inf.0) +(check (- -inf.0 3 2.0) => -inf.0) +(check (- 1/3 -inf.0 2.0 4) => +inf.0) +(check (- 1+i +inf.0) => -inf.0+1.0i) +(check (- 1+i -inf.0) => +inf.0+1.0i) + +(check (nan? (+ 1 1.0 +nan.0)) => #t) +(check (nan? (+ +inf.0 +nan.0)) => #t) +(check (nan? (+ +inf.0 -inf.0 +nan.0)) => #t) +(check (nan? (+ 1+i +nan.0)) => #t) +(check (nan? (- 1 1.0 +nan.0)) => #t) +(check (nan? (- +inf.0 +nan.0)) => #t) +(check (nan? (- +inf.0 -inf.0 +nan.0)) => #t) +(check (nan? (- 1+i +nan.0)) => #t) +(check (< (abs(- 1 (- 1 4.9e-324))) 1e-323) => #t) +(check (< (abs(- 1 (+ 1 4.9e-324))) 1e-323) => #t) + +(check (+ 1.0e308 1.0e308) => +inf.0) +(check (+ -1.0e308 -1.0e308) => -inf.0) + +(check (<= (abs (- (+ 1.0 1e-16) 1.0000000000000001)) 1e-15) => #t) +(check (<= (abs (- (- 1.0 1e-16) 1.0000000000000001)) 1e-15) => #t) (check (+ ) => 0) +(check-catch 'wrong-number-of-args (- )) -(check (+ #x7fffffffffffffff 1) => #x8000000000000000) +(check-catch type-error (+ 'hello 7)) +(check-catch 'type-error (- 'hello 7)) + +(check-catch 'type-error (+ "world" 7)) +(check-catch 'type-error (- "world" 7)) + +(check-catch 'type-error (+ #t 7)) +(check-catch 'type-error (+ #f 7)) +(check-catch 'type-error (- #t 7)) +(check-catch 'type-error (- #f 7)) +(check-catch 'type-error (+ '(1 3 5) 7)) +(check-catch 'type-error (+ '() 7)) +(check-catch 'type-error (- '(1 3 5) 7)) +(check-catch 'type-error (- '() 7)) + +(check-catch 'type-error (+ 1+i 2i)) +(check-catch unbound-variable (- 1+i 2i)) + +(check (+ #x7fffffffffffffff 1) => #x8000000000000000) +(check (- #x8000000000000000 1) => #x7fffffffffffffff) (check (floor 1.1) => 1.0) (check (floor 1) => 1) (check (floor 1/2) => 0)