Permalink
Browse files

Test cleanup.

  • Loading branch information...
1 parent 5ad28f4 commit 30dbd9745d527d0c63fb266c0aa0ee6661076a07 @lynaghk committed Apr 12, 2012
View
@@ -9,7 +9,9 @@
:profiles {:dev {:dependencies [[midje "1.3.1"]
[lein-midje "1.0.8"]
- [com.stuartsierra/lazytest "1.2.3"]]
+ [com.stuartsierra/lazytest "1.2.3"]
+
+ [com.keminglabs/vomnibus "0.3.0"]]
;;Required for lazytest.
:repositories {"stuartsierra-releases" "http://stuartsierra.com/maven2"
"stuartsierra-snapshots" "http://stuartsierra.com/m2snapshots"}}}
@@ -19,7 +21,12 @@
:source-paths ["src/clj" "src/cljs"
;;See src/cljx/README.markdown
- ".generated/clj" ".generated/cljs"]
+ ".generated/clj" ".generated/cljs"
+
+ ;;Uncomment & change accordingly if you want to build/test with a different version of ClojureScript besides what comes with cljsbuild.
+ ;;For details: https://github.com/emezeske/lein-cljsbuild/issues/58
+ ;;"../software/clojurescript/src/clj" "../software/clojurescript/src/cljs"
+ ]
:cljx {:builds [{:source-paths ["src/cljx"]
:output-path ".generated/clj"
@@ -31,12 +38,11 @@
:rules cljx.rules/cljs-rules}]}
- :cljsbuild {:builds {:test {:source-path "test/integration"
+ :cljsbuild {:builds {:test {:source-path "test/integration/cljs"
:compiler {:output-to "out/test/integration.js"
:optimizations :whitespace
:pretty-print true}}}
- :test-commands {"integration" ["phantomjs test/integration/runner.coffee"]}
- }
+ :test-commands {"integration" ["phantomjs test/integration/runner.coffee"]}}
;;generate cljx before JAR
@@ -0,0 +1,33 @@
+(ns c2.choropleth_test
+ (:use-macros [c2.util :only [p pp profile]])
+ (:use [c2.core :only [unify! style]]
+ [c2.maths :only [extent floor]]
+ [c2.geo.core :only [geo->svg]]
+ [c2.geo.projection :only [albers-usa]]
+ [vomnibus.geo.us.states :only [states]])
+ (:require [c2.scale :as scale]
+ [c2.dom :as dom]
+ [vomnibus.color-brewer :as color-brewer]))
+
+(profile "Drawing a sweet choropleth"
+ (let [data (into {} (map vector (keys states) (repeatedly rand)))
+
+ color-scheme color-brewer/Greens-9
+ color-scale (let [s (scale/linear :domain (extent (vals data))
+ :range [0 (dec (count color-scheme))])]
+ ;;todo: build interpolators so scales handle non-numeric ranges
+ (fn [d] (nth color-scheme (floor (s d)))))
+
+ proj (albers-usa)
+ $svg (dom/append! "body" [:svg {:xmlns "http://www.w3.org/2000/svg"
+ :preserveAspectRatio "xMinYMin meet"
+ :width 960 :height 400
+ :viewBox "0 0 950 500"}])
+ $states (dom/append! $svg [:g.states])]
+
+ (unify! $states data
+ (fn [[state-name val]]
+ [:path.state {:d (geo->svg (get states state-name)
+ :projection proj)
+ :stroke "black"
+ :fill (color-scale val)}]))))
@@ -1,11 +1,10 @@
(ns c2.core-test
- (:use-macros [c2.util :only [p profile]])
+ (:use-macros [c2.util :only [p pp profile]])
(:require [c2.svg :as svg])
(:use [c2.core :only [unify!]]
[c2.dom :only [attr children]]))
-(defn *print-fn* [x]
- (.log js/console x))
+(set! *print-fn* #(.log js/console %))
(def xhtml "http://www.w3.org/1999/xhtml")
@@ -32,7 +31,6 @@
(assert (= "span" (.toLowerCase (.-nodeName fel))))
(assert (= "0" (:x (attr fel)))))
-
(profile (str "UPDATE single tag, reversing order")
(unify! container (reverse (range n)) mapping))
(let [children (children container)
@@ -77,10 +75,4 @@
(clear!)
-
-;;Axis component
-(let [s #(* 10 %)]
- (svg/axis svg-container s
- :ticks [1 2 3]))
-
(print "\n\nHurray, no errors!")
@@ -0,0 +1,32 @@
+(ns c2.dom-test
+ (:use-macros [c2.util :only [p pp profile]])
+ (:use [c2.dom :only [attr build-dom-elem]]))
+
+(set! *print-fn* #(.log js/console %))
+
+(def xhtml "http://www.w3.org/1999/xhtml")
+
+(def container (.createElementNS js/document xhtml "div"))
+;;Appending to html instead of body here because of PhantomJS page.injectJs() wonky behavior
+(.appendChild (.querySelector js/document "html") container)
+
+(defn clear! [] (set! (.-innerHTML container) ""))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;Attribute reading & writing
+(assert (= nil (attr container :x)))
+(attr container :x 1)
+(assert (= "1" (attr container :x)))
+(attr container {:y 2 :z 3})
+(assert (= {:x "1" :y "2" :z "3"} (attr container)))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;DOM Element creation from vectors
+(assert (= "<p><span>hello</span><i>0</i><i>1</i><i>2</i></p>"
+ (.-outerHTML (build-dom-elem [:p [:span "hello"]
+ (map #(vector :i %) (range 3))]))))
+
+
+(clear!)
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang='en'>
<body> </body>
- <script src="../../out/integration_tests.js"></script>
+ <script src="../../out/test/integration.js"></script>
</html>

0 comments on commit 30dbd97

Please sign in to comment.