Carp/test/int_math.carp
2018-06-23 14:23:42 +10:00

64 lines
1.8 KiB
Plaintext

(load "Test.carp")
(use-all Int Test)
(defn main []
(with-test test
(assert-equal test
1
(min 1 2)
"min works as expected")
(assert-equal test
2
(max 1 2)
"max works as expected")
(assert-equal test
1
(abs -1)
"abs works as expected")
(assert-equal test
false
(even? 3)
"even? works as expected")
(assert-equal test
true
(odd? 3)
"odd? works as expected")
(assert-equal test
1
(bit-and 3 5)
"bit-and works as expected")
(assert-equal test
5
(bit-or 1 4)
"bit-or works as expected")
(assert-equal test
4
(bit-xor 1 5)
"bit-xor works as expected")
(assert-equal test
-2
(bit-not 1)
"bit-not works as expected")
(assert-equal test
8
(bit-shift-left 2 2)
"bit-shift-left works as expected")
(assert-equal test
2
(bit-shift-right 16 3)
"bit-shift-right works as expected")
(assert-equal test
-2
(neg 2)
"neg works as expected")
(assert-equal test
2
(neg -2)
"neg works as expected II")
(assert-equal test
1
(/ 3 2)
"integer division truncates as expected")
(print-test-results test)))