Created
August 23, 2016 11:37
-
-
Save MikeMKH/abe54ef2eae58ceb8b116ac1f5825a2d to your computer and use it in GitHub Desktop.
FizzBuzz kata in Racket using cond
This file contains hidden or 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
| #lang racket | |
| (require rackunit rackunit/text-ui) | |
| (define (fizz-buzz n) | |
| (cond | |
| [(zero? (modulo n 15)) "fizzbuzz"] | |
| [(zero? (modulo n 3)) "fizz"] | |
| [(zero? (modulo n 5)) "buzz"] | |
| [else (number->string n)])) | |
| (run-tests | |
| (test-suite | |
| "map given to expected value" | |
| (check-equal? "fizz" (fizz-buzz 3)) | |
| (check-equal? "fizz" (fizz-buzz 33)) | |
| (check-equal? "buzz" (fizz-buzz 5)) | |
| (check-equal? "buzz" (fizz-buzz 55)) | |
| (check-equal? "fizzbuzz" (fizz-buzz 15)) | |
| (check-equal? "fizzbuzz" (fizz-buzz 45)) | |
| (check-equal? "2" (fizz-buzz 2)) | |
| (check-equal? "22" (fizz-buzz 22)))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is my first Racket kata, so this is most likely not very good.