Created
October 26, 2015 18:32
-
-
Save adolfont/64d14f6169212daa97a4 to your computer and use it in GitHub Desktop.
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
(ns maff-tests) | |
(use 'clojure.test) | |
;;; Functions | |
(defn maff-180-formula [age] | |
(- 180 age) | |
) | |
(defn maff-max-age [age condition] | |
(let | |
[formula-result (maff-180-formula age)] | |
(cond | |
(= condition :consistent-training) formula-result | |
(= condition :illness-medication) (- formula-result 10) | |
(= condition :injured) (- formula-result 5) | |
(= condition :constant-progress) (+ formula-result 5) | |
:else "Error" | |
) | |
) | |
) | |
(defn maff-min-age [age condition] | |
(- (maff-max-age age condition) 10) | |
) | |
;;; Tests | |
;; Basic case (c) | |
(deftest maff-180-formula-test | |
(is (= 140 (maff-180-formula 40)))) | |
(deftest maff-max-age-test | |
(is (= 137 (maff-max-age 43 :consistent-training))) | |
) | |
(deftest maff-min-age-test | |
(is (= 127 (maff-min-age 43 :consistent-training))) | |
) | |
;; Case (a): illness or medication | |
(deftest maff-max-age-test-illness | |
(is (= 127 (maff-max-age 43 :illness-medication))) | |
) | |
(deftest maff-min-age-test-illness | |
(is (= 117 (maff-min-age 43 :illness-medication))) | |
) | |
;; Case (b): injured and so on | |
(deftest maff-max-age-test-injured | |
(is (= 132 (maff-max-age 43 :injured))) | |
) | |
(deftest maff-min-age-test-injured | |
(is (= 122 (maff-min-age 43 :injured))) | |
) | |
;; Case (d): constant progress | |
(deftest maff-max-age-test-constant-progress | |
(is (= 142 (maff-max-age 43 :constant-progress))) | |
) | |
(deftest maff-min-age-test-constant-progress | |
(is (= 132 (maff-min-age 43 :constant-progress))) | |
) | |
(run-tests 'maff-tests) | |
(println) | |
(println "Maffetone Zone:") | |
(def age 43) | |
(println "Age: " age) | |
(println "(c) Consistent Training " (maff-min-age age :consistent-training) " - " (maff-max-age age :consistent-training)) | |
(println "(a) Illness or Medication " (maff-min-age age :illness-medication) " - " (maff-max-age age :illness-medication)) | |
(println "(b) Injured " (maff-min-age age :injured) " - " (maff-max-age age :injured)) | |
(println "(d) Constant Progress " (maff-min-age age :constant-progress) " - " (maff-max-age age :constant-progress)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment