Created
January 22, 2021 15:44
-
-
Save jordanrobinson/09fcaf2018a5bbfe27ee6698206a3dac to your computer and use it in GitHub Desktop.
This file contains 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
(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