2018-02-05 12:49:35 +03:00
|
|
|
(Debug.sanitize-addresses)
|
|
|
|
|
2017-11-21 14:01:31 +03:00
|
|
|
(load "Test.carp")
|
|
|
|
(load "Vector.carp")
|
|
|
|
(load "Geometry.carp")
|
|
|
|
|
2017-12-12 17:08:33 +03:00
|
|
|
(use-all Test VectorN Geometry Double)
|
2017-10-24 17:05:17 +03:00
|
|
|
|
2018-11-07 18:11:38 +03:00
|
|
|
(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"
|
Various submodule fixes (#1078)
* fix: don't set the inner env to globals in type mods
Previously, we set the inner environment of a type generated module to
the global env in cases where the overarching context didn't have an
inner env. This leads to problems where by the recognition of modules is
inconsistent, and one can't use the names of types as submodules in
certain circumstances.
This commit fixes that issue.
* refactor: refactor primitiveDefmodule
This refactor fixes a issues with meta information on submodules, for
instance, sigs on submodule functions used to result in a compiler error
about ambiguous identifiers. This fixes that.
Unfortunately, I don't have a precise idea about what exactly was wrong
with the original definition of this function. My suspicion is that the
recursion originally altered submodule paths in the wrong way, but I'm
not certain. In any case it's fixed.
* fix: ensure macros are expanded in the correct module
Previously, macro expansions folded over all forms after the top level
form, without performing any context updates on encountered
`defmodules`. This created an issue in which macro calls that produced
new bindings, "meta stubs", were *hoisted* out of submodules and into
the top-level module, creating duplicate definitions.
This commit fixes that issue by adding a special case for defmodule in
macroExpand.
* fix: ensure submodules and globals don't conflict
Previously, our module lookups during new module definition always
eventually fell back to the global environment, which caused submodules
that happen to share a name with a global module to be confused with the
global module. This change fixes that, so now one can define both
`Dynamic` (global) and `Foo.Dynamic` without issue.
* fix: remove old prefixes from vector tests
Commit 7b7cb5d1e replaced /= with a generic function. However, the
vector tests still called the specific Vector variants of this function,
which were removed when the generic was introduced. After recent
changes, these calls are now (correctly) identified as erroneous. My
guess is that they only worked in the past because of problems with our
lookups.
* chore: format code
2020-12-18 23:45:28 +03:00
|
|
|
/=)
|
2018-11-07 18:11:38 +03:00
|
|
|
(assert-equal test
|
|
|
|
&(init 3 [3.0 3.0 4.5])
|
2019-02-11 13:39:03 +03:00
|
|
|
&(Maybe.unsafe-from
|
|
|
|
(add &(init 3 [2.0 1.0 2.0]) &(init 3 [1.0 2.0 2.5])))
|
2018-11-07 18:11:38 +03:00
|
|
|
"add operator works")
|
2020-05-12 15:53:42 +03:00
|
|
|
(assert-nothing test
|
|
|
|
&(add &(init 1 [2.0]) &(init 2 [1.0 2.0]))
|
|
|
|
"add operator works on wrong magnitudes")
|
2018-11-07 18:11:38 +03:00
|
|
|
(assert-equal test
|
|
|
|
&(init 3 [1.0 -1.0 -1.5])
|
2019-02-11 13:39:03 +03:00
|
|
|
&(Maybe.unsafe-from
|
|
|
|
(sub &(init 3 [2.0 1.0 2.0]) &(init 3 [1.0 2.0 3.5])))
|
2018-11-07 18:11:38 +03:00
|
|
|
"sub operator works")
|
2020-05-12 15:53:42 +03:00
|
|
|
(assert-nothing test
|
|
|
|
&(sub &(init 1 [2.0]) &(init 2 [1.0 2.0]))
|
|
|
|
"sub operator works on wrong magnitudes")
|
2018-11-07 18:11:38 +03:00
|
|
|
(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
|
2019-02-11 13:39:03 +03:00
|
|
|
(radians-to-degree
|
|
|
|
(Maybe.unsafe-from (angle-between &(init 3 [1.0 0.0 0.0])
|
|
|
|
&(init 3 [0.0 1.0 0.0]))))
|
2018-11-07 18:11:38 +03:00
|
|
|
"angle-between works"
|
|
|
|
Double.approx)
|
|
|
|
(assert-true test
|
2019-02-11 13:39:03 +03:00
|
|
|
(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])))
|
2018-11-07 18:11:38 +03:00
|
|
|
"anti-parallel? works")
|
|
|
|
(assert-true test
|
2019-02-11 13:39:03 +03:00
|
|
|
(Maybe.unsafe-from (parallel? &(init 4 [1.0 0.0 0.0 0.0])
|
|
|
|
&(init 4 [1.0 0.0 0.0 0.0])))
|
2018-11-07 18:11:38 +03:00
|
|
|
"parallel? works")
|
|
|
|
(assert-true test
|
2019-02-11 13:39:03 +03:00
|
|
|
(Maybe.unsafe-from (perpendicular? &(init 4 [1.0 0.0 0.0 0.0])
|
|
|
|
&(init 4 [0.0 0.0 1.0 0.0])))
|
2018-11-07 18:11:38 +03:00
|
|
|
"perpendicular? works")
|
|
|
|
(assert-equal test
|
|
|
|
53.0
|
2019-02-11 13:39:03 +03:00
|
|
|
(Maybe.unsafe-from (dot &(init 3 [10.0 2.0 3.0])
|
|
|
|
&(init 3 [2.0 12.0 3.0])))
|
2018-11-07 18:11:38 +03:00
|
|
|
"dot works")
|
|
|
|
(assert-equal test
|
|
|
|
&(init 1 [2.0])
|
2019-09-08 14:02:04 +03:00
|
|
|
&(Maybe.unsafe-from (vlerp &(init 1 [0.0]) &(init 1 [5.0]) 0.4))
|
|
|
|
"vlerp works")
|
2018-11-07 18:11:38 +03:00
|
|
|
)
|