Skip to content

Commit

Permalink
CLJS-1353: range inconsistent with Clojure if step is 0 Changed the i…
Browse files Browse the repository at this point in the history
…mplementation to match Clojure's and also updated tests. Used == instead of =
  • Loading branch information
kamn authored and swannodette committed Aug 27, 2015
1 parent 19bcf10 commit bbcadde
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/main/cljs/cljs/core.cljs
Expand Up @@ -8430,11 +8430,10 @@ reduces them without incurring seq initialization"

ISeqable
(-seq [rng]
(if (pos? step)
(when (< start end)
rng)
(when (> start end)
rng)))
(cond
(pos? step) (when (< start end) rng)
(neg? step) (when (> start end) rng)
:else (when-not (== start end) rng)))

ISeq
(-first [rng]
Expand Down
4 changes: 2 additions & 2 deletions src/test/cljs/cljs/core_test.cljs
Expand Up @@ -1221,11 +1221,11 @@
(is (= (range 0 -3 -1) (list 0 -1 -2)))
(is (= (range 3 0 -1) (list 3 2 1)))
(is (= (range 0 10 -1) (list)))
(is (= (range 0 1 0) (list)))
(is (= (take 3 (range 0 1 0)) (list 0 0 0)))
(is (= (range 10 0 1) (list)))
(is (= (range 0 0 0) (list)))
(is (= (count (range 0 10 -1)) 0))
(is (= (count (range 0 1 0)) 0))
(is (= (count (take 3 (range 0 2 0))) 3))
(is (= (count (range 10 0 1)) 0))
(is (= (count (range 0 0 0)) 0))
(is (= (take 3 (range 1 0 0)) (list 1 1 1)))
Expand Down

0 comments on commit bbcadde

Please sign in to comment.