mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-05 04:44:12 +03:00
85 lines
3.1 KiB
Plaintext
85 lines
3.1 KiB
Plaintext
(Debug.sanitize-addresses)
|
|
|
|
(load "Test.carp")
|
|
(load "Vector.carp")
|
|
(load "Geometry.carp")
|
|
|
|
(use-all Test VectorN Geometry Double)
|
|
|
|
(deftest test
|
|
(assert-equal test
|
|
&(init 4 [0.0 0.0 0.0 0.0]) &(zero-sized 4)
|
|
"zero-sized works")
|
|
(assert-equal test
|
|
&(init 4 [1.0 2.0 3.0 4.0]) &(init 4 [1.0 2.0 3.0 4.0])
|
|
"= operator works")
|
|
(assert-op test
|
|
&(init 4 [1.0 2.0 3.0 4.0]) &(init 4 [1.0 1.0 3.0 4.0])
|
|
"/= operator works"
|
|
VectorN./=)
|
|
(assert-equal test
|
|
&(init 3 [3.0 3.0 4.5])
|
|
&(Maybe.unsafe-from
|
|
(add &(init 3 [2.0 1.0 2.0]) &(init 3 [1.0 2.0 2.5])))
|
|
"add operator works")
|
|
(assert-nothing test
|
|
&(add &(init 1 [2.0]) &(init 2 [1.0 2.0]))
|
|
"add operator works on wrong magnitudes")
|
|
(assert-equal test
|
|
&(init 3 [1.0 -1.0 -1.5])
|
|
&(Maybe.unsafe-from
|
|
(sub &(init 3 [2.0 1.0 2.0]) &(init 3 [1.0 2.0 3.5])))
|
|
"sub operator works")
|
|
(assert-nothing test
|
|
&(sub &(init 1 [2.0]) &(init 2 [1.0 2.0]))
|
|
"sub operator works on wrong magnitudes")
|
|
(assert-equal test
|
|
&(init 3 [4.0 2.0 2.2])
|
|
&(mul &(init 3 [2.0 1.0 1.1]) 2.0)
|
|
"mul operator works")
|
|
(assert-equal test
|
|
&(init 3 [1.0 0.5 0.25])
|
|
&(div &(init 3 [2.0 1.0 0.5]) 2.0)
|
|
"div operator works")
|
|
(assert-equal test
|
|
5.0
|
|
(mag &(init 3 [3.0 4.0 0.0]))
|
|
"mag works")
|
|
(assert-equal test
|
|
101.0
|
|
(mag-sq &(init 3 [10.0 1.0 0.0]))
|
|
"mag-sq works")
|
|
(assert-equal test
|
|
&(init 3 [0.6 0.8 0.0])
|
|
&(normalize &(init 3 [3.0 4.0 0.0]))
|
|
"normalize works")
|
|
(assert-op test
|
|
90.0
|
|
(radians-to-degree
|
|
(Maybe.unsafe-from (angle-between &(init 3 [1.0 0.0 0.0])
|
|
&(init 3 [0.0 1.0 0.0]))))
|
|
"angle-between works"
|
|
Double.approx)
|
|
(assert-true test
|
|
(Maybe.unsafe-from (anti-parallel? &(init 4 [1.0 0.0 0.0 0.0])
|
|
&(init 4 [-1.0 0.0 0.0 0.0])))
|
|
"anti-parallel? works")
|
|
(assert-true test
|
|
(Maybe.unsafe-from (parallel? &(init 4 [1.0 0.0 0.0 0.0])
|
|
&(init 4 [1.0 0.0 0.0 0.0])))
|
|
"parallel? works")
|
|
(assert-true test
|
|
(Maybe.unsafe-from (perpendicular? &(init 4 [1.0 0.0 0.0 0.0])
|
|
&(init 4 [0.0 0.0 1.0 0.0])))
|
|
"perpendicular? works")
|
|
(assert-equal test
|
|
53.0
|
|
(Maybe.unsafe-from (dot &(init 3 [10.0 2.0 3.0])
|
|
&(init 3 [2.0 12.0 3.0])))
|
|
"dot works")
|
|
(assert-equal test
|
|
&(init 1 [2.0])
|
|
&(Maybe.unsafe-from (vlerp &(init 1 [0.0]) &(init 1 [5.0]) 0.4))
|
|
"vlerp works")
|
|
)
|