Skip to content

Commit

Permalink
Merge pull request #2 from ezephyr/master
Browse files Browse the repository at this point in the history
Update the kata to work with the newest versions of clojure, lein and midje
  • Loading branch information
gigasquid committed Dec 26, 2013
2 parents 3894b9c + 391d029 commit 1707afe
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 149 deletions.
38 changes: 15 additions & 23 deletions README.md
@@ -1,39 +1,31 @@
# Yellow Belt Clojure Katas

This is a template for beginner level Clojure Katas done with tests
in [midje](https://github.com/marick/Midje).
The katas are taken more or less from the
[Coding Kata site](http://codingkata.org/katas/).
This is a template for beginner level Clojure Katas done with tests in
[midje](https://github.com/marick/Midje). The katas were taken more
or less from the (now vanished) Coding Kata site
(http://codingkata.org/katas/).

Once you've mastered these simple kata, check out the [Pragmatic
Programmers
Kata](http://codekata.pragprog.com/2007/01/code_kata_backg.html).


## Setup instructions

* Download and install [leiningen](https://github.com/technomancy/leiningen).
* Download and install
[leiningen](https://github.com/technomancy/leiningen).
* Clone project.
* CD in the project and run "lein deps".
* run "lein test". You should see all the tests run with "WORK TO DO"
* Choose a kata. The shell source code with instructions is in the src/clojure_katas directory and the test
is in the test/clojure_katas directory.
* In the test find the change the word
future-facts
to
facts
or
future-fact
to
fact
* run "lein midje". You should see all the tests run with "WORK TO DO"
* Choose a kata. The shell source code with instructions is in the
src/clojure_katas directory. The tests are in the same files.
* In the test find the change the word future-facts to facts or
future-fact to fact
* Run lein test again. You should have failing tests now
* Fix the the code and run the tests!

If you have any problem setting up the project, please let me know.


## Hints

There are quite a number of solutions on the Coding Kata site. I found it fun
to browse them and see how other people solved them after I had
finished mine.

# Corrections

Being a beginner myself, there might be mistakes or something I
Expand Down
10 changes: 5 additions & 5 deletions project.clj
@@ -1,6 +1,6 @@
(defproject clojure-katas "1.0.0-SNAPSHOT"
(defproject clojure-katas "2.0.0-SNAPSHOT"
:description "Clojure Katas with: write"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]]
:dev-dependencies [[swank-clojure "1.2.1"]
[midje "1.1-alpha-3"]])
:profiles {:dev {:plugins [[lein-midje "3.0.1"]]
:dependencies [[midje "1.5.1"]]}}
:dependencies [[org.clojure/clojure "1.5.0"]
[org.clojure/math.numeric-tower "0.0.2"]])
15 changes: 9 additions & 6 deletions src/clojure_katas/fib.clj
@@ -1,9 +1,12 @@
(ns clojure-katas.fib)

;; Calculate the fibonacci sequence
;; f(0) = 0, f(1) = 1
;; f(n) = f(n-1) + f(n-2)
(ns clojure-katas.fib
(:use [midje.sweet]))

(defn fib[n])


(future-facts "Calculate the fibonacci sequence
f(0) = 0, f(1) = 1
f(n) = f(n-1) + f(n-2)"
(fib 0) => 0
(fib 1) => 1
(fib 3) => 2
(fib 10) => 55)
17 changes: 11 additions & 6 deletions src/clojure_katas/fizzbuzz.clj
@@ -1,9 +1,14 @@
(ns clojure-katas.fizzbuzz)
(ns clojure-katas.fizzbuzz
(:use [midje.sweet]))

;; answer should return "fizz" for n divisible by 3,
;; "buzz" for n divisible by 5
;; and "fizzbuzz" for n divisible by 5 and 3
;; otherwise just the number
(defn fizzbuzz [n])

(defn answer [n])
(future-facts "Fizzbuzz returns \"fizz\" when the number is divisible
by 3, and \"buzz\" when the number is divisible by 5. If divisible by
3 AND 5, return \"fizzbuzz\". Otherwise, return the number."

(fizzbuzz 3) => "fizz"
(fizzbuzz 5) => "buzz"
(fizzbuzz 15) => "fizzbuzz"
(fizzbuzz 7) => 7
(fizzbuzz 7) =not=> "fizz")
13 changes: 8 additions & 5 deletions src/clojure_katas/gcd.clj
@@ -1,9 +1,12 @@
(ns clojure-katas.gcd
(:require [clojure.contrib.math :as math]))

;; Greatest Common divisor
;; gcd(a,0) = a
;; gcd(b, a mod b)
(:use [midje.sweet])
(:require [clojure.math.numeric-tower :as math]))

(defn gcd [a b])

(future-facts "Greatest Common divisor:
gcd(a,0) = a
gcd(b, a mod b)"
(gcd 3 0) => 3
(gcd 48 180) => 12
(gcd 9 28) => 1)
11 changes: 7 additions & 4 deletions src/clojure_katas/nasa_countdown.clj
@@ -1,7 +1,10 @@
(ns clojure-katas.nasa-countdown)

;; Countdown should return a list counting down from the start all the
;; way to zero
(ns clojure-katas.nasa-countdown
(:use [midje.sweet]))

(defn countdown [start])

(future-fact "Countdown should return a list counting down from the
start all the way to zero"

(countdown 5) => '(5 4 3 2 1 0)
(countdown 0) => '(0))
8 changes: 5 additions & 3 deletions src/clojure_katas/reverseword.clj
@@ -1,5 +1,7 @@
(ns clojure-katas.reverseword)

;; Reverse a given input word
(ns clojure-katas.reverseword
(:use [midje.sweet]))

(defn reverse-word [word])

(future-fact "Reverse a given input word"
(reverse-word "looc") => "cool")
20 changes: 12 additions & 8 deletions src/clojure_katas/teaparty.clj
@@ -1,11 +1,15 @@
(ns clojure-katas.teaparty)

;; welcome should return the greeting with the proper title depending
;; on whether it is a man, woman, or knight
;; A woman is addressed as Ms.
;; A man is addressed as Mr.
;; A knight is addressed as Sir
;; The return string should be "Welcome (the title) (last name)
(ns clojure-katas.teaparty
(:use [midje.sweet]))

(defn welcome [last-name is-woman? is-sir?])

(future-fact "Welcome should return the greeting with the proper title
depending on whether it is a man, woman, or knight.
A woman is addressed as Ms.
A man is addressed as Mr.
A knight is addressed as Sir.
The return string should be Welcome (the title) (last name)"

(welcome "Austen" true false) => "Welcome Ms. Austen"
(welcome "Orwell" false false) => "Welcome Mr. Orwell"
(welcome "Newton" false true) => "Welcome Sir Newton")
17 changes: 12 additions & 5 deletions src/clojure_katas/teleprompter.clj
@@ -1,10 +1,17 @@
(ns clojure-katas.teleprompter)

;; Given an input text string and a list of slang words and their
;; translations
;; return the cleansed input string of the slang words
(ns clojure-katas.teleprompter
(:use [midje.sweet]))

(defn translate [input-string dictionary])

(def dict-1 {"hizzle" "house"})
(def dict-2 {"hizzle" "house"
"brainspin" "insomnia"})

(future-facts "Given an input text string and a list of slang words
and their translations, return a string cleansed of the slang words,
by replacing them with their translations."

(translate "In the hizzle" dict-1) => "In the house"
(translate "In the hizzle, hizzle" dict-1) => "In the house, house"
(translate "In the hizzle, suffering from brainspin" dict-2)
=> "In the house, suffering from insomnia")
12 changes: 0 additions & 12 deletions test/clojure_katas/test/fib.clj

This file was deleted.

13 changes: 0 additions & 13 deletions test/clojure_katas/test/fizzbuzz.clj

This file was deleted.

11 changes: 0 additions & 11 deletions test/clojure_katas/test/gcd.clj

This file was deleted.

12 changes: 0 additions & 12 deletions test/clojure_katas/test/nasa_countdown.clj

This file was deleted.

8 changes: 0 additions & 8 deletions test/clojure_katas/test/reverseword.clj

This file was deleted.

11 changes: 0 additions & 11 deletions test/clojure_katas/test/teaparty.clj

This file was deleted.

17 changes: 0 additions & 17 deletions test/clojure_katas/test/teleprompter.clj

This file was deleted.

0 comments on commit 1707afe

Please sign in to comment.