Created
December 30, 2008 01:09
-
-
Save larrytheliquid/41468 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(share-test "non-empty specjure.examples/stack" [] | |
(test "is not empty" | |
(is (not (empty? ($get :stack))))) | |
(test "returns the top item when applied to specjure.examples/peek" | |
(is (= ($get :last-item-added) (peek ($get :stack))))) | |
(test "does not remove the top item when applied to specjure.examples/peek" | |
(is (= ($get :last-item-added) (peek ($get :stack)))) | |
(is (= ($get :last-item-added) (peek ($get :stack))))) | |
(test "returns the top item when applied to specjure.examples/pop!" | |
(is (= ($get :last-item-added) (pop! ($get :stack))))) | |
(test "removes the top item when applied to specjure.examples/pop!" | |
(is (= ($get :last-item-added) (pop! ($get :stack)))) | |
(when-not (empty? ($get :stack)) | |
(is (not (= ($get :last-item-added) (pop! ($get :stack))))))) | |
(share-test "non-full specjure.examples/stack" [] | |
(test "is not full" | |
(is (not (full? ($get :stack))))) | |
(test "adds to the top when applied to specjure.examples/push!" | |
(push! ($get :stack) "newly added top item") | |
(when-not (empty? ($get :stack)) | |
(is (= "newly added top item" (peek ($get :stack))))))) | |
(context stack | |
(before ($assoc! :stack (stack))) | |
(context "(empty)" | |
(test "is empty" | |
(is (empty? ($get :stack)))) | |
(use-test "non-full specjure.examples/stack") | |
(test "complains when applied to specjure.examples/peek" | |
(is (thrown? java.util.EmptyStackException (peek ($get :stack))))) | |
(test "complains when applied to specjure.examples/pop!" | |
(is (thrown? java.util.EmptyStackException (pop! ($get :stack)))))) | |
(context "(with one item)" | |
(before | |
(push! ($get :stack) 3) | |
($assoc! :last-item-added 3)) | |
(use-test "non-empty specjure.examples/stack") | |
(use-test "non-full specjure.examples/stack")) | |
(context "(with one item less than capactiy)" | |
(before | |
(doseq i (range 1 10) (push! ($get :stack) i)) | |
($assoc! :last-item-added 9)) | |
(use-test "non-empty specjure.examples/stack") | |
(use-test "non-full specjure.examples/stack")) | |
(context "(full)" | |
(before | |
(doseq i (range 1 11) (push! ($get :stack) i)) | |
($assoc! :last-item-added 10)) | |
(test "is full" | |
(is (full? ($get :stack)))) | |
(use-test "non-empty specjure.examples/stack") | |
(test "complains when applied to specjure.examples/push!" | |
(is (thrown? Exception (push! ($get :stack) (fn []))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment