Skip to content

Commit

Permalink
numbered tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jani Rahkola committed Mar 9, 2013
1 parent 32c6ed0 commit 9678110
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 54 deletions.
12 changes: 2 additions & 10 deletions README.md
@@ -1,15 +1,7 @@
# structured-data

I'm an app. Or maybe I'm a library? I haven't decided yet.

The choice is up to you!
I'm part of the [120 hour epic sax marathon](http://iloveponies.github.com/120-hour-epic-sax-marathon/).

## Usage

FIXME

## License

Copyright © 2012 FIXME

Distributed under the Eclipse Public License, the same as Clojure.
Make a fork of me!
8 changes: 3 additions & 5 deletions project.clj
@@ -1,7 +1,5 @@
(defproject structured-data "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]]
:profiles {:dev {:dependencies [[midje "1.4.0"]
[com.stuartsierra/lazytest "1.2.3"]]
:plugins [[lein-midje "2.0.0-SNAPSHOT"]]}}
:repositories {"stuart" "http://stuartsierra.com/maven2"})
:dependencies [[org.clojure/clojure "1.5.0"]]
:profiles {:dev {:dependencies [[midje "1.5-RC1"]]
:plugins [[lein-midje "3.0-RC1"]]}})

78 changes: 39 additions & 39 deletions test/structured_data_test.clj
Expand Up @@ -2,48 +2,48 @@
(:use structured-data
midje.sweet))

