Skip to content

Instantly share code, notes, and snippets.

@adolfont
Created March 15, 2016 19:06
Show Gist options
  • Select an option

  • Save adolfont/587a401f5282ce6f6bf6 to your computer and use it in GitHub Desktop.

Select an option

Save adolfont/587a401f5282ce6f6bf6 to your computer and use it in GitHub Desktop.
(ns clojure.test.cond
(:use clojure.set)
(:use clojure.test)
)
(defn tem-intersecao [conjunto vetor]
(> (count (intersection conjunto (set vetor))) 0)
)
(defn test-cond [age & args]
(let
[valor-inicial (- 180 age)
condicao-a (if (tem-intersecao #{:bla :bli} args) -5 0)
condicao-b (if (tem-intersecao #{:ble :blu} args) -10 0)
]
(cond
(= 0 (count args)) valor-inicial
:else (+ valor-inicial condicao-a condicao-b)
)
)
)
(deftest test-cond-1 (is (= 160 (test-cond 20))))
(deftest test-cond-bla (is (= 155 (test-cond 20 :bla))))
(deftest test-cond-bli (is (= 155 (test-cond 20 :bli))))
(deftest test-cond-ble (is (= 150 (test-cond 20 :ble))))
(deftest test-cond-blu (is (= 150 (test-cond 20 :blu))))
(deftest test-cond-bla-ble (is (= 145 (test-cond 20 :bla :ble))))
(deftest test-cond-bli-blu (is (= 145 (test-cond 20 :bli :blu))))
(deftest test-cond-bla-ble-bli-blu (is (= 135 (test-cond 30 :bla :ble :bli :blu))))
(run-tests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment