Carp/lisp/array_tests.carp

105 lines
1.6 KiB
Plaintext
Raw Normal View History

2016-02-26 11:13:08 +03:00
2016-02-26 11:14:47 +03:00
;; Generic Arrays
(defn get-a-float [xs]
(* 2.0f (nth xs 0)))
(defn test-get-a-float []
(do (bake get-a-float)))
(test-get-a-float)
(defn array-literal []
[10 20 30])
(defn test-array-literal []
(bake array-literal))
(test-array-literal)
2016-02-26 11:14:47 +03:00
2016-02-26 11:13:08 +03:00
(defn get-a-float [xs]
(* 2.0f (nth xs 0)))
(defn test-get-a-float []
(do
(bake get-a-float)))
2016-02-26 11:13:08 +03:00
(defn test-int-array []
(+ 100 (nth (array-of-size 3) 0)))
;; (test-int-array) ;; FAILS...
2016-02-26 11:13:08 +03:00
(defn small-array []
(let [a (array-of-size 3)
b (array-set a 0 10)
c (array-set b 1 20)
d (array-set c 2 30)]
d))
(bake small-array)
2016-02-26 11:13:08 +03:00
;; (def small-ast (lambda-to-ast (code small-array)))
;; (def small-con (gencon small-ast))
;; (def small-sol (solve-constraints small-con))
;; (def small-asta (annotate-ast small-ast))
(defn small-array-2 []
(array-set
2016-02-26 11:13:08 +03:00
(array-set
(array-set
(array-of-size 3)
0 10)
1 20)
2 30))
2016-02-26 11:13:08 +03:00
(bake small-array-2)
2016-02-26 11:13:08 +03:00
;; (def small-2-ast (lambda-to-ast (code small-array-2)))
;; (def small-2-con (gencon small-2-ast))
;; (def small-2-sol (solve-constraints small-2-con))
;; (def small-2-asta (annotate-ast small-2-ast))
(defn array-literal []
[10 20 30])
(bake array-literal)
2016-02-26 11:13:08 +03:00
(defn array-literal-2 []
[10.1 20.7 30.2])
(bake array-literal-2)
2016-02-26 16:18:46 +03:00
(defn array-of-arrays []
[(array-literal) (array-literal)])
2016-02-26 16:18:46 +03:00
(bake array-of-arrays)
2016-02-27 02:02:13 +03:00
(defstruct Vector
[x :int
y :int])
(defn test-print-array-of-vector []
(let [vecs [(Vector 1001 1002)
(Vector 1003 1004)
(Vector 1005 1006)]]
(assert-eq "[(Vector 1001 1002) (Vector 1003 1004) (Vector 1005 1006)]" (str vecs))))
(test-print-array-of-vector)