Created
December 20, 2010 05:52
-
-
Save capoferro/748072 to your computer and use it in GitHub Desktop.
I like writing unit tests
This file contains hidden or 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
| (test/with-test | |
| (defn to_wound | |
| ([s t] | |
| (let [x (+ 4 (- t s))] | |
| (max 2 (min 6 x))))) | |
| (test/is (= (to_wound 3 3) 4)) | |
| (test/is (= (to_wound 3 4) 5)) | |
| (test/is (= (to_wound 3 2) 3)) | |
| (test/is (= (to_wound 3 1) 2)) | |
| (test/is (= (to_wound 4 1) 2)) | |
| (test/is (= (to_wound 5 1) 2)) | |
| (test/is (= (to_wound 6 1) 2)) | |
| (test/is (= (to_wound 7 1) 2)) | |
| (test/is (= (to_wound 4 6) 6)) | |
| (test/is (= (to_wound 4 7) 6))) | |
| (test/with-test | |
| (defn to_hit | |
| ([attacker_ws defender_ws] | |
| (let [difference (- defender_ws attacker_ws)] | |
| (cond | |
| (> difference attacker_ws) 5 | |
| (< difference 0) 3 | |
| :else 4))))) | |
| (test/is (= (to_hit 3 3) 4)) | |
| (test/is (= (to_hit 3 4) 4)) | |
| (test/is (= (to_hit 3 5) 4)) | |
| (test/is (= (to_hit 3 6) 4)) | |
| (test/is (= (to_hit 3 7) 5)) | |
| (test/is (= (to_hit 3 8) 5)) | |
| (test/is (= (to_hit 3 2) 3)) | |
| (test/is (= (to_hit 3 1) 3))) | |
| (test/with-test | |
| (defn to_save_armor | |
| ([s armor] | |
| (let [modifier (max 0 (- s 3))] | |
| (max 2 (+ armor modifier))))) | |
| (test/is (= (to_save_armor 5 2) 4)) | |
| (test/is (= (to_save_armor 5 3) 5)) | |
| (test/is (= (to_save_armor 5 5) 7)) | |
| (test/is (= (to_save_armor 1 3) 3)) | |
| (test/is (= (to_save_armor 2 3) 3)) | |
| (test/is (= (to_save_armor 3 3) 3)) | |
| (test/is (= (to_save_armor 3 1) 2)) | |
| (test/is (= (to_save_armor 3 -1) 2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment