Skip to content

Instantly share code, notes, and snippets.

@gnab
Created June 21, 2011 12:48
Show Gist options
  • Save gnab/1037786 to your computer and use it in GitHub Desktop.
Save gnab/1037786 to your computer and use it in GitHub Desktop.
FizzBuzz Kata in Clojure
(ns fizzbuzz (:use clojure.test))
(defn fizzbuzz [n]
(let [ret (str (when (= (rem n 3) 0) "Fizz")
(when (= (rem n 5) 0) "Buzz"))]
(if (empty? ret) n ret)))
(deftest fizzbuzz-test
(is (= (fizzbuzz 1) 1))
(is (= (fizzbuzz 2) 2))
(is (= (fizzbuzz 3) "Fizz"))
(is (= (fizzbuzz 4) 4))
(is (= (fizzbuzz 5) "Buzz"))
(is (= (fizzbuzz 15) "FizzBuzz"))
)
(run-tests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment