diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-03-18 11:47:22 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-18 12:06:18 +0000 |
| commit | b6cbc69461dc054019f50f8971704f6ef9de63ab (patch) | |
| tree | d2b8942b780f668ccbe57b52dd8d65f61613e935 /spec/lib/math_spec.moon | |
| parent | builtins: switch takes single array as value (diff) | |
| download | alive-wip.tar.gz alive-wip.zip | |
language: [array] and {struct} literalswip
Diffstat (limited to 'spec/lib/math_spec.moon')
| -rw-r--r-- | spec/lib/math_spec.moon | 162 |
1 files changed, 80 insertions, 82 deletions
diff --git a/spec/lib/math_spec.moon b/spec/lib/math_spec.moon index 23a353b..40c7abd 100644 --- a/spec/lib/math_spec.moon +++ b/spec/lib/math_spec.moon @@ -88,85 +88,83 @@ describe "math", -> describe "add, sub, mul, div, pow, mod", -> it "handle scalar/vector", -> COPILOT\eval_once ' - (expect= (array 3 4 5) - (+ 1 (array 1 2 3) 1)) + (expect= [3 4 5] + (+ 1 [1 2 3] 1)) - (expect= (array 0 1 2) - (- (array 1 2 3) 1)) + (expect= [0 1 2] + (- [1 2 3] 1)) - (expect= (array 3 6 9) - (* 3 (array 1 2 3))) - (expect= (array 3 6 9) - (* (array 1 2 3) 3)) + (expect= [3 6 9] + (* 3 [1 2 3])) + (expect= [3 6 9] + (* [1 2 3] 3)) - (expect= (array 12 9 4) - (/ 36 (array 3 4 9))) + (expect= [12 9 4] + (/ 36 [3 4 9])) - (expect= (array 9 16 25) - (^ (array 3 4 5) 2)) - (expect= (array 1 2 4 8) - (^ 2 (array 0 1 2 3))) + (expect= [9 16 25] + (^ [3 4 5] 2)) + (expect= [1 2 4 8] + (^ 2 [0 1 2 3])) - (expect= (array 3 0 1) - (% (array 3 4 5) 4)) + (expect= [3 0 1] + (% [3 4 5] 4)) ' it "handle vector/vector and matrix/matrix", -> COPILOT\eval_once ' - (expect= (array 5 7 9) - (+ (array 1 2 3) - (array 4 5 6))) + (expect= [5 7 9] + (+ [1 2 3] + [4 5 6])) - (expect= (array (array 11 12) - (array 13 14)) + (expect= [[11 12] + [13 14]] (+ - (array (array 1 2) - (array 3 4)) + [[1 2] + [3 4]] 5 5)) - (expect= (array 2 0 -2) - (- (array 3 2 1) - (array 1 2 3))) + (expect= [2 0 -2] + (- [3 2 1] + [1 2 3])) - (expect= (array 1 -2 -3) - (- (array -1 2 3))) + (expect= [1 -2 -3] + (- [-1 2 3])) ' err = assert.has.error -> COPILOT\eval_once ' - (+ (array 1 2 3) - (array 1 2))' + (+ [1 2 3] + [1 2])' err = assert.has.error -> COPILOT\eval_once ' - (+ (array (array 1 2) (array 1 2)) - (array 1 2))' + (+ [[1 2] [1 2]] + [1 2])' err = assert.has.error -> COPILOT\eval_once ' - (- (array 1 2 3) - (array 1 2))' + (- [1 2 3] + [1 2])' err = assert.has.error -> COPILOT\eval_once ' - (- (array (array 1 2) (array 1 2)) - (array 1 2))' + (- [[1 2] [1 2]] + [1 2])' describe "mul", -> it "handles scalars and matrices", -> with COPILOT\eval_once ' (* 3 - (array - (array 1 2) - (array 4 5)))' + [[1 2] + [4 5]])' assert.is.true \is_const! assert.is.equal '<num[2][2]= [[3 6] [12 15]]>', tostring .result with COPILOT\eval_once ' - (* (array - (array 1 2) - (array 4 5)) + (* [[1 2] + [4 5]] 3)' assert.is.true \is_const! assert.is.equal '<num[2][2]= [[3 6] [12 15]]>', tostring .result @@ -174,90 +172,90 @@ describe "math", -> it "handles vectors and matrices", -> with COPILOT\eval_once ' (* - (array (array 1 0 0) - (array 0 1 0) - (array 0 0 1)) - (array 4 5 6))' + [[1 0 0] + [0 1 0] + [0 0 1]] + [4 5 6])' assert.is.true \is_const! assert.is.equal '<num[3]= [4 5 6]>', tostring .result with COPILOT\eval_once ' (* - (array (array 1 0 0) - (array 0 1 0) - (array 3 2 1)) - (array 4 5 1))' + [[1 0 0] + [0 1 0] + [3 2 1]] + [4 5 1])' assert.is.true \is_const! assert.is.equal '<num[3]= [4 5 23]>', tostring .result it "handles matrices", -> with COPILOT\eval_once ' (* - (array (array 1 2 3) - (array 4 5 6)) - (array (array 10 11) - (array 20 21) - (array 30 31)))' + [[1 2 3] + [4 5 6]] + [[10 11] + [20 21] + [30 31]])' assert.is.true \is_const! assert.is.equal '<num[2][2]= [[140 146] [320 335]]>', tostring .result it "handles everything mixed", -> with COPILOT\eval_once ' (* - (array (array 1 2 3) - (array 4 5 6)) + [[1 2 3] + [4 5 6]] 2 - (array (array 10 11) - (array 20 21) - (array 30 31)))' + [[10 11] + [20 21] + [30 31]])' assert.is.true \is_const! assert.is.equal '<num[2][2]= [[280 292] [640 670]]>', tostring .result with COPILOT\eval_once ' (* - (array (array 1 2 3) - (array 4 5 6)) + [[1 2 3] + [4 5 6]] 2 - (array (array 10 11) - (array 20 21) - (array 30 31)) - (array 4 7))' + [[10 11] + [20 21] + [30 31]] + [4 7])' assert.is.true \is_const! assert.is.equal '<num[2]= [3164 7250]>', tostring .result it "errors with wrong sizes (matrix and vector)", -> err = assert.has.error -> COPILOT\eval_once ' (* - (array (array 1 2 3) - (array 4 5 6)) - (array 1 2))' + [[1 2 3] + [4 5 6]] + [1 2])' -- assert.matches "", err err = assert.has.error -> COPILOT\eval_once ' (* - (array 1 2 3) - (array (array 1 2 3) - (array 4 5 6)))' + [1 2 3] + [[1 2 3] + [4 5 6]])' -- assert.matches "", err it "errors with wrong sizes (matrix)", -> err = assert.has.error -> COPILOT\eval_once ' (* - (array (array 1 2 3) - (array 4 5 6)) - (array (array 1 2) - (array 4 5)))' + [[1 2 3] + [4 5 6)] + [[1 2] + [4 5]])' -- assert.matches "", err it "min, max, clamp, huge", -> COPILOT\eval_once ' - (expect= (array 3 2 1) - (min (array 3 4 1) (array 5 2 huge))) - (expect= (array 5 huge 4) - (max (array 3 huge 4) (array 5 999 2))) + (expect= [3 2 1] + (min [3 4 1] [5 2 huge])) + (expect= [5 huge 4] + (max [3 huge 4] [5 999 2])) - (expect= (array -2 -1 0 1 3.5) - (clamp -2 3.5 (array -4 -1 0 1 4))) + (expect= [-2 -1 0 1 3.5] + (clamp -2 3.5 [-4 -1 0 1 4])) (expect= 1 (inc 0)) (expect= -1 (dec 0)) |
