Skip to content

Instantly share code, notes, and snippets.

@jordanrobinson
Created January 22, 2021 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordanrobinson/09fcaf2018a5bbfe27ee6698206a3dac to your computer and use it in GitHub Desktop.
Save jordanrobinson/09fcaf2018a5bbfe27ee6698206a3dac to your computer and use it in GitHub Desktop.
(defn divisible?
[divisor number]
(zero? (mod number divisor)))
(defn fizzbuzz
[number]
(cond (divisible? 15 number) "fizzbuzz"
(divisible? 5 number) "buzz"
(divisible? 3 number) "fizz"
:else (str number)))
(deftest fizzbuzz-should
(testing "multiples of 3 should return fizz"
(is (= (fizzbuzz 3) "fizz"))
(is (= (fizzbuzz 6) "fizz"))
(is (= (fizzbuzz 9) "fizz")))
(testing "multiples of 5 should return buzz"
(is (= (fizzbuzz 5) "buzz"))
(is (= (fizzbuzz 10) "buzz"))
(is (= (fizzbuzz 20) "buzz")))
(testing "multiples of 3 and 5 should return fizzbuzz"
(is (= (fizzbuzz 15) "fizzbuzz"))
(is (= (fizzbuzz 30) "fizzbuzz"))
(is (= (fizzbuzz 45) "fizzbuzz")))
(testing "everything else should return the original number"
(is (= (fizzbuzz 4) "4"))
(is (= (fizzbuzz 7) "7"))
(is (= (fizzbuzz 11) "11"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment