2020-04-29 11:39:15 +03:00
|
|
|
(load "Test.carp")
|
|
|
|
(use Test)
|
2020-05-02 15:18:14 +03:00
|
|
|
(use StaticArray)
|
2020-04-29 11:39:15 +03:00
|
|
|
|
|
|
|
(deftest test
|
|
|
|
|
|
|
|
(assert-true test
|
|
|
|
(= $[1 2 3] $[1 2 3])
|
|
|
|
"= works as expected I")
|
|
|
|
|
|
|
|
(assert-false test
|
|
|
|
(= $[1 2 3] $[1 2 3 4 5])
|
|
|
|
"= works as expected II")
|
|
|
|
|
|
|
|
(assert-false test
|
|
|
|
(= $[1 1 1] $[0 0 0])
|
|
|
|
"= works as expected III")
|
|
|
|
|
2020-04-29 11:54:41 +03:00
|
|
|
(assert-equal test
|
|
|
|
5
|
|
|
|
(let [a $[0 1 2 3 4 5 6 7 8 9]]
|
|
|
|
@(unsafe-nth a 5))
|
|
|
|
"unsafe-nth works as expected")
|
|
|
|
|
|
|
|
;; TODO: FIX! THIS ONE IS PROBLEMATIC.
|
|
|
|
;; (assert-equal test
|
|
|
|
;; &[4 5 6]
|
|
|
|
;; (let [nested $[[1 2 3]
|
|
|
|
;; [4 5 6]
|
|
|
|
;; [7 8 9]]]
|
|
|
|
;; &@(unsafe-nth nested 1))
|
|
|
|
;; "unsafe-nth works as expected")
|
|
|
|
|
2020-05-02 15:18:14 +03:00
|
|
|
(assert-equal test
|
|
|
|
10
|
|
|
|
(let [arr $[2 2 2 2]]
|
|
|
|
(reduce
|
|
|
|
&(fn [acc val] (+ acc @val))
|
|
|
|
2
|
|
|
|
arr))
|
|
|
|
"reduce works as expected")
|
|
|
|
|
|
|
|
(assert-equal test
|
|
|
|
$[2 4 8]
|
|
|
|
(let-do [arr $[1 2 4]]
|
|
|
|
(map!
|
|
|
|
arr
|
|
|
|
&(fn [val] (* @val 2)))
|
|
|
|
arr)
|
|
|
|
"map! works as expected"))
|
|
|
|
|