Skip to content

Commit

Permalink
Merge branch 'master' into checked-arithmetic
Browse files Browse the repository at this point in the history
Conflicts:
	src/clj/cljs/core.clj

* src/clj/cljs/core.clj: merge master
  • Loading branch information
swannodette committed Jan 29, 2012
2 parents b48ccf5 + 1028ca1 commit 4257e06
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/clj/cljs/core.clj
Expand Up @@ -98,7 +98,6 @@
([x y & more] `(+ (+ ~x ~y) ~@more)))

(defmacro -
([] 0)
([x] (check-numbers "(- ~{})" '- x))
([x y] (check-numbers "(~{} - ~{})" '- x y))
([x y & more] `(- (- ~x ~y) ~@more)))
Expand All @@ -110,7 +109,6 @@
([x y & more] `(* (* ~x ~y) ~@more)))

(defmacro /
([] 1)
([x] `(/ 1 ~x))
([x y] (let [expr (check-numbers "(~{} / ~{})" '/ x y)]
(if @*js-unchecked-arithmetic*
Expand Down
2 changes: 1 addition & 1 deletion src/cljs/cljs/core.cljs
Expand Up @@ -839,7 +839,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 <
Expand Down
143 changes: 142 additions & 1 deletion 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)))
Expand Down Expand Up @@ -838,4 +978,5 @@
h #{#{:2 :alt}}]
(assert (= g h)))

:ok)
:ok
)

0 comments on commit 4257e06

Please sign in to comment.