(facts "do-a-thing"
(facts "1 do-a-thing"
(do-a-thing 3) => 46656.0
(do-a-thing 1) => 4.0
(do-a-thing 0) => 1.0)

(facts "spiff"
(facts "2 spiff"
(spiff [1 2 3]) => 4
(spiff [1 2 -34 4 5 6]) => -33)

(facts "cutify"
(facts "3 cutify"
(cutify []) => ["<3"]
(cutify [1 2 3]) => [1 2 3 "<3"]
(cutify ["a" "b"]) => ["a" "b" "<3"])

(facts "spiff-destructuring"
(facts "4 spiff-destructuring"
(spiff-destructuring [1 2 3]) => 4
(spiff-destructuring [1 2 -34 4 5 6]) => -33)

(facts "width"
(facts "5 width"
(width (rectangle [1 1] [5 1])) => 4
(width (rectangle [1 1] [1 1])) => 0
(width (rectangle [3 1] [10 4])) => 7)

(facts "height"
(facts "5 height"
(height (rectangle [1 1] [5 1])) => 0
(height (rectangle [1 1] [5 5])) => 4
(height (rectangle [0 0] [2 3])) => 3)

(facts "square?"
(facts "6 square?"
(square? (rectangle [1 1] [2 2])) => true
(square? (rectangle [1 1] [2 3])) => false
(square? (rectangle [1 1] [1 1])) => true
(square? (rectangle [3 2] [1 0])) => true
(square? (rectangle [3 2] [1 1])) => false)

(facts "area"
(facts "7 area"
(area (rectangle [1 1] [5 1])) => 0
(area (rectangle [0 0] [1 1])) => 1
(area (rectangle [0 0] [4 3])) => 12
(area (rectangle [3 1] [10 4])) => 21)

(facts "contains-point?"
(facts "8 contains-point?"
(contains-point? (rectangle [0 0] [2 2])
(point 1 1)) => true
(contains-point? (rectangle [0 0] [2 2])
Expand All @@ -57,7 +57,7 @@
(contains-point? (rectangle [1 1] [1 1])
(point 1 1)) => true)

(facts "contains-rectangle?"
(facts "9 contains-rectangle?"
(contains-rectangle? (rectangle [0 0] [3 3])
(rectangle [1 1] [2 2])) => true
(contains-rectangle? (rectangle [0 0] [2 2])
Expand Down Expand Up @@ -95,22 +95,22 @@
:authors [friedman, felleisen]}
books [cities, wild-seed, embassytown, little-schemer]]

(facts "title-length"
(facts "10 title-length"
(title-length cities) => 21
(title-length wild-seed) => 9
(title-length little-schemer) => 18)

(facts "author-count"
(facts "11 author-count"
(author-count cities) => 1
(author-count wild-seed) => 1
(author-count little-schemer) => 2)

(facts "multiple-authors?"
(facts "12 multiple-authors?"
(multiple-authors? cities) => false
(multiple-authors? wild-seed) => false
(multiple-authors? little-schemer) => true)

(facts "add-author"
(facts "13 add-author"
(add-author little-schemer {:name "Gerald J. Sussman"})
=> {:title "The Little Schemer"
:authors [{:birth-year 1944, :name "Daniel Friedman"}
Expand All @@ -119,48 +119,48 @@
(add-author {:authors [{:name "Juhana"}]} {:name "Jani"})
=> {:authors [{:name "Juhana"} {:name "Jani"}]})

(facts "alive?"
(facts "14 alive?"
(alive? china) => true
(alive? octavia) => false)

(facts "element-lengths"
(facts "15 element-lengths"
(element-lengths ["foo" "bar" "" "quux"]) => [3 3 0 4]
(element-lengths ["x" [:a :b :c] {:y 42}]) => [1 3 1])

(facts "second-elements"
(facts "16 second-elements"
(second-elements [[1 2] [2 3] [3 4]]) => [2 3 4]
(second-elements [[1 2 3 4] [1] ["a" "s" "d" "f"]]) => [2 nil "s"])

(facts "titles"
(facts "17 titles"
(titles [cities]) => ["The City and the City"]
(titles books) => (just ["The City and the City"
"Wild Seed"
"Embassytown"
"The Little Schemer"]
:in-any-order)))

(facts "monotonic?"
(facts "18 stars"
(stars 1) => "*"
(stars 7) => "*******"
(stars 3) => "***")

(facts "19 monotonic?"
(monotonic? [1 2 3]) => true
(monotonic? [0 1 10 11]) => true
(monotonic? [3 2 0 -3]) => true
(monotonic? [3 2 2]) => true
(monotonic? [1 2 1 0]) => false)

(facts "stars"
(stars 1) => "*"
(stars 7) => "*******"
(stars 3) => "***")

(facts "toggle"
(facts "20 toggle"
(toggle #{:a :b :c} :d) => #{:a :b :c :d}
(toggle #{:a :b :c} :a) => #{:b :c})

(facts "contains-duplicates?"
(facts "21 contains-duplicates?"
(contains-duplicates? [1 1 2 3 -40]) => true
(contains-duplicates? [1 2 3 -40]) => false
(contains-duplicates? [1 2 3 "a" "a"]) => true)

(facts "old-book->new-book"
(facts "22 old-book->new-book"
(old-book->new-book {:title "The Little Schemer"
:authors [friedman, felleisen]})
=> {:title "The Little Schemer" :authors #{friedman, felleisen}}
Expand Down Expand Up @@ -193,31 +193,31 @@

books [cities, wild-seed, embassytown, little-schemer]]

(facts "has-author?"
(facts "23 has-author?"
(has-author? cities china) => true
(has-author? cities felleisen) => false
(has-author? little-schemer felleisen) => true
(has-author? little-schemer friedman) => true
(has-author? little-schemer octavia) => false)

(facts "authors"
(facts "24 authors"
(authors [cities, wild-seed]) => #{china, octavia}
(authors [cities, wild-seed, embassytown]) => #{china, octavia}
(authors [little-schemer, cities]) => #{china, friedman, felleisen})

(facts "all-author-names"
(facts "25 all-author-names"
(all-author-names []) => #{}
(all-author-names [cities, wild-seed])
=> #{"China Miéville" "Octavia E. Butler"}
(all-author-names books)
=> #{"Matthias Felleisen" "China Miéville"
"Octavia E. Butler" "Daniel Friedman"})
(facts "author->string"
(facts "26 author->string"
(author->string felleisen) => "Matthias Felleisen"
(author->string friedman) => "Daniel Friedman (1944 - )"
(author->string octavia) => "Octavia E. Butler (1947 - 2006)")

(facts "authors->string"
(facts "27 authors->string"
(authors->string (:authors little-schemer))
=> (every-checker (contains "Daniel Friedman (1944 - )")
(contains "Matthias Felleisen")
Expand All @@ -229,43 +229,43 @@
(contains "Daniel Friedman (1944 - )")
(contains ", ")))

(facts "book->string"
(facts "28 book->string"
(book->string wild-seed)
=> "Wild Seed, written by Octavia E. Butler (1947 - 2006)"
(book->string little-schemer)
=> (every-checker (has-prefix "The Little Schemer, written by ")
(has-suffix #"Daniel Friedman \(1944 - \), Matthias Felleisen|Matthias Felleisen, Daniel Friedman \(1944 - \)")))

(facts "books->string"
(facts "29 books->string"
(books->string []) => "No books."
(books->string [cities])
=> "1 book. The City and the City, written by China Miéville (1972 - )."
(books->string [little-schemer, cities, wild-seed])
=> #"3 books. The Little Schemer, written by (Daniel Friedman \(1944 - \), Matthias Felleisen|Matthias Felleisen, Daniel Friedman \(1944 - \)). The City and the City, written by China Miéville \(1972 - \). Wild Seed, written by Octavia E. Butler \(1947 - 2006\).")

(facts "books-by-author"
(facts "30 books-by-author"
(books-by-author china books) => (just [cities embassytown])
(books-by-author octavia books) => (just [wild-seed]))

(facts "author-by-name"
(facts "31 author-by-name"
(author-by-name "Octavia E. Butler" authors-set) => octavia
(author-by-name "Octavia E. Butler" #{felleisen, friedman}) => nil
(author-by-name "China Miéville" authors-set) => china
(author-by-name "Goerge R. R. Martin" authors-set) => nil)

(facts "living-authors"
(facts "32 living-authors"
(living-authors authors-set) => (just #{china, felleisen, friedman})
(living-authors #{octavia}) => (just #{})
(living-authors #{china, felleisen}) => (just #{china, felleisen}))

(facts "has-a-living-author?"
(facts "33 has-a-living-author?"
(has-a-living-author? wild-seed) => false
(has-a-living-author? silmarillion) => true
(has-a-living-author? little-schemer) => true
(has-a-living-author? cities) => true
(has-a-living-author? deus-irae) => false)

(facts "books-by-living-authors"
(facts "34 books-by-living-authors"
(books-by-living-authors books) => (just #{little-schemer cities embassytown})
(books-by-living-authors (concat books [deus-irae, silmarillion]))
=> (just #{little-schemer cities embassytown silmarillion})))

0 comments on commit 9678110

Please sign in to comment.