Login
7 branches 0 tags
Ben (X13/Arch) Simplified things a little 0643405 9 days ago 1260 Commits
nujel / tests / testsuite / arrays.nuj
("##(2 3 4)" (string/write (-> [1 2 3 4] (delete 1))))
("##(1 2 3 #nil)" (string/write (array/push [1 2 3])))
("##(1 2 3 \"4\")" (string/write (array/push [1 2 3] "4")))
("##(1 2 3 4)" (string/write (array/push [1 2 3] 4)))
("##(1 2 3 5.2)" (string/write (array/push [1 2 3] 5.2)))
(0 (:length []))
(1 (:length [1]))
(4 (:length [1 2 3 4]))
(2 (ref [1 2 3 4] 1))
(3 (:length (:alloc Array 3)))
(#t (array/equal? [1 2 3] [1 2 3]))
(#f (array/equal? [2 2 3] [1 2 3]))
(#f (array/equal? [1 2 3] [1 2 3 4]))
(#f (array/equal? [1 2 3 4] [1 2 3]))
(#t (array/equal? [1.0 2.0 3.0] [1.0 2.0 3.0]))
(#t (array/equal? [:a :b :c] [:a :b :c]))
(#f (array/equal? [:a :b :c] [:a :b :d]))
(#f (array/equal? ["a" "b" "c"] ["a" "b" "d"]))
(#t (array/equal? ["a" "b" "c"] ["a" "b" "c"]))
(#t (array? [1 2 3]))
(#t (array? (:alloc Array 3)))
(#f (array? '(1 2 3)))
(#f (array? {:a 1 :b 2 :c 3}))
(:type-error (try car (def ein-test-arr [1 2 3]) (ref ein-test-arr 2.2)))
([99 2 3 4] (let ((cur-arr [1 2 3 4])) (set! cur-arr 0 99) cur-arr))
([42 42 42 42 42 42] (array/fill! (:alloc Array 6) 42))
(3 (def ein-test-arr [1 2 3]) (ref ein-test-arr 2))
(2 (def ein-test-arr [1 2 3]) (ref ein-test-arr 1))
(:out-of-bounds (try car (def testerle [1 2 3]) (ref testerle 4)))
(:out-of-bounds (try car (def testerle [1 2 3]) (ref testerle 40000)))
([1 2 3] (def testerle [1 2 3]) testerle)
(:type-error (try car (def testerle [1 2 3]) (ref testerle #t)))
(1 (ref [1 2 3] 0))
(2 (def arr [1 2 3]) (:length! arr 2) (:length arr))
(3 (def arr [1 2 3]) (:length! arr 2) (reduce arr + 0))
("##(2 4)" (string/write (filter [1 2 3 4] even?)))
("##(0 0 0)" (string/write (-> (:alloc Array 3) (array/fill! 0))))
("##(3 9 0)" (string/write (-> (:alloc Array 3) (array/fill! 0) (set! 1 9) (set! 0 3))))
(10 (def arr [1 2 3]) (:length! arr 4) (set! arr 3 4) (reduce arr + 0))
(10 (-> [1 2 3] (:length! 4) (set! 3 4) (reduce + 0)))
("##(#nil)" (string/write (set! [1] 0 #nil)))
("##(2)" (string/write (set! [1] 0 2)))
("##(#t)" (string/write (set! [1] 0 #t)))
("##(#f)" (string/write (set! [1] 0 #f)))
("##(1 2 3 4)" (string/write (array/append [1 2] [3 4])))
("##(1 2 3)" (string/write (array/append [1 2] [3])))
("##(1 2)" (string/write (array/append [1 2] [])))
(:type-error (try car (array/append [1] '(2))))
(:type-error (try car (array/append '(1) #nil)))
(:type-error (try car (array/append [1])))
(:type-error (try car (array/append '(1))))
(:type-error (try car (array/append)))
("##(1 2 3)" (string/write (let ((o [2 2 3])) (set! o 0 1) (set! (array/dup o) 0 3) o)))
(#f (= [1] [1]))
(#f (= [1] [2]))
(#t (let ((a [1])) (= a a)))
(#t (:has? [1 2 3] 0))
(#t (:has? [1 2 3] 2))
(#f (:has? [1 2 3] 3))
(#f (:has? [1 2 3] -1))
(#f (:has? [] 0))