Created
September 19, 2011 12:47
-
-
Save marick/1226430 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns scratch.core | |
(:use midje.sweet | |
[clojure.set :only [union intersection]] | |
:reload)) | |
(unfinished newborns) | |
(defn survivable? [cell living-cells]) | |
;; (fact "A cell is survivable if 2 or 3 of its neighbors are alive" | |
;; (survivable? ..cell.. ..living-cells..) => truthy | |
;; (provided | |
;; (intersection (neighborhood ..cell..) ..living-cells..) => ...living-cells-in-that-neighborhood..) | |
(defn survivors [living-cells] | |
(map (fn [cell] (survivable? cell living-cells)) | |
living-cells)) | |
(defn tick [living-cells] | |
(union (set (newborns living-cells)) | |
(set (survivors living-cells)))) | |
;.;. For every disciplined effort, there is a multiple reward. -- Rohn | |
(fact "the tick produces newborn cells and surviving cells" | |
(tick ..living-cells..) => (just [..newborn.. ..survivor..] | |
:in-any-order) | |
(provided | |
(newborns ..living-cells..) => [..newborn.. ..survivor..] | |
(survivors ..living-cells..) => [..survivor..])) | |
(defn generations [living-cells] | |
(rest (iterate tick living-cells))) | |
(fact "generations are produced by the tick function" | |
(first (generations ..living-cells..)) => ..generation-1.. | |
(provided | |
(tick ..living-cells..) => ..generation-1..) | |
(second (generations ..living-cells..)) => ..generation-2.. | |
(provided | |
(tick (tick ..living-cells..)) => ..generation-2..)) | |
(future-fact "blinkers blink") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment