Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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