🎉 Add tests build.

This commit is contained in:
Andrey Antukh 2020-04-30 10:08:36 +02:00 committed by Alonso Torres
parent c2847bec4d
commit 24f2f3b677
5 changed files with 11 additions and 153 deletions

View file

@ -1,22 +0,0 @@
(ns uxbox.tests.main
(:require [cljs.test :as test]
[uxbox.tests.test-util-geom]
[uxbox.tests.test-main-data-shapes-impl]))
(enable-console-print!)
(defn main
[]
(test/run-tests
(test/empty-env)
'uxbox.tests.test-util-geom
'uxbox.tests.test-main-data-shapes-impl
))
(defmethod test/report [:cljs.test/default :end-run-tests]
[m]
(if (test/successful? m)
(set! (.-exitCode js/process) 0)
(set! (.-exitCode js/process) 1)))
(set! *main-cli-fn* main)

View file

@ -1,126 +0,0 @@
(ns uxbox.tests.test-main-data-shapes-impl
#_(:require [cljs.test :as t :include-macros true]
[cljs.pprint :refer [pprint]]
[uxbox.util.uuid :as uuid]
[uxbox.main.data.shapes :as impl]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Duplicate (one shape)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (defn constantly-inc
;; [init]
;; (let [v (atom init)]
;; (fn [& args]
;; (let [result @v]
;; (swap! v inc)
;; result))))
;; ;; duplicate shape: duplicate simple shape
;; (t/deftest duplicate-shapes-test1
;; (let [initial {:pages {1 {:id 1 :shapes [1]}}
;; :shapes {1 {:id 1 :page 1 :name "a"}}}
;; expected (-> initial
;; (assoc-in [:pages 1 :shapes] [2 1])
;; (assoc-in [:shapes 2] {:id 2 :page 1 :name "a-copy-1"}))]
;; (with-redefs [uxbox.util.uuid/random (constantly 2)]
;; (let [result (impl/duplicate-shapes initial [1])]
;; ;; (pprint expected)
;; ;; (pprint result)
;; (t/is (= result expected))))))
;; ;; duplicate shape: duplicate inside group
;; (t/deftest duplicate-shapes-test2
;; (let [initial {:pages {1 {:id 1 :shapes [1]}}
;; :shapes {1 {:id 1 :name "1" :page 1
;; :type :group
;; :items [2 3]}
;; 2 {:id 2 :name "2" :page 1 :group 1}
;; 3 {:id 3 :name "3" :page 1 :group 1}}}
;; expected (-> initial
;; (assoc-in [:shapes 1 :items] [5 4 2 3])
;; (assoc-in [:shapes 4] {:id 4 :name "3-copy-1" :page 1 :group 1})
;; (assoc-in [:shapes 5] {:id 5 :name "2-copy-1" :page 1 :group 1}))]
;; (with-redefs [uxbox.util.uuid/random (constantly-inc 4)]
;; (let [result (impl/duplicate-shapes initial [2 3])]
;; ;; (pprint expected)
;; ;; (pprint result)
;; (t/is (= result expected))))))
;; ;; duplicate shape: duplicate mixed bag
;; (t/deftest duplicate-shapes-test3
;; (let [initial {:pages {1 {:id 1 :shapes [1 4]}}
;; :shapes {1 {:id 1 :name "1" :page 1
;; :type :group
;; :items [2 3]}
;; 2 {:id 2 :name "2" :page 1 :group 1}
;; 3 {:id 3 :name "3" :page 1 :group 1}
;; 4 {:id 4 :name "4" :page 1}}}
;; expected (-> initial
;; (assoc-in [:pages 1 :shapes] [6 5 1 4])
;; (assoc-in [:shapes 5] {:id 5 :name "4-copy-1" :page 1})
;; (assoc-in [:shapes 6] {:id 6 :name "3-copy-1" :page 1}))]
;; (with-redefs [uxbox.util.uuid/random (constantly-inc 5)]
;; (let [result (impl/duplicate-shapes initial [3 4])]
;; ;; (pprint expected)
;; ;; (pprint result)
;; (t/is (= result expected))))))
;; ;; duplicate shape: duplicate one group
;; (t/deftest duplicate-shapes-test4
;; (let [initial {:pages {1 {:id 1 :shapes [1]}}
;; :shapes {1 {:id 1
;; :name "1"
;; :page 1
;; :type :group
;; :items [2]}
;; 2 {:id 2
;; :name "2"
;; :page 1
;; :group 1}}}
;; expected (-> initial
;; (assoc-in [:pages 1 :shapes] [3 1])
;; (assoc-in [:shapes 3] {:id 3
;; :name "1-copy-1"
;; :page 1
;; :type :group
;; :items [4]})
;; (assoc-in [:shapes 4] {:id 4
;; :name "2-copy-1"
;; :page 1
;; :group 3}))]
;; (with-redefs [uxbox.util.uuid/random (constantly-inc 3)]
;; (let [result (impl/duplicate-shapes initial [1])]
;; ;; (pprint expected)
;; ;; (pprint result)
;; (t/is (= result expected))))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; Delete Shape
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; delete shape: delete from page
;; (t/deftest delete-shape-test1
;; (let [initial {:pages {1 {:id 1 :shapes [1 3 4]}}
;; :shapes {1 {:id 1 :page 1
;; :type :group
;; :items [2]}
;; 2 {:id 2 :page 1 :group 1}
;; 3 {:id 3 :page 1}
;; 4 {:id 4 :page 1}}}
;; shape (get-in initial [:shapes 4])
;; expected {:pages {1 {:id 1 :shapes [1 3]}}
;; :shapes {1 {:id 1 :page 1 :type :group :items [2]}
;; 2 {:id 2 :page 1 :group 1}
;; 3 {:id 3 :page 1}}}
;; result (impl/dissoc-shape initial shape)]
;; ;; (pprint expected)
;; ;; (pprint result)
;; (t/is (= result expected))))

View file

@ -1,85 +0,0 @@
(ns uxbox.tests.test-util-geom
(:require [cljs.test :as t :include-macros true]
[cljs.pprint :refer [pprint]]
;; [uxbox.util.geom.point-impl :as gpt2]
;; [uxbox.util.geom.matrix-impl :as gmt2]
[uxbox.util.geom.point :as gpt]
[uxbox.util.geom.matrix :as gmt]))
(t/deftest point-constructors-test
(let [p (gpt/point 1 2)]
(t/is (= (:x p) 1))
(t/is (= (:y p) 2)))
(let [p (gpt/point 1)]
(t/is (= (:x p) 1))
(t/is (= (:y p) 1)))
(let [p (gpt/point)]
(t/is (= (:x p) 0))
(t/is (= (:y p) 0))))
;; (t/deftest point-rotate-test
;; (let [p1 (gpt/point 10 0)
;; p2 (gpt/rotate p1 90)]
;; (t/is (= (:x p2) 0))
;; (t/is (= (:y p2) 10))))
(t/deftest point-add-test
(let [p1 (gpt/point 1 1)
p2 (gpt/point 2 2)
p3 (gpt/add p1 p2)]
(t/is (= (:x p3) 3))
(t/is (= (:y p3) 3))))
(t/deftest point-subtract-test
(let [p1 (gpt/point 3 3)
p2 (gpt/point 2 2)
p3 (gpt/subtract p1 p2)]
(t/is (= (:x p3) 1))
(t/is (= (:y p3) 1))))
(t/deftest point-distance-test
(let [p1 (gpt/point 0 0)
p2 (gpt/point 10 0)
d (gpt/distance p1 p2)]
(t/is (number? d))
(t/is (= d 10))))
(t/deftest point-length-test
(let [p1 (gpt/point 10 0)
ln (gpt/length p1)]
(t/is (number? ln))
(t/is (= ln 10))))
(t/deftest point-angle-test
(let [p1 (gpt/point 0 10)
angle (gpt/angle p1)]
(t/is (number? angle))
(t/is (= angle 90)))
(let [p1 (gpt/point 0 10)
p2 (gpt/point 10 10)
angle (gpt/angle-with-other p1 p2)]
(t/is (number? angle))
(t/is (= angle 45))))
(t/deftest matrix-constructors-test
(let [m (gmt/matrix)]
(t/is (= (str m) "matrix(1,0,0,1,0,0)")))
(let [m (gmt/matrix 1 1 1 2 2 2)]
(t/is (= (str m) "matrix(1,1,1,2,2,2)"))))
(t/deftest matrix-translate-test
(let [m (-> (gmt/matrix)
(gmt/translate (gpt/point 2 10)))]
(t/is (str m) "matrix(1,0,0,1,2,10)")))
(t/deftest matrix-scale-test
(let [m (-> (gmt/matrix)
(gmt/scale (gpt/point 2)))]
(t/is (str m) "matrix(2,0,0,2,0,0)")))
(t/deftest matrix-rotate-test
(let [m (-> (gmt/matrix)
(gmt/rotate 10))]
(t/is (str m) "matrix(0.984807753012208,0.17364817766693033,-0.17364817766693033,0.984807753012208,0,0)")))