同居人には内緒で sticker 発注だん。それは良いとしてとりあえず以下な手続きの試験を書いてみます。
- empty-stack
- push
- pop
- top
- empty-stack?
この節の記述によれば top と empty-stack? が ovservers でそれ以外は constructors ってことで良いのかどうか。
とりあえず stack はリストで表現することにしますね。試験としては以下がでっちあがりました。元気があれば実装も書く方向ですがどうなるか。
(use gauche.test)
(add-load-path ".")
(load "stacks")
(test-start "stack")
(test-section "empty-stack")
(test* "empty-stack"
'()
(empty-stack))
(test-section "empty-stack?")
(test* "empty-stack"
#t
(empty-stack? (empty-stack)))
(test-section "push")
(test* "pushed stack is not empty"
#f
(empty-stack? (push 1 (empty-stack))))
(test-section "pop")
(test* "cannot pop from empty-stack"
(test-error)
(pop (empty-stack)))
(test* "get top of stack"
1
(pop (push 1 (empty-stack))))
(test* "after pop"
#t
(empty-stack? (pop (push 1 (empty-stack)))))
(test=section "top")
(test* "top of empty-stack is '()"
'()
(top (empty-stack)))
(test* "top of _not empty-stack_ check"
1
(top (push 1 (empty-stack))))
(test: "top not pop"
#f
(empty-stack? (top (push 1 (empty-stack)))))
(test-end)
追記するかも。しないかも。