Skip to content

Commit

Permalink
!124 refine test3 for + -(liii base)
Browse files Browse the repository at this point in the history
  • Loading branch information
李炎城 authored and da-liii committed Jan 20, 2025
1 parent 2e76e3d commit 3610394
Show file tree
Hide file tree
Showing 2 changed files with 337 additions and 6 deletions.
236 changes: 232 additions & 4 deletions GoldfishScheme.tmu
Original file line number Diff line number Diff line change
Expand Up @@ -1911,27 +1911,255 @@

<value|r7rs><paragraph|+ -><index|+>

测试+ -函数两个参数的情况。整数,浮点数,分数,复数,无穷大,NaN。

<\scm-chunk|tests/goldfish/liii/base-test.scm|true|true>
(check (+ 1 2) =\<gtr\> 3)

(check (- 2 1) =\<gtr\> 1)

\;

(check (\<less\> (abs(- 3.3 (+ 1.1 2.2))) <code|1e-15>) =\<gtr\> #t)

(check (\<less\> (abs(- 1.08 (- 2.2 1.12))) <code|1e-15>) =\<gtr\> #t)

\;

(check (+ 1/3 1/2) =\<gtr\> 5/6)

(check (- 2/3 1/3) =\<gtr\> 1/3)

\;

(check (+ 1+i 2+2i) =\<gtr\> 3.0+3.0i)

(check (- 2+2i 1+i) =\<gtr\> 1.0+1.0i)

\;

(check (+ +inf.0 0.7) =\<gtr\> +inf.0)

(check (+ -inf.0 7) =\<gtr\> -inf.0)

(check (+ +inf.0 1+i) =\<gtr\> +inf.0+1.0i)

(check (- -inf.0 1) =\<gtr\> -inf.0)

(check (- +inf.0 1) =\<gtr\> +inf.0)

(check (- +inf.0 1+i) =\<gtr\> +inf.0-1.0i)

(check (- 1 +inf.0) =\<gtr\> -inf.0)

(check (- 1 -inf.0) =\<gtr\> +inf.0)

(check (- 1+i -inf.0) =\<gtr\> +inf.0+1.0i)

\;

(check (nan? (+ +nan.0 1)) =\<gtr\> #t)

(check (nan? (- +nan.0 0.5)) =\<gtr\> #t)

(check (nan? (+ +nan.0 1+i)) =\<gtr\> #t)
</scm-chunk>

测试+ -函数多个参数的情况。整数,浮点数,分数,复数,无穷大,NaN。

<\scm-chunk|tests/goldfish/liii/base-test.scm|true|true>
(check (+ 1 2 3) =\<gtr\> 6)

(check (- 7 2 1) =\<gtr\> 4)

\;

(check (\<less\> (abs(- 12.7 (+ 1.2 6.7 4.8))) <code|1e-15>) =\<gtr\> #t)

(check (\<less\> (abs(- 2.7 (- 6.98 2.5 1.78))) <code|1e-15>) =\<gtr\> #t)

\;

(check (+ 1/3 1/4 1/5) =\<gtr\> 47/60)

(check (- 1/2 1/5 1/7) =\<gtr\> 11/70)

\;

(check (+ 1+2i 2+3i 3+4i) =\<gtr\> 6.0+9.0i)

(check (- 3+4i 0+2i 1+i) =\<gtr\> 2.0+1.0i)

\;

(check (+ +inf.0 1 2) =\<gtr\> +inf.0)

(check (+ -inf.0 1 2) =\<gtr\> -inf.0)

(check (+ 1 2 -inf.0) =\<gtr\> -inf.0)

(check (- +inf.0 1 2) =\<gtr\> +inf.0)

(check (- -inf.0 1 2) =\<gtr\> -inf.0)

(check (- 1 2 -inf.0) =\<gtr\> +inf.0)

\;

(check (nan? (+ 1 2 +nan.0)) =\<gtr\> #t)

(check (nan? (- 1 2 -nan.0)) =\<gtr\> #t)
</scm-chunk>

测试+ - 混合参数的情况。整数,浮点数,分数,复数,无穷大,NaN的混合。

<\scm-chunk|tests/goldfish/liii/base-test.scm|true|true>
(check (\<less\> (abs(- 5.0 (+ 4 1.0))) <code|1e-15>) =\<gtr\> #t)

(check (+ 1 1/3) =\<gtr\> 4/3)

(check (\<less\> (abs(- 1.5 (+ 1.0 1/2))) <code|1e-15>) =\<gtr\> #t)

(check (\<less\> (abs(- 5.5 (+ 4 1.0 1/2))) <code|1e-15>) =\<gtr\> #t)

(check (+ 1+i 1) =\<gtr\> 2.0+1.0i)

(check (+ 1+i 1/2) =\<gtr\> 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 (\<less\> (abs(- 3.0 (- 4 1.0))) <code|1e-15>) =\<gtr\> #t)
</code>

(check (- 1 1/3) =\<gtr\> 2/3)

(check (\<less\> (abs(- 0.5 (- 1.0 1/2))) <code|1e-15>) =\<gtr\> #t)

(check (\<less\> (abs(- 2.5 (- 4 1.0 1/2))) <code|1e-15>) =\<gtr\> #t)

(check (- 2+i 1) =\<gtr\> 1.0+1.0i)

(check (- 1+i 1/2) =\<gtr\> 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)
</code>

\;

(check (+ 3.0 2 +inf.0) =\<gtr\> +inf.0)

(check (+ 1/3 2 -inf.0) =\<gtr\> -inf.0)

(check (+ 1+i +inf.0) =\<gtr\> +inf.0+1.0i)

(check (- +inf.0 1/3 2.0) =\<gtr\> +inf.0)

(check (- -inf.0 3 2.0) =\<gtr\> -inf.0)

(check (- 1/3 -inf.0 2.0 4) =\<gtr\> +inf.0)

(check (- 1+i +inf.0) =\<gtr\> -inf.0+1.0i)

(check (- 1+i -inf.0) =\<gtr\> +inf.0+1.0i)

\;

(check (nan? (+ 1 1.0 +nan.0)) =\<gtr\> #t)

(check (nan? (+ +inf.0 +nan.0)) =\<gtr\> #t)

(check (nan? (+ +inf.0 -inf.0 +nan.0)) =\<gtr\> #t)

(check (nan? (+ 1+i +nan.0)) =\<gtr\> #t)

(check (nan? (- 1 1.0 +nan.0)) =\<gtr\> #t)

(check (nan? (- +inf.0 +nan.0)) =\<gtr\> #t)

(check (nan? (- +inf.0 -inf.0 +nan.0)) =\<gtr\> #t)

(check (nan? (- 1+i +nan.0)) =\<gtr\> #t)
</scm-chunk>

测试+ -函数对于非规格化数,边界条件,接近机器精度的数的情况

<\scm-chunk|tests/goldfish/liii/base-test.scm|true|true>
(check (\<less\> (abs(- 1 (- 1 4.9e-324))) 1e-323) =\<gtr\> #t)

(check (\<less\> (abs(- 1 (+ 1 4.9e-324))) 1e-323) =\<gtr\> #t)

\;

(check <code|(+ 1.0e308 1.0e308) =\<gtr\> +inf.0)>

(check (+ -1.0e308 -1.0e308) =\<gtr\> -inf.0)

\;

(check (\<less\>= (abs (- (+ 1.0 1e-16) 1.0000000000000001)) 1e-15) =\<gtr\> #t)

(check (\<less\>= (abs (- (- 1.0 1e-16) 1.0000000000000001)) 1e-15) =\<gtr\> #t)
</scm-chunk>

测试+ -函数异常及错误情况。无实参,符号,字符串,布尔,列表,虚数

<\scm-chunk|tests/goldfish/liii/base-test.scm|true|true>
(check (+ ) =\<gtr\> 0)

(check (- 2 1) =\<gtr\> 1)
(check-catch 'wrong-number-of-args (- ))

\;

<\scm-chunk|tests/goldfish/liii/base-test.scm|true|false>
(check (- #x8000000000000000 1) =\<gtr\> #x7fffffffffffffff)
</scm-chunk>
(check-catch 'wrong-type-arg (+ 'hello 7))

(check-catch 'wrong-type-arg (- 'hello 7))

\;

(check-catch 'wrong-type-arg (+ "world" 7))

(check-catch 'wrong-type-arg (- "world" 7))

\;

(check-catch 'wrong-type-arg (+ #t 7))

(check-catch 'wrong-type-arg (+ #f 7))

(check-catch 'wrong-type-arg (- #t 7))

(check-catch 'wrong-type-arg (- #f 7))

\;

(check-catch 'wrong-type-arg (+ '(1 3 5) 7))

(check-catch 'wrong-type-arg (+ '() 7))

(check-catch 'wrong-type-arg (- '(1 3 5) 7))

(check-catch 'wrong-type-arg (- '() 7) )

\;

(check-catch 'unbound-variable (+ 1+i 2i))

(check-catch 'unbound-variable (- 1+i 2i))

\;
</scm-chunk>

\;

测试+ -运算溢出情况。

<\scm-chunk|tests/goldfish/liii/base-test.scm|true|true>
(check (+ #x7fffffffffffffff 1) =\<gtr\> #x8000000000000000)

(check (- #x8000000000000000 1) =\<gtr\> #x7fffffffffffffff)

\;
</scm-chunk>

Expand Down
107 changes: 105 additions & 2 deletions tests/goldfish/liii/base-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,115 @@
(check-catch 'type-error (min 1+2i 2))

(check (+ 1 2) => 3)
(check (+ ) => 0)
(check (- 2 1) => 1)

(check (- #x8000000000000000 1) => #x7fffffffffffffff)
(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-catch 'wrong-type-arg (+ 'hello 7))
(check-catch 'wrong-type-arg (- 'hello 7))

(check-catch 'wrong-type-arg (+ "world" 7))
(check-catch 'wrong-type-arg (- "world" 7))

(check-catch 'wrong-type-arg (+ #t 7))
(check-catch 'wrong-type-arg (+ #f 7))
(check-catch 'wrong-type-arg (- #t 7))
(check-catch 'wrong-type-arg (- #f 7))

(check-catch 'wrong-type-arg (+ '(1 3 5) 7))
(check-catch 'wrong-type-arg (+ '() 7))
(check-catch 'wrong-type-arg (- '(1 3 5) 7))
(check-catch 'wrong-type-arg (- '() 7) )

(check-catch 'unbound-variable (+ 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)
Expand Down

0 comments on commit 3610394

Please sign in to comment.