Carp/test/control_flow.carp

58 lines
1.1 KiB
Plaintext
Raw Normal View History

2017-12-05 21:35:45 +03:00
(use Int)
(load "Test.carp")
(use Test)
(defn break-test []
(let [x 0]
(do
(while (< x 10)
(if (> x 4)
(break)
(set! &x (inc x))))
x)))
2017-12-12 19:39:15 +03:00
(defn when-test-true []
(let [x 0]
(do
(when true
(set! &x 5))
x)))
(defn when-test-false []
(let [x 0]
(do
(when false
(set! &x 5))
x)))
2017-12-05 21:35:45 +03:00
(defn all-eq [a b]
(if (/= (Array.count a) (Array.count b))
false
(let [eq true]
(do
(for [i 0 (Array.count a)]
(if (/= @(Array.nth a i) @(Array.nth b i))
(set! &eq false)
()))
eq))))
(defn main []
(with-test test
(assert-equal test
5
(break-test)
"break works as expected"
)
2017-12-12 19:39:15 +03:00
(assert-equal test
5
(when-test-true)
"when works as expected when true"
)
(assert-equal test
0
(when-test-false)
"when works as expected when false"
)
2017-12-05 21:35:45 +03:00
(print-test-results test)))