Skip to content

Commit

Permalink
add test for unit vector
Browse files Browse the repository at this point in the history
  • Loading branch information
prakhar1989 committed Feb 2, 2017
1 parent 56d1118 commit e26252f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions test/cljc/snippets/math/random.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@
(q/random-seed 42)
(q/text (str "(q/random 42) = " (q/random 42)) 10 20))

(defn- unit-vector? [v]
(let [n (->> v (map q/sq) (apply +))]
(< (Math/abs (- n 1.0)) 0.001)))

(defsnippet random-2d {}
(q/background 255)
(q/fill 0)
(q/text (str "(q/random-2d) = " (q/random-2d)) 10 20))
(q/background 255)
(q/fill 0)
(q/text (str "unit 2D vector? " (unit-vector? (q/random-2d))) 10 20))

This comment has been minimized.

Copy link
@nbeloglazov

nbeloglazov Feb 2, 2017

Member

Actually, can you leave original version as it is and maybe add 2 new tests like

(deftest random-2d-returns-unit-vector
   ; 100 times generate 2d and check it's unit vector
 )

This way test can actually fail. Because in current "visual" tests they cannot fail if result is wrong.


(defsnippet random-3d {}
(q/background 255)
(q/fill 0)
(q/text (str "(q/random-3d) = " (q/random-3d)) 10 20))
(q/text (str "unit 3D vector? " (unit-vector? (q/random-3d))) 10 20))

0 comments on commit e26252f

Please sign in to comment.