Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* src/clj/cljs/core.clj: fix some broken arithmetic. arithmetic tests.

  • Loading branch information...
commit 1028ca12f169322e31d7967d8c385165cf773665 1 parent bbc1ae7
@swannodette swannodette authored
View
4 src/clj/cljs/core.clj
@@ -67,7 +67,6 @@
([x y & more] `(+ (+ ~x ~y) ~@more)))
(defmacro -
- ([] 0)
([x] (list 'js* "(- ~{})" x))
([x y] (list 'js* "(~{} - ~{})" x y))
([x y & more] `(- (- ~x ~y) ~@more)))
@@ -79,8 +78,7 @@
([x y & more] `(* (* ~x ~y) ~@more)))
(defmacro /
- ([] 1)
- ([x] `(/ 1 x))
+ ([x] `(/ 1 ~x))
([x y] (list 'js* "(~{} / ~{})" x y))
([x y & more] `(/ (/ ~x ~y) ~@more)))
View
2  src/cljs/cljs/core.cljs
@@ -835,7 +835,7 @@ reduces them without incurring seq initialization"
"If no denominators are supplied, returns 1/numerator,
else returns numerator divided by all of the denominators."
([x] (/ 1 x))
- ([x y] (/ x y))
+ ([x y] (js* "(~{x} / ~{y})")) ;; FIXME: waiting on cljs.core//
([x y & more] (reduce / (/ x y) more)))
(defn <
View
143 test/cljs/cljs/core_test.cljs
@@ -1,6 +1,146 @@
(ns cljs.core-test)
(defn test-stuff []
+ ;; arithmetic
+ (assert (= (+) 0))
+ (assert (= (apply + []) 0))
+ (assert (= (+ 1) 1))
+ (assert (= (apply + [1]) 1))
+ (assert (= (+ 1 1) 2))
+ (assert (= (apply + [1 1]) 2))
+ (assert (= (+ 1 2 3) 6))
+ (assert (= (apply + [1 2 3]) 6))
+
+ (assert (= (- 1) -1))
+ (assert (= (apply - [1]) -1))
+ (assert (= (- 1 1) 0))
+ (assert (= (apply - [1 1]) 0))
+ (assert (= (- 3 2 1) 0))
+ (assert (= (apply - [3 2 1]) 0))
+
+ (assert (= (*) 1))
+ (assert (= (apply * []) 1))
+ (assert (= (* 2) 2))
+ (assert (= (apply * [2]) 2))
+ (assert (= (* 2 3) 6))
+ (assert (= (apply * [2 3]) 6))
+
+ (assert (= (/ 2) 0.5))
+ (assert (= (apply / [2]) 0.5))
+ (assert (= (/ 6 2) 3))
+ (assert (= (apply / [6 2]) 3))
+ (assert (= (/ 6 3 2) 1))
+ (assert (= (apply / [6 3 2]) 1))
+
+ (assert (= (< 1) true))
+ (assert (= (apply < [1]) true))
+ (assert (= (< 1 2) true))
+ (assert (= (apply < [1 2]) true))
+ (assert (= (< 1 1) false))
+ (assert (= (apply < [1 1]) false))
+ (assert (= (< 2 1) false))
+ (assert (= (apply < [2 1]) false))
+ (assert (= (< 1 2 3) true))
+ (assert (= (apply < [1 2 3]) true))
+ (assert (= (< 1 1 3) false))
+ (assert (= (apply < [1 1 3]) false))
+ (assert (= (< 3 1 1) false))
+ (assert (= (apply < [3 1 1]) false))
+
+ (assert (= (<= 1) true))
+ (assert (= (apply <= [1]) true))
+ (assert (= (<= 1 1) true))
+ (assert (= (apply <= [1 1]) true))
+ (assert (= (<= 1 2) true))
+ (assert (= (apply <= [1 2]) true))
+ (assert (= (<= 2 1) false))
+ (assert (= (apply <= [2 1]) false))
+ (assert (= (<= 1 2 3) true))
+ (assert (= (apply <= [1 2 3]) true))
+ (assert (= (<= 1 1 3) true))
+ (assert (= (apply <= [1 1 3]) true))
+ (assert (= (<= 3 1 1) false))
+ (assert (= (apply <= [3 1 1]) false))
+
+ (assert (= (> 1) true))
+ (assert (= (apply > [1]) true))
+ (assert (= (> 2 1) true))
+ (assert (= (apply > [2 1]) true))
+ (assert (= (> 1 1) false))
+ (assert (= (apply > [1 1]) false))
+ (assert (= (> 1 2) false))
+ (assert (= (apply > [1 2]) false))
+ (assert (= (> 3 2 1) true))
+ (assert (= (apply > [3 2 1]) true))
+ (assert (= (> 3 1 1) false))
+ (assert (= (apply > [3 1 1]) false))
+ (assert (= (> 1 1 3) false))
+ (assert (= (apply > [1 1 3]) false))
+
+ (assert (= (>= 1) true))
+ (assert (= (apply >= [1]) true))
+ (assert (= (>= 2 1) true))
+ (assert (= (apply >= [2 1]) true))
+ (assert (= (>= 1 1) true))
+ (assert (= (apply >= [1 1]) true))
+ (assert (= (>= 1 2) false))
+ (assert (= (apply >= [1 2]) false))
+ (assert (= (>= 3 2 1) true))
+ (assert (= (apply >= [3 2 1]) true))
+ (assert (= (>= 3 1 1) true))
+ (assert (= (apply >= [3 1 1]) true))
+ (assert (= (>= 3 1 2) false))
+ (assert (= (apply >= [3 1 2]) false))
+ (assert (= (>= 1 1 3) false))
+ (assert (= (apply >= [1 1 3]) false))
+
+ (assert (= (dec 1) 0))
+ (assert (= (apply dec [1]) 0))
+ (assert (= (inc 0) 1))
+ (assert (= (apply inc [0]) 1))
+
+ (assert (= (zero? 0) true))
+ (assert (= (apply zero? [0]) true))
+ (assert (= (zero? 1) false))
+ (assert (= (apply zero? [1]) false))
+ (assert (= (zero? -11) false))
+ (assert (= (apply zero? [-11]) false))
+ (assert (= (pos? 0) false))
+ (assert (= (apply pos? [0]) false))
+ (assert (= (pos? 1) true))
+ (assert (= (apply pos? [1]) true))
+ (assert (= (pos? -1) false))
+ (assert (= (apply pos? [-1]) false))
+ (assert (= (neg? -1) true))
+ (assert (= (apply neg? [-1]) true))
+
+ (assert (= (max 1) 1))
+ (assert (= (apply max [1]) 1))
+ (assert (= (max 1 2) 2))
+ (assert (= (apply max [1 2]) 2))
+ (assert (= (max 2 1) 2))
+ (assert (= (apply max [2 1]) 2))
+ (assert (= (max 1 2 3) 3))
+ (assert (= (apply max [1 2 3]) 3))
+ (assert (= (max 1 3 2) 3))
+ (assert (= (apply max [1 3 2]) 3))
+
+ (assert (= (min 1) 1))
+ (assert (= (apply min [1]) 1))
+ (assert (= (min 1 2) 1))
+ (assert (= (apply min [1 2]) 1))
+ (assert (= (min 2 1) 1))
+ (assert (= (apply min [2 1]) 1))
+ (assert (= (min 1 2 3) 1))
+ (assert (= (apply min [1 2 3]) 1))
+ (assert (= (min 2 1 3) 1))
+ (assert (= (apply min [3 1 3]) 1))
+
+ (assert (= (mod 4 2) 0))
+ (assert (= (apply mod [4 2]) 0))
+ (assert (= (mod 3 2) 1))
+ (assert (= (apply mod [3 2]) 1))
+
(assert (= [4 3 2 1 0] (loop [i 0 j ()]
(if (< i 5)
(recur (inc i) (conj j (fn [] i)))
@@ -838,4 +978,5 @@
h #{#{:2 :alt}}]
(assert (= g h)))
- :ok)
+ :ok
+ )
Please sign in to comment.
Something went wrong with that request. Please try again.