From b155b003c37d46c6e3aed263d9bf0c3138eeb18b Mon Sep 17 00:00:00 2001 From: xiaoyvhuv Date: Thu, 2 Jan 2025 17:41:05 +0800 Subject: [PATCH 1/7] =?UTF-8?q?when=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GoldfishScheme.tmu | 40 ++++++++++++++++++++++++++++++- tests/goldfish/liii/base-test.scm | 4 ++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/GoldfishScheme.tmu b/GoldfishScheme.tmu index ed7c5b6e..13a82535 100644 --- a/GoldfishScheme.tmu +++ b/GoldfishScheme.tmu @@ -1,4 +1,4 @@ -> +> > @@ -595,6 +595,44 @@ + 测试 when 在条件为真时执行所有表达式 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + (check (let ((result (when (\ 3 2) "条件为真" (+ 1 2)))) result) =\ 3)\ + + \; + + + \; + + 测试 when 语句在条件为假时不执行任何表达式 + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + (check (let ((result (when (\ 3 2) "条件为假" (+ 1 2)))) result) =\ #f)\ + + \; + + + \; + + 测试 when 语句返回未指定值 ,当条件为假时\ + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + (check (let ((result (when #f "条件为假" (+ 1 2)))) (eq? result (void))) =\ #t) + + \; + + + 测试 when 语句只在条件为真时执行多个表达式并返回最后一个表达式的值\ + + <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> + (check (let ((result (when (\ 4 3) "条件为真" (+ 1 2) (* 2 2)))) result) =\ 4) + + \; + + + \; + diff --git a/tests/goldfish/liii/base-test.scm b/tests/goldfish/liii/base-test.scm index c8a45975..5e3816cc 100755 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -19,6 +19,10 @@ (liii list)) (check-set-mode! 'report-failed) +(check (let ((result (when (> 3 2) "条件为真" (+ 1 2)))) result) => 3) +(check (let ((result (when (< 3 2) "条件为假" (+ 1 2)))) result) => #f) +(check (let ((result (when #f "条件为假" (+ 1 2)))) (eq? result (void))) => #t) +(check (let ((result (when (> 4 3) "条件为真" (+ 1 2) (* 2 2)))) result) => 4) (check (if (> 3 2) 3 2) => 3) (check (if (< 3 2) 3 2) => 2) -- Gitee From e549597a74e93b5582f896a647903a8b544f3c93 Mon Sep 17 00:00:00 2001 From: xiaoyvhuv Date: Thu, 2 Jan 2025 18:47:01 +0800 Subject: [PATCH 2/7] =?UTF-8?q?when=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GoldfishScheme.tmu | 10 +++------- tests/goldfish/liii/base-test.scm | 11 +++++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/GoldfishScheme.tmu b/GoldfishScheme.tmu index 13a82535..57b86679 100644 --- a/GoldfishScheme.tmu +++ b/GoldfishScheme.tmu @@ -597,13 +597,9 @@ 测试 when 在条件为真时执行所有表达式 - <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> - (check (let ((result (when (\ 3 2) "条件为真" (+ 1 2)))) result) =\ 3)\ - - \; - - - \; + <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> + (check (let ((result (when (\ 3 2) "条件为真" (+ 1 2)))) result) =\ 3) + 测试 when 语句在条件为假时不执行任何表达式 diff --git a/tests/goldfish/liii/base-test.scm b/tests/goldfish/liii/base-test.scm index 5e3816cc..d3d6ca47 100755 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -19,10 +19,6 @@ (liii list)) (check-set-mode! 'report-failed) -(check (let ((result (when (> 3 2) "条件为真" (+ 1 2)))) result) => 3) -(check (let ((result (when (< 3 2) "条件为假" (+ 1 2)))) result) => #f) -(check (let ((result (when #f "条件为假" (+ 1 2)))) (eq? result (void))) => #t) -(check (let ((result (when (> 4 3) "条件为真" (+ 1 2) (* 2 2)))) result) => 4) (check (if (> 3 2) 3 2) => 3) (check (if (< 3 2) 3 2) => 2) @@ -75,6 +71,13 @@ (check (and #t 1) => 1) +(check (let ((result (when (> 3 2) "条件为真" (+ 1 2)))) result) => 3) +(check (let ((result (when (< 3 2) "条件为假" (+ 1 2)))) result) => #f) + +(check (let ((result (when #f "条件为假" (+ 1 2)))) (eq? result (void))) => #t) + +(check (let ((result (when (> 4 3) "条件为真" (+ 1 2) (* 2 2)))) result) => 4) + (define (test-letrec) (letrec ((even? (lambda (n) -- Gitee From 16f4a976aae51f64760a14fc27a9ab5d2f176227 Mon Sep 17 00:00:00 2001 From: xiaoyvhuv Date: Thu, 2 Jan 2025 19:58:59 +0800 Subject: [PATCH 3/7] =?UTF-8?q?when=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GoldfishScheme.tmu | 22 ++++++++++------------ tests/goldfish/liii/base-test.scm | 8 ++++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/GoldfishScheme.tmu b/GoldfishScheme.tmu index 57b86679..fc0efd45 100644 --- a/GoldfishScheme.tmu +++ b/GoldfishScheme.tmu @@ -598,23 +598,21 @@ 测试 when 在条件为真时执行所有表达式 <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> - (check (let ((result (when (\ 3 2) "条件为真" (+ 1 2)))) result) =\ 3) + (check (when (\ 3 2) "条件为真" (+ 1 2)) =\ 3) + + + \; + > 测试 when 语句在条件为假时不执行任何表达式 <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> - (check (let ((result (when (\ 3 2) "条件为假" (+ 1 2)))) result) =\ #f)\ - - \; - + + (check >> (when (\ 2 3) "条件为假" \ (set! res #t)) res =\ #f ) - \; - - 测试 when 语句返回未指定值 ,当条件为假时\ - - <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> - (check (let ((result (when #f "条件为假" (+ 1 2)))) (eq? result (void))) =\ #t) + \; + >> \; @@ -622,7 +620,7 @@ 测试 when 语句只在条件为真时执行多个表达式并返回最后一个表达式的值\ <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> - (check (let ((result (when (\ 4 3) "条件为真" (+ 1 2) (* 2 2)))) result) =\ 4) + (check (when (\ 4 3) "条件为真" (+ 1 2) (* 2 2))=\4) \; diff --git a/tests/goldfish/liii/base-test.scm b/tests/goldfish/liii/base-test.scm index d3d6ca47..c61a2ebb 100755 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -71,12 +71,12 @@ (check (and #t 1) => 1) -(check (let ((result (when (> 3 2) "条件为真" (+ 1 2)))) result) => 3) -(check (let ((result (when (< 3 2) "条件为假" (+ 1 2)))) result) => #f) +(check (when (> 3 2) "条件为真" (+ 1 2)) => 3) -(check (let ((result (when #f "条件为假" (+ 1 2)))) (eq? result (void))) => #t) +(check (define res #f) (when (> 2 3) "条件为假" (set! res #t)) res => #f ) -(check (let ((result (when (> 4 3) "条件为真" (+ 1 2) (* 2 2)))) result) => 4) + +(check (when (> 4 3) "条件为真" (+ 1 2) (* 2 2))=>4) (define (test-letrec) (letrec ((even? -- Gitee From 8cb1d9299b92c75f62f714a2e92acdd20a05b5eb Mon Sep 17 00:00:00 2001 From: xiaoyvhuv Date: Thu, 2 Jan 2025 20:44:20 +0800 Subject: [PATCH 4/7] =?UTF-8?q?when=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GoldfishScheme.tmu | 76 +++++++++++++++++++++++-------- tests/goldfish/liii/base-test.scm | 31 +++++++++++-- 2 files changed, 83 insertions(+), 24 deletions(-) diff --git a/GoldfishScheme.tmu b/GoldfishScheme.tmu index fc0efd45..a97cf88e 100644 --- a/GoldfishScheme.tmu +++ b/GoldfishScheme.tmu @@ -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,37 +595,73 @@ - 测试 when 在条件为真时执行所有表达式 + 测试 when 在条件为真,假时的执行情况 <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> - (check (when (\ 3 2) "条件为真" (+ 1 2)) =\ 3) + + ; 测试 when 中条件为真的情况 - \; - > - - 测试 when 语句在条件为假时不执行任何表达式 + \; - <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> - - (check >> (when (\ 2 3) "条件为假" \ (set! res #t)) res =\ #f ) + (check (let ((result #f)) \; - >> - \; - + \ \ \ \ \ \ \ \ \ - 测试 when 语句只在条件为真时执行多个表达式并返回最后一个表达式的值\ + (when (and (\ 3 1) (\ 3 4))\ - <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> - (check (when (\ 4 3) "条件为真" (+ 1 2) (* 2 2))=\4) + \; - \; - + \ \ \ \ \ \ \ \ \ \ \ - \; + (set! result 'true-branch)) + + \; + + \ \ \ \ \ \ \ \ \ result + + ) =\ 'true-branch) + + \; + + \; + + \; + + ; 测试 when 中条件为假的情况,此时应该返回初始设定的值(这里是 #f) + + \; + + \; + + (check (let ((result #f)) + + \; + + \ \ \ \ \ \ \ \ \ + + (when (or (\ 3 4) (\3 1)) + + \; + + \ \ \ \ \ \ \ \ \ \ \ + + (set! result 'false-branch)) + + \; + + \ \ \ \ \ \ \ \ \ result + + ) =\ #f) + > + + + \; + > + diff --git a/tests/goldfish/liii/base-test.scm b/tests/goldfish/liii/base-test.scm index c61a2ebb..9d74c5ed 100755 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -23,7 +23,7 @@ (check (if (> 3 2) 3 2) => 3) (check (if (< 3 2) 3 2) => 2) -(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) (check (case '+ @@ -71,12 +71,35 @@ (check (and #t 1) => 1) -(check (when (> 3 2) "条件为真" (+ 1 2)) => 3) +; 测试 when 中条件为真的情况 -(check (define res #f) (when (> 2 3) "条件为假" (set! res #t)) res => #f ) +(check (let ((result #f)) -(check (when (> 4 3) "条件为真" (+ 1 2) (* 2 2))=>4) + +(when (and (> 3 1) (< 3 4)) + + +(set! result 'true-branch)) + + result +) => 'true-branch) + + + +; 测试 when 中条件为假的情况,此时应该返回初始设定的值(这里是 #f) + + +(check (let ((result #f)) + + +(when (or (> 3 4) (<3 1)) + + +(set! result 'false-branch)) + + result +) => #f) (define (test-letrec) (letrec ((even? -- Gitee From 576440369fc46dd75da0c3c6ab4c88c5bed30419 Mon Sep 17 00:00:00 2001 From: xiaoyvhuv Date: Thu, 2 Jan 2025 22:06:39 +0800 Subject: [PATCH 5/7] =?UTF-8?q?when=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GoldfishScheme.tmu | 62 +++++++++++++++---------------- tests/goldfish/liii/base-test.scm | 24 +++--------- 2 files changed, 35 insertions(+), 51 deletions(-) diff --git a/GoldfishScheme.tmu b/GoldfishScheme.tmu index a97cf88e..d1f540c1 100644 --- a/GoldfishScheme.tmu +++ b/GoldfishScheme.tmu @@ -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,67 +595,65 @@ - 测试 when 在条件为真,假时的执行情况 + 测试 when 中条件为真的情况 <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> - ; 测试 when 中条件为真的情况 - - \; - \; - (check (let ((result #f)) + (check (when #t 1) =\ 1) \; + > - \ \ \ \ \ \ \ \ \ - - (when (and (\ 3 1) (\ 3 4))\ - + \; + > + - \ \ \ \ \ \ \ \ \ \ \ - - (set! result 'true-branch)) + 测试 when 中条件为假的情况 + <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> + \; - \ \ \ \ \ \ \ \ \ result - - ) =\ 'true-branch) - - \; + (check (when #f 1 ) =\ #\unspecified\) \; + > + \; + > + - ; 测试 when 中条件为假的情况,此时应该返回初始设定的值(这里是 #f) + \; - \; + 测试when中添加简单条件为真的情况 + <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> + \; - (check (let ((result #f)) + (check (when (\ 3 1) 1 ) =\ 1) \; + > - \ \ \ \ \ \ \ \ \ - - (when (or (\ 3 4) (\3 1)) - + \; + > + - \ \ \ \ \ \ \ \ \ \ \ - - (set! result 'false-branch)) + 测试when中添加简单条件为假的情况 + <\goldfish-chunk|tests/goldfish/liii/base-test.scm|true|true> + \; - \ \ \ \ \ \ \ \ \ result + (check (when (\ 1 3) 1 ) =\ #\unspecified\) - ) =\ #f) + \; > @@ -665,7 +663,7 @@ - + > diff --git a/tests/goldfish/liii/base-test.scm b/tests/goldfish/liii/base-test.scm index 9d74c5ed..88c27c72 100755 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -23,7 +23,7 @@ (check (if (> 3 2) 3 2) => 3) (check (if (< 3 2) 3 2) => 2) -(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) (check (case '+ @@ -71,35 +71,21 @@ (check (and #t 1) => 1) -; 测试 when 中条件为真的情况 +(check (when #t 1) => 1) -(check (let ((result #f)) - -(when (and (> 3 1) (< 3 4)) - -(set! result 'true-branch)) +(check (when #f 1 ) => #) - result -) => 'true-branch) +(check (when (> 3 1) 1 ) => 1) -; 测试 when 中条件为假的情况,此时应该返回初始设定的值(这里是 #f) -(check (let ((result #f)) +(check (when (> 1 3) 1 ) => #) - -(when (or (> 3 4) (<3 1)) - - -(set! result 'false-branch)) - - result -) => #f) (define (test-letrec) (letrec ((even? -- Gitee From fcf38411102f5ff62c3426d311830b12b3a5ecf4 Mon Sep 17 00:00:00 2001 From: xiaoyvhuv Date: Thu, 2 Jan 2025 22:13:09 +0800 Subject: [PATCH 6/7] =?UTF-8?q?when=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GoldfishScheme.tmu | 2 +- tests/goldfish/liii/base-test.scm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GoldfishScheme.tmu b/GoldfishScheme.tmu index d1f540c1..f8108685 100644 --- a/GoldfishScheme.tmu +++ b/GoldfishScheme.tmu @@ -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) diff --git a/tests/goldfish/liii/base-test.scm b/tests/goldfish/liii/base-test.scm index 88c27c72..afc5e5a2 100755 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -23,7 +23,7 @@ (check (if (> 3 2) 3 2) => 3) (check (if (< 3 2) 3 2) => 2) -(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) (check (case '+ -- Gitee From 977e7f405b94fcd1aae001d07192a3517404c9e7 Mon Sep 17 00:00:00 2001 From: xiaoyvhuv Date: Sat, 4 Jan 2025 17:29:28 +0800 Subject: [PATCH 7/7] add test of max --- GoldfishScheme.tmu | 68 +++++++++++++++++++++++++++++++ tests/goldfish/liii/base-test.scm | 23 +++++++++++ 2 files changed, 91 insertions(+) diff --git a/GoldfishScheme.tmu b/GoldfishScheme.tmu index f8108685..531825ba 100644 --- a/GoldfishScheme.tmu +++ b/GoldfishScheme.tmu @@ -1761,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 afc5e5a2..47ec85e3 100755 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -348,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") -- Gitee