Permalink
Browse files

make tests data-oriented, take advantage of laziness

  • Loading branch information...
1 parent c958cd1 commit 985e7ab285a28dac88da8790197236fb40d66b87 @stuarthalloway committed Jul 20, 2009
Showing with 9 additions and 23 deletions.
  1. +9 −23 test/test/bowling_game.clj
View
@@ -2,20 +2,6 @@
(:use clojure.test)
(:use bowling-game))
-(defn roll-list [game list]
- (if (empty? list)
- game
- (roll-list (roll game (first list)) (rest list))
- ))
-
-(defn roll-many [game n pins]
- (loop [i n g game]
- (if (zero? i)
- g
- (recur (dec i) (roll g pins)))))
-
-(defn gutter-game [game] (roll-many game 20 0))
-
(deftest can-create-game
(is (not (nil? (new-game)))))
@@ -32,19 +18,19 @@
(deftest test-score-frames-for-various-games
(are [description expected-scores game] (= expected-scores (score-frames game))
- "gutter game" (repeat 10 0) (repeat 20 0)
- "all ones" (repeat 10 2) (repeat 20 1)
- "all fives (spares)" (repeat 10 15) (repeat 21 5)
- "all tens (strikes)" (repeat 10 30) (repeat 22 10)
+ "gutter game" (repeat 10 0) (repeat 0)
+ "all ones" (repeat 10 2) (repeat 1)
+ "all fives (spares)" (repeat 10 15) (repeat 5)
+ "all tens (strikes)" (repeat 10 30) (repeat 10)
))
(deftest test-various-games
(are [description expected-score game] (= expected-score (score game))
- "gutter game" 0 (gutter-game (new-game))
- "all ones" 20 (roll-many (new-game) 20 1)
- "one space" 16 (roll-many (roll-list (new-game) [5 5 3]) 17 0)
- "one strike" 24 (roll-many (roll-list (new-game) [10 3 4]) 16 0)
- "perfect game" 300 (roll-many (new-game) 12 10)
+ "gutter game" 0 (repeat 0)
+ "all ones" 20 (repeat 1)
+ "one spare" 16 (concat [5 5 3] (repeat 0))
+ "one strike" 24 (concat [10 3 4] (repeat 0))
+ "perfect game" 300 (repeat 10)
))

0 comments on commit 985e7ab

Please sign in to comment.