diff --git a/src/footpad/generate.clj b/src/footpad/generate.clj new file mode 100644 index 0000000..bcaba8a --- /dev/null +++ b/src/footpad/generate.clj @@ -0,0 +1,32 @@ +(ns footpad.generate) + +(defstruct point :type :xloc :yloc) + +;; Make it easier to refer to the types of characters +;; that we deal with. +(def game-chars {:rock \# + :up \> + :down \< + :space \space}) + +(defn print-out [ p ] + ((:type p) game-chars)) + +(defn pad-spaces [amount] + (take amount (repeat (:space game-chars)))) + +(defn add-point [coll p] + (concat + coll + (pad-spaces (- (:xloc p) (count coll))) + (list ((:type p) game-chars)))) + +(defn to-points [ coll ] + (if (zero? (mod (count coll) 2)) + (map #(apply struct point %1 ) (partition 2 coll)))) + +;; (defn full-wall [ s ] +;; (map #(struct point % :rock) (range 0 s))) + +(defn print-game-line [ coll ] + (String. (char-array (reduce add-point () (to-points coll))))) diff --git a/test/footpad/generate_test.clj b/test/footpad/generate_test.clj new file mode 100644 index 0000000..dfb6bbb --- /dev/null +++ b/test/footpad/generate_test.clj @@ -0,0 +1,26 @@ +(ns footpad.generate-test + (:use footpad.generate + clojure.test :reload)) + + +(deftest padding + (testing "Zero padding" + (= () (pad-spaces 0))) + (testing "Other cases" + (= (list \space) (pad-spaces 1)) + (= (list \space \space) (pad-spaces 2)))) + +(deftest adding + (testing "Simple case" + (= (list \#) (add-point () (struct point :rock 0))) + ) + (testing "Padded case" + (= (list \space \space \#) (add-point () (struct point :rock 2)))) + (testing "Pre-populated list" + (= (list \# \space \space \space \>) (add-point (list \#) (struct point :up 4)))) + ) + +(deftest converting + (testing "Simple case" + (= (list (struct point :rock 2) (struct point :up 6)) + (to-points [:rock 2 :up 6]))))