Spotting Bugs with clojure.test
Let’s begin our adventures in testing by building a brand-new book store inventory project:
$ lein new inventory
Now imagine we’re going to have a book inventory that looks like this:
| [{:title "2001" :author "Clarke" :copies 21} |
| {:title "Emma" :author "Austen" :copies 10} |
| {:title "Misery" :author "King" :copies 101}]) |
And we write some functions to do useful things with it:
| (ns inventory.core) |
| |
| (defn find-by-title |
| "Search for a book by title, |
| where title is a string and books is a collection |
| of book maps, each of which must have a :title entry" |
| [title books] |
| (some #(when (= (:title %) title) %) books)) |
| |
| (defn number-of-copies-of |
|
Get Getting Clojure now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.