Skip to content

Commit

Permalink
add clojure fizzbuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
tellisnz committed Feb 4, 2016
0 parents commit 5841fbf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.gradle
build
*.iws
*.ipr
*.iml
.idea
lib
27 changes: 27 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
buildscript {
repositories {
maven { url 'http://clojars.org/repo' }
mavenCentral()
}

dependencies {
classpath 'clojuresque:clojuresque:1.7.0'
}
}

apply plugin: 'clojure'
apply plugin: 'idea'

clojure {
warnOnReflection = true
aotCompile = true
}

repositories {
maven { url 'http://clojars.org/repo' }
mavenCentral()
}

dependencies {
compile 'org.clojure:clojure:1.8.0'
}
11 changes: 11 additions & 0 deletions src/main/clojure/fizzbuzz.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns fizzbuzz)

(defn fizz-buzz [fizz buzz end]
"Returns Fizz and/or Buzz for all multiples of the fizz and buzz parameters from 1 to end."
(map (fn [n]
(cond
(and (zero? (mod n fizz)) (zero? (mod n buzz))) "FizzBuzz"
(zero? (mod n fizz)) "Fizz"
(zero? (mod n buzz)) "Buzz"
:else n))
(range 1 (+ end 1))))
12 changes: 12 additions & 0 deletions src/test/clojure/fizzbuzz_should.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns fizzbuzz-should
(:require [clojure.test :refer :all]
[fizzbuzz :refer :all]))


(deftest correctly-say-fizz-buzz
(is
(=
[1 2 "Fizz" 4 "Buzz" "Fizz" 7 8 "Fizz" "Buzz" 11 "Fizz" 13 14 "FizzBuzz"]
(fizz-buzz 3 5 15))))

(run-tests 'fizzbuzz-should)

0 comments on commit 5841fbf

Please sign in to comment.