diff --git a/GoldfishScheme.tmu b/GoldfishScheme.tmu index ed7c5b6e8fbaa42f46a6d0cbd13be26c3019d4d2..531825bad4cd84e4f004efbd3db97a5e0bd03485 100644 --- a/GoldfishScheme.tmu +++ b/GoldfishScheme.tmu @@ -1,4 +1,4 @@ -> +> > @@ -442,7 +442,7 @@ <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> (check (if (\ 3 2) 3 2) =\ 3) - (check (if (\< 3 2) 3 2) =\> 2) + (check (if (\ 3 2) 3 2) =\ 2) \; @@ -452,7 +452,7 @@ 测试 if 语句的真、假分支,使用复杂表达式 <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> - (check (if (and (\> 3 1) (\< 3 4)) 'true-branch 'false-branch) =\> 'true-branch) + (check (if (and (\ 3 1) (\ 3 4)) 'true-branch 'false-branch) =\ 'true-branch) (check (if (or (\ 3 4) (\ 3 1)) 'true-branch 'false-branch) =\ 'false-branch) @@ -595,9 +595,75 @@ + 测试 when 中条件为真的情况 + + <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> + + \; + + (check (when #t 1) =\ 1) + + \; + > + + + \; + > + + + 测试 when 中条件为假的情况 + + <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> + + \; + + (check (when #f 1 ) =\ #\unspecified\) + + \; + > + + + \; + > + + + \; + + 测试when中添加简单条件为真的情况 + + <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> + + \; + + (check (when (\ 3 1) 1 ) =\ 1) + + \; + > + + + \; + > + + + 测试when中添加简单条件为假的情况 + + <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> + + \; + + (check (when (\ 1 3) 1 ) =\ #\unspecified\) + + \; + > + + + \; + > + + - + > @@ -1695,6 +1761,74 @@ + + + 测试 max 函数的基本功能 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + \; + + (check (max 1 2 3) =\ 3) + + (check (max 3 2 1) =\ 3) + + (check (max -1 -2 -3) =\ -1) + + (check (max 0 0 0) =\ 0) + + (check (max 1.5 2.5 3.5) =\ 3.5) + + (check (max 1/2 3/4 1/4) =\ 3/4) + + \; + + + 测试 max 函数在没有参数时的情况 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + (check-catch 'wrong-number-of-args (max)) + + \; + + + 测试 max 函数在参数类型不正确时的情况 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + \; + + (check-catch 'wrong-type-arg (max 1 "2" 3)) + + (check-catch 'wrong-type-arg (max 1 #\\a 3)) + + (check-catch 'wrong-type-arg (max 1 'symbol 3)) + + \; + + + 测试 max 函数在参数为布尔值时的情况 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + \; + + (check-catch 'wrong-type-arg (max #t #f)) + + (check-catch 'wrong-type-arg (max 1 #t 3)) + + \; + + + 测试 max 函数在参数为列表时的情况 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + \; + + (check-catch 'wrong-type-arg (max 1 '(2) 3)) + + (check-catch 'wrong-type-arg (max '(1 2 3) '(4 5 6))) + + \; + + string>string> string?> diff --git a/tests/goldfish/liii/base-test.scm b/tests/goldfish/liii/base-test.scm index c8a459759393eb55f79fd7b88a92c26730ff01d0..47ec85e340b5e3e80635ac2302c5bed3adc97cbc 100755 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -71,6 +71,22 @@ (check (and #t 1) => 1) + +(check (when #t 1) => 1) + + + +(check (when #f 1 ) => #) + + + +(check (when (> 3 1) 1 ) => 1) + + + +(check (when (> 1 3) 1 ) => #) + + (define (test-letrec) (letrec ((even? (lambda (n) @@ -332,6 +348,29 @@ (check (square 2) => 4) + +(check (max 1 2 3) => 3) +(check (max 3 2 1) => 3) +(check (max -1 -2 -3) => -1) +(check (max 0 0 0) => 0) +(check (max 1.5 2.5 3.5) => 3.5) +(check (max 1/2 3/4 1/4) => 3/4) + +(check-catch 'wrong-number-of-args (max)) + + +(check-catch 'wrong-type-arg (max 1 "2" 3)) +(check-catch 'wrong-type-arg (max 1 #\a 3)) +(check-catch 'wrong-type-arg (max 1 'symbol 3)) + + +(check-catch 'wrong-type-arg (max #t #f)) +(check-catch 'wrong-type-arg (max 1 #t 3)) + + +(check-catch 'wrong-type-arg (max 1 '(2) 3)) +(check-catch 'wrong-type-arg (max '(1 2 3) '(4 5 6))) + (check (number->string 123) => "123") (check (number->string -456) => "-456")