From 6aa3c910cd067cb5c5d44dafb42ec635785adcab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=B5=AA=E7=86=8A=E7=8C=AB=E5=84=BF?= Date: Fri, 27 Sep 2024 08:07:45 +0000 Subject: [PATCH] !65 Goldfish: minor improvements --- Goldfish.tmu | 226 +++------------------------- tests/goldfish/liii/base-test.scm | 9 +- tests/goldfish/liii/list-test.scm | 26 +--- tests/goldfish/liii/string-test.scm | 94 ++---------- 4 files changed, 41 insertions(+), 314 deletions(-) diff --git a/Goldfish.tmu b/Goldfish.tmu index 50a4ca7..f7c9169 100644 --- a/Goldfish.tmu +++ b/Goldfish.tmu @@ -3652,13 +3652,9 @@ list>是一个S7内置的函数,用于将字符串转换为字符列表。 <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> - (check - - \ \ (string-\list "MathAgape") - - \ \ =\ + (check (string-\list "MathAgape") - \ \ '(#\\M #\\a #\\t #\\h #\\A #\\g #\\a #\\p #\\e)) + \ \ =\ '(#\\M #\\a #\\t #\\h #\\A #\\g #\\a #\\p #\\e)) \; @@ -3676,9 +3672,7 @@ \ \ (list-\string '(#\\M #\\a #\\t #\\h #\\A #\\g #\\a #\\p #\\e)) - \ \ =\ - - \ \ "MathAgape") + \ \ =\ "MathAgape") \; @@ -3806,21 +3800,7 @@ (check-catch 'value-error (string-join '() ":" 'no-such-grammer)) - \; - - (check - - \ \ (catch 'wrong-number-of-args - - \ \ \ \ (lambda ()\ - - \ \ \ \ \ \ (string-join '() ":" 1 2 3)) - - \ \ \ \ (lambda args #t)) - - \ \ =\ - - \ \ #t) + (check-catch 'wrong-number-of-args (string-join '() ":" 1 2 3)) \; @@ -3892,31 +3872,9 @@ \; - (check + (check-true (string-every char-numeric? "012345")) - \ \ (string-every\ - - \ \ \ \ char-numeric? - - \ \ \ \ "012345") - - \ \ =\ - - \ \ #t) - - \; - - (check - - \ \ (string-every\ - - \ \ \ \ char-numeric? - - \ \ \ \ "012d45") - - \ \ =\ - - \ \ #f) + (check-false (string-every char-numeric? "012d45")) \; @@ -3924,23 +3882,7 @@ 注意,评估规则必须是谓词或字符,否则报错。 <\scm-chunk|tests/goldfish/liii/string-test.scm|true|true> - (check - - \ \ (catch 'wrong-type-arg - - \ \ \ \ (lambda ()\ - - \ \ \ \ \ \ (string-every - - \ \ \ \ \ \ \ \ \ 1 - - \ \ \ \ \ \ \ \ \ "012345")) - - \ \ \ \ (lambda args #t)) - - \ \ =\ - - \ \ #t) + (check-catch 'wrong-type-arg (string-every 1 "012345")) \; @@ -3988,31 +3930,9 @@ 注意,谓词要使用字符属性测试函数(例如),不要用类型检查函数(例如>),否则失去了检查的意义。 <\scm-chunk|tests/goldfish/liii/string-test.scm|true|true> - (check - - \ \ (string-every\ - - \ \ \ \ char-numeric? - - \ \ \ \ "012345") - - \ \ =\ - - \ \ #t) - - \; - - (check - - \ \ (string-every\ - - \ \ \ \ + (check-true (string-every char-numeric? "012345")) - \ \ \ \ "012345") - - \ \ =\ - - \ \ #f) + (check-false (string-every number? "012345")) \; @@ -4022,61 +3942,15 @@ <\scm-chunk|tests/goldfish/liii/string-test.scm|true|true> (check-true (string-every char-numeric? "ab2345" 2)) - \; - (check-false (string-every char-numeric? "ab2345" 1)) - \; - - (check - - \ \ (string-every\ - - \ \ \ \ char-numeric? - - \ \ \ \ "ab234f" - - \ \ \ \ 2) - - \ \ =\ - - \ \ #f) + (check-false (string-every \ char-numeric? "ab234f" 2)) \; - (check - - \ \ (string-every\ - - \ \ \ \ char-numeric? - - \ \ \ \ "ab234f" - - \ \ \ \ 2 - - \ \ \ \ 4) + (check-true (string-every char-numeric? "ab234f" 2 4)) - \ \ =\ - - \ \ #t) - - \; - - (check - - \ \ (string-every\ - - \ \ \ \ - - \ \ \ \ "ab234f" - - \ \ \ \ 2 - - \ \ \ \ 2) - - \ \ =\ - - \ \ #t) + (check-true (string-every char-numeric? "ab234f" 2 2)) \; @@ -4246,33 +4120,9 @@ (check-false (string-any #\\0 "xxxxxx")) - \; - - (check + (check-true (string-any char-numeric? "xxx0xx")) - \ \ (string-any\ - - \ \ \ \ char-numeric? - - \ \ \ \ "xxx0xx") - - \ \ =\ - - \ \ #t) - - \; - - (check - - \ \ (string-any - - \ \ \ \ char-numeric? - - \ \ \ \ "xxxxxx") - - \ \ =\ - - \ \ #f) + (check-false (string-any char-numeric? "xxxxxx")) \; @@ -6436,10 +6286,10 @@ <\scm-chunk|tests/goldfish/liii/list-test.scm|true|true> (check (second '(1 2 3 4 5 6 7 8 9 10)) =\ 2) - (check (second '(left . right)) =\ 'right) - \; + (check-catch 'wrong-type-arg (second '(left . right))) + (check-catch 'wrong-type-arg (second '(1))) \; @@ -6626,15 +6476,7 @@ \; - (check - - \ \ (catch 'wrong-type-arg - - \ \ \ \ (lambda () (drop '(1 2 3 4) 5)) - - \ \ \ \ (lambda args #t)) - - \ \ =\ #t) + (check-catch 'wrong-type-arg (drop '(1 2 3 4) 5)) \; @@ -6642,15 +6484,7 @@ \; - (check - - \ \ (catch 'wrong-type-arg - - \ \ \ \ (lambda () (drop '(1 2 3 . 4) 4)) - - \ \ \ \ (lambda args #t)) - - \ \ =\ #t) + (check-catch 'wrong-type-arg (drop '(1 2 3 . 4) 4)) \; @@ -6820,15 +6654,7 @@ \; - (check - - \ \ (catch 'wrong-type-arg - - \ \ \ \ (lambda () (last-pair '())) - - \ \ \ \ (lambda args #t)) - - \ \ =\ #t) + (check-catch 'wrong-type-arg (last-pair '())) \; @@ -6858,24 +6684,16 @@ \; - (check - - \ \ (catch 'wrong-type-arg - - \ \ \ \ (lambda () (last '())) - - \ \ \ \ (lambda args #t)) - - \ \ =\ #t) + (check-catch 'wrong-type-arg (last '())) \; - integer> + integer> - 是一个S7内置的R7RS定义的函数,它接收一个列表为参数,返回该列表中元素的数量。如果参数不是列表,返回0。 + 是一个S7内置函数,它接收一个列表为参数,返回该列表中元素的数量。如果参数不是列表,返回0。 <\scm-chunk|tests/goldfish/liii/base-test.scm|true|true> (check (length ()) =\ 0) diff --git a/tests/goldfish/liii/base-test.scm b/tests/goldfish/liii/base-test.scm index 2bf9f0a..aae0075 100644 --- a/tests/goldfish/liii/base-test.scm +++ b/tests/goldfish/liii/base-test.scm @@ -318,17 +318,14 @@ (check (string? 123) => #f) (check (string? '(1 2 3)) => #f) -(check - (string->list "MathAgape") - => - '(#\M #\a #\t #\h #\A #\g #\a #\p #\e)) +(check (string->list "MathAgape") + => '(#\M #\a #\t #\h #\A #\g #\a #\p #\e)) (check (string->list "") => '()) (check (list->string '(#\M #\a #\t #\h #\A #\g #\a #\p #\e)) - => - "MathAgape") + => "MathAgape") (check (list->string '()) => "") diff --git a/tests/goldfish/liii/list-test.scm b/tests/goldfish/liii/list-test.scm index f31873c..2e09984 100644 --- a/tests/goldfish/liii/list-test.scm +++ b/tests/goldfish/liii/list-test.scm @@ -43,8 +43,8 @@ (check-catch 'wrong-type-arg (first '())) (check (second '(1 2 3 4 5 6 7 8 9 10)) => 2) -(check (second '(left . right)) => 'right) +(check-catch 'wrong-type-arg (second '(left . right))) (check-catch 'wrong-type-arg (second '(1))) (check (third '(1 2 3 4 5 6 7 8 9 10)) => 3) @@ -76,19 +76,11 @@ (check (drop '(1 2 3 4) 4) => '()) -(check - (catch 'wrong-type-arg - (lambda () (drop '(1 2 3 4) 5)) - (lambda args #t)) - => #t) +(check-catch 'wrong-type-arg (drop '(1 2 3 4) 5)) (check (drop '(1 2 3 . 4) 3) => 4) -(check - (catch 'wrong-type-arg - (lambda () (drop '(1 2 3 . 4) 4)) - (lambda args #t)) - => #t) +(check-catch 'wrong-type-arg (drop '(1 2 3 . 4) 4)) (check (take-right '(1 2 3 4) 3) => '(2 3 4)) @@ -138,11 +130,7 @@ (check (last-pair '(a b . c)) => '(b . c)) (check (last-pair '(b . c)) => '(b . c)) -(check - (catch 'wrong-type-arg - (lambda () (last-pair '())) - (lambda args #t)) - => #t) +(check-catch 'wrong-type-arg (last-pair '())) (check (last '(a b c)) => 'c) (check (last '(c)) => 'c) @@ -150,11 +138,7 @@ (check (last '(a b . c)) => 'b) (check (last '(b . c)) => 'b) -(check - (catch 'wrong-type-arg - (lambda () (last '())) - (lambda args #t)) - => #t) +(check-catch 'wrong-type-arg (last '())) (check (count even? '(3 1 4 1 5 9 2 5 6)) => 3) diff --git a/tests/goldfish/liii/string-test.scm b/tests/goldfish/liii/string-test.scm index d9deaf0..821961b 100644 --- a/tests/goldfish/liii/string-test.scm +++ b/tests/goldfish/liii/string-test.scm @@ -34,14 +34,7 @@ (check-catch 'value-error (string-join '() ":" 'strict-infix)) (check-catch 'type-error (string-join '() ":" 2)) (check-catch 'value-error (string-join '() ":" 'no-such-grammer)) - -(check - (catch 'wrong-number-of-args - (lambda () - (string-join '() ":" 1 2 3)) - (lambda args #t)) - => - #t) +(check-catch 'wrong-number-of-args (string-join '() ":" 1 2 3)) (check-true (string-null? "")) @@ -52,29 +45,10 @@ (check-true (string-every #\x "xxxxxx")) (check-false (string-every #\x "xxx0xx")) -(check - (string-every - char-numeric? - "012345") - => - #t) +(check-true (string-every char-numeric? "012345")) +(check-false (string-every char-numeric? "012d45")) -(check - (string-every - char-numeric? - "012d45") - => - #f) - -(check - (catch 'wrong-type-arg - (lambda () - (string-every - 1 - "012345")) - (lambda args #t)) - => - #t) +(check-catch 'wrong-type-arg (string-every 1 "012345")) (check (catch 'wrong-type-arg @@ -96,49 +70,15 @@ => #t) -(check - (string-every - char-numeric? - "012345") - => - #t) - -(check - (string-every - number? - "012345") - => - #f) +(check-true (string-every char-numeric? "012345")) +(check-false (string-every number? "012345")) (check-true (string-every char-numeric? "ab2345" 2)) - (check-false (string-every char-numeric? "ab2345" 1)) +(check-false (string-every char-numeric? "ab234f" 2)) -(check - (string-every - char-numeric? - "ab234f" - 2) - => - #f) - -(check - (string-every - char-numeric? - "ab234f" - 2 - 4) - => - #t) - -(check - (string-every - char-numeric? - "ab234f" - 2 - 2) - => - #t) +(check-true (string-every char-numeric? "ab234f" 2 4)) +(check-true (string-every char-numeric? "ab234f" 2 2)) (check (string-every @@ -206,20 +146,8 @@ (check-true (string-any #\0 "xxx0xx")) (check-false (string-any #\0 "xxxxxx")) - -(check - (string-any - char-numeric? - "xxx0xx") - => - #t) - -(check - (string-any - char-numeric? - "xxxxxx") - => - #f) +(check-true (string-any char-numeric? "xxx0xx")) +(check-false (string-any char-numeric? "xxxxxx")) (check (catch 'wrong-type-arg