Skip to content

Instantly share code, notes, and snippets.

@unclebob
Created October 18, 2010 20:53
Show Gist options
  • Save unclebob/633038 to your computer and use it in GitHub Desktop.
Save unclebob/633038 to your computer and use it in GitHub Desktop.
Simple Mad Libs app.
(ns mad-libs-test
(:use clojure.test midje.sweet))
(defn find-prompt [t])
(defn get-response [t])
(defn mad-libs [text]
(let [
[pre prompt post] (find-prompt text)]
(if (nil? prompt)
text
(str pre (get-response prompt) (mad-libs post)))))
(deftest mad-libs-test
(fact (mad-libs "text") => "text"
(provided (find-prompt "text") => ["text" nil nil]))
(fact (mad-libs "a ((x)) b") => "a response b"
(provided
(find-prompt "a ((x)) b") => ["a " "x" " b"]
(find-prompt " b") => [" b" nil nil]
(get-response "x") => "response"))
)
(run-tests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment