hy/tests/native_tests/math.hy

42 lines
748 B
Hy
Raw Normal View History

2013-03-06 00:39:34 +01:00
; copyright ..
(setv square (fn [x]
2013-03-06 04:15:45 +01:00
(* x x)))
(setv test_basic_math (fn []
2013-03-06 04:15:45 +01:00
"NATIVE: Test basic math."
2013-03-06 03:42:54 +01:00
(assert (= (+ 2 2) 4))))
2013-03-06 04:15:45 +01:00
(setv test_mult (fn []
2013-03-06 04:15:45 +01:00
"NATIVE: Test multiplication."
(assert (= 4 (square 2)))))
(setv test_sub (fn []
2013-03-06 04:15:45 +01:00
"NATIVE: Test subtraction"
(assert (= 4 (- 8 4)))))
(setv test_add (fn []
2013-03-06 04:15:45 +01:00
"NATIVE: Test addition"
(assert (= 4 (+ 1 1 1 1)))))
(setv test_div (fn []
2013-03-06 04:15:45 +01:00
"NATIVE: Test division"
(assert (= 25 (/ 100 2 2)))
; Commented out until float constants get implemented
; (assert (= 0.5 (/ 1 2)))
(assert (= 1 (* 2 (/ 1 2))))))
2013-03-19 02:46:58 +01:00
(setv test_int_div (fn []
"NATIVE: Test integer division"
(assert (= 25 (// 101 2 2)))))
2013-03-19 02:46:58 +01:00
(defn test-modulo []
"NATIVE: test mod"
(assert (= (% 10 2) 0)))