id:yamanetoshi さんのところでgauche.testについて触れられてたので自分でも試行錯誤してみた。
gauche.test の件 - /var/log/messages
GWなのでよく理解しないままマクロでコネコネした結果こうなったとさ。
f-testでテストしたい関数fと[answer args ...]のリストをつらつら書くとargs ...をfに与えた時の結果がanswerと一緒かテストしてくれます。ついでなんで関数名でtest-sectionも吐くように。argsは勝手にquoteするようにしてみた。でもこれだと数がargsやanswerな時まずいかもなぁ。まぁいっか。後で考える。
(use gauche.test)
(add-load-path ".")
(load "func")
(define-syntax test-q&a (syntax-rules () ((_ q a) (test* (quote q) a q))))
(define-syntax f-test
(syntax-rules ()
((_ f (a args ...) ...)
(begin
(test-section (symbol->string (quote f)))
(test-q&a (f (quote args) ...) (quote a)) ...))))
(test-start "chapter 3")
(f-test
rember
[(lamb chops and jelly) mint (lamb chops and mint jelly)]
[(lamb chops and flavored mint jelly) mint (lamb chops and mint flavored mint jelly)]
[(bacon lettuce and tomato) toast (bacon lettuce and tomato)]
[(coffee tea cup and hick cup) cup (coffee cup tea cup and hick cup)]
[(lettuce and tomato) bacon (bacon lettuce and tomato)]
[(bacon lettuce tomato) and (bacon lettuce and tomato)]
[(soy and tomato sauce) sauce (soy sauce and tomato sauce)])
(f-test
firsts
[(apple plum grape bean) ((apple peach pumpkin)
(plum pear cherry)
(grape raisin pea)
(bean carrot eggplant))]
[(a c e) ((a b) (c d) (e f))]
[() ()]
[(five four eleven) ((five plums) (four) (eleven green oranges))]
[((five plums) eleven (no)) (((five plums) four)
(eleven green oranges)
((no) more))])
(f-test
seconds
[(b d f) ((a b)
(c d)
(e f))])
(f-test
insertR
[(ice cream with fudge topping for dessert)
topping fudge (ice cream with fudge for dessert)]
[(tacos tamales and jalapeno salsa) jalapeno and (tacos tamales and salsa)]
[(a b c d e f g d h) e d (a b c d f g d h)])
(f-test
insertL
[(ice cream with topping fudge for dessert) topping fudge (ice cream with fudge for dessert)]
[(tacos tamales jalapeno and salsa) jalapeno and (tacos tamales and salsa)]
[(a b c e d f g d h) e d (a b c d f g d h)])
(f-test
subst
[(ice cream with topping for dessert) topping fudge (ice cream with fudge for dessert)])
(f-test
subst2
[(vanilla ice creamwith chocolate topping)
vanilla chocolate banana (banana ice creamwith chocolate topping)])
(f-test
multirember
[(coffee tea and hick) cup (coffee cup tea cup and hick cup)])
(f-test
multiinsertR
[(a b c d e f g d e h) e d (a b c d f g d h)]
[(w r y y y y y y y y y y) y y (w r y y y y y)])
(f-test
multiinsertL
[(chips and fried fish or fried fish and fried) fried fish (chips and fish or fish and fried)]
[(j o j o) j o (o o)])
(f-test
multisubst
[(o p p a o) o i (i p p a i)]
[() o i ()])
(test-end)
なんかだ随分寂しい感じ。すっかすか。
実行結果がこれ。diffとったけど普通に最初書いたテストと変わらなかった。
> gosh 3.scm
Testing chapter 3 ...
<rember>-----------------------------------------------------------------------
test (rember 'mint '(lamb chops and mint jelly)), expects (lamb chops and jelly) ==> ok
test (rember 'mint '(lamb chops and mint flavored mint jelly)), expects (lamb chops and flavored mint jelly) ==> ok
test (rember 'toast '(bacon lettuce and tomato)), expects (bacon lettuce and tomato) ==> ok
test (rember 'cup '(coffee cup tea cup and hick cup)), expects (coffee tea cup and hick cup) ==> ok
test (rember 'bacon '(bacon lettuce and tomato)), expects (lettuce and tomato) ==> ok
test (rember 'and '(bacon lettuce and tomato)), expects (bacon lettuce tomato) ==> ok
test (rember 'sauce '(soy sauce and tomato sauce)), expects (soy and tomato sauce) ==> ok
<firsts>-----------------------------------------------------------------------
test (firsts '((apple peach pumpkin) (plum pear cherry) (grape raisin pea) (bean carrot eggplant))), expects (apple plum grape bean) ==> ok
test (firsts '((a b) (c d) (e f))), expects (a c e) ==> ok
test (firsts '()), expects () ==> ok
test (firsts '((five plums) (four) (eleven green oranges))), expects (five four eleven) ==> ok
test (firsts '(((five plums) four) (eleven green oranges) ((no) more))), expects ((five plums) eleven (no)) ==> ok
<seconds>----------------------------------------------------------------------
test (seconds '((a b) (c d) (e f))), expects (b d f) ==> ok
<insertR>----------------------------------------------------------------------
test (insertR 'topping 'fudge '(ice cream with fudge for dessert)), expects (ice cream with fudge topping for dessert) ==> ok
test (insertR 'jalapeno 'and '(tacos tamales and salsa)), expects (tacos tamales and jalapeno salsa) ==> ok
test (insertR 'e 'd '(a b c d f g d h)), expects (a b c d e f g d h) ==> ok
<insertL>----------------------------------------------------------------------
test (insertL 'topping 'fudge '(ice cream with fudge for dessert)), expects (ice cream with topping fudge for dessert) ==> ok
test (insertL 'jalapeno 'and '(tacos tamales and salsa)), expects (tacos tamales jalapeno and salsa) ==> ok
test (insertL 'e 'd '(a b c d f g d h)), expects (a b c e d f g d h) ==> ok
<subst>------------------------------------------------------------------------
test (subst 'topping 'fudge '(ice cream with fudge for dessert)), expects (ice cream with topping for dessert) ==> ok
<subst2>-----------------------------------------------------------------------
test (subst2 'vanilla 'chocolate 'banana '(banana ice creamwith chocolate topping)), expects (vanilla ice creamwith chocolate topping) ==> ok
<multirember>------------------------------------------------------------------
test (multirember 'cup '(coffee cup tea cup and hick cup)), expects (coffee tea and hick) ==> ok
<multiinsertR>-----------------------------------------------------------------
test (multiinsertR 'e 'd '(a b c d f g d h)), expects (a b c d e f g d e h) ==> ok
test (multiinsertR 'y 'y '(w r y y y y y)), expects (w r y y y y y y y y y y) ==> ok
<multiinsertL>-----------------------------------------------------------------
test (multiinsertL 'fried 'fish '(chips and fish or fish and fried)), expects (chips and fried fish or fried fish and fried) ==> ok
test (multiinsertL 'j 'o '(o o)), expects (j o j o) ==> ok
<multisubst>-------------------------------------------------------------------
test (multisubst 'o 'i '(i p p a i)), expects (o p p a o) ==> ok
test (multisubst 'o 'i '()), expects () ==> ok
passed.
f-testとかも適当に名前つけちゃった。どうなんだろこれ。なんか分かりづらくなってしまったような気がしないでもない。