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)
|
2018-02-02 09:19:10 +03:00
|
|
|
(set! x (inc x))))
|
2017-12-05 21:35:45 +03:00
|
|
|
x)))
|
|
|
|
|
2017-12-12 19:39:15 +03:00
|
|
|
(defn when-test-true []
|
|
|
|
(let [x 0]
|
|
|
|
(do
|
|
|
|
(when true
|
2018-02-02 09:19:10 +03:00
|
|
|
(set! x 5))
|
2017-12-12 19:39:15 +03:00
|
|
|
x)))
|
|
|
|
|
|
|
|
(defn when-test-false []
|
|
|
|
(let [x 0]
|
|
|
|
(do
|
|
|
|
(when false
|
2018-02-02 09:19:10 +03:00
|
|
|
(set! x 5))
|
2017-12-12 19:39:15 +03:00
|
|
|
x)))
|
|
|
|
|
2017-12-12 20:45:29 +03:00
|
|
|
(defn unless-test-true []
|
|
|
|
(let [x 0]
|
|
|
|
(do
|
|
|
|
(unless true
|
2018-02-02 09:19:10 +03:00
|
|
|
(set! x 5))
|
2017-12-12 20:45:29 +03:00
|
|
|
x)))
|
|
|
|
|
|
|
|
(defn unless-test-false []
|
|
|
|
(let [x 0]
|
|
|
|
(do
|
|
|
|
(unless false
|
2018-02-02 09:19:10 +03:00
|
|
|
(set! x 5))
|
2017-12-12 20:45:29 +03:00
|
|
|
x)))
|
|
|
|
|
2017-12-05 21:35:45 +03:00
|
|
|
(defn all-eq [a b]
|
2018-05-20 10:57:51 +03:00
|
|
|
(if (/= (Array.length a) (Array.length b))
|
2017-12-05 21:35:45 +03:00
|
|
|
false
|
|
|
|
(let [eq true]
|
|
|
|
(do
|
2018-05-20 10:57:51 +03:00
|
|
|
(for [i 0 (Array.length a)]
|
2019-10-31 12:23:23 +03:00
|
|
|
(if (/= @(Array.unsafe-nth a i) @(Array.unsafe-nth b i))
|
2018-02-02 09:19:10 +03:00
|
|
|
(set! eq false)
|
2017-12-05 21:35:45 +03:00
|
|
|
()))
|
|
|
|
eq))))
|
|
|
|
|
2018-11-07 18:11:38 +03:00
|
|
|
(deftest test
|
|
|
|
(assert-equal test
|
|
|
|
5
|
|
|
|
(break-test)
|
|
|
|
"break works as expected")
|
|
|
|
(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")
|
|
|
|
(assert-equal test
|
|
|
|
0
|
|
|
|
(unless-test-true)
|
|
|
|
"unless works as expected when true")
|
|
|
|
(assert-equal test
|
|
|
|
5
|
|
|
|
(unless-test-false)
|
|
|
|
"unless works as expected when false"))
|