adolfont
4/19/2016 - 7:25 PM

Coding Dojo de 19/04/2016

Coding Dojo de 19/04/2016

;;Testes:

(ns fizzbuzz.core-test
  (:require [clojure.test :refer :all]
            [fizzbuzz.core :refer :all]))

(deftest fizz-buzz-007
    (is (= (fizzbuzz 1) 1)))

(deftest fizz-buzz-002
  (is (= (fizzbuzz 2) 2)))

(deftest fizz-buzz-001
  (is (= (fizzbuzz 3) "fizz")))

(deftest fizz-buzz-003
  (is (= (fizzbuzz 4) 4)))

(deftest fizz-buzz-004
  (is (= (fizzbuzz 5) "buzz")))

(deftest fizz-buzz-005
  (is (= (fizzbuzz 15) "fizzbuzz")))

(deftest fizz-buzz-006
    (is (= (fizzbuzz 16) 16)))

(deftest fizz-buzz-008
  (is (= (fizzbuzz 10) "buzz")))

(deftest fizz-buzz-009
  (is (= (fizzbuzz 6) "fizz")))

(deftest fizz-buzz-1-a-x
  (is (= '(1 2 "fizz") (fizz-buzz-intervalo 1 3) )))

(deftest fizz-buzz-5-a-15
  (is (= '("buzz" "fizz" 7 8 "fizz" "buzz" 11 "fizz" 13 14 "fizzbuzz")
          (fizz-buzz-intervalo 5 15) )))


;;Código:

(ns fizzbuzz.core)

(defn fizzbuzz [num]
    (cond
      (= (mod num 15) 0) "fizzbuzz"
      (= (mod num 5) 0) "buzz"
      (= (mod num 3) 0) "fizz"
      :else num)
)

(defn fizz-buzz-intervalo [inicio fim]
  (map fizzbuzz (range inicio (+ fim 1)))
)