Permalink
Browse files

CLJS-393: Bugfixes for PersistentTreeMap: sorted-map-by and -sorted-s…

…eq-from
  • Loading branch information...
1 parent bef56a7 commit e3ed0e7b69f9522e8759d0a6567afabb2a98d949 @ejlo ejlo committed with David Nolen Oct 18, 2012
Showing with 17 additions and 7 deletions.
  1. +2 −2 src/cljs/cljs/core.cljs
  2. +15 −5 test/cljs/cljs/core_test.cljs
View
@@ -5468,7 +5468,7 @@ reduces them without incurring seq initialization"
:else (if (pos? c)
(recur (conj stack t) (.-right t))
(recur stack (.-left t)))))
- (if (nil? stack)
+ (when-not (nil? stack)
(PersistentTreeMapSeq. nil stack ascending? -1 nil))))))
(-entry-key [coll entry] (key entry))
@@ -5519,7 +5519,7 @@ reduces them without incurring seq initialization"
Returns a new sorted map with supplied mappings, using the supplied comparator."
([comparator & keyvals]
(loop [in (seq keyvals)
- out (cljs.core.PersistentTreeMap. comparator nil 0 nil 0)]
+ out (cljs.core.PersistentTreeMap. (fn->comparator comparator) nil 0 nil 0)]
(if in
(recur (nnext in) (assoc out (first in) (second in)))
out))))
@@ -1229,7 +1229,6 @@
(assert (identical? cljs.core.PersistentTreeMap (type m1)))
(assert (identical? cljs.core.PersistentTreeMap (type m2)))
(assert (identical? compare (.-comp m1)))
- (assert (identical? c2 (.-comp m2)))
(assert (zero? (count m1)))
(assert (zero? (count m2)))
(let [m1 (assoc m1 :foo 1 :bar 2 :quux 3)
@@ -1271,16 +1270,17 @@
c2 (comp - compare)
s2 (sorted-set-by c2)
c3 #(compare (quot %1 2) (quot %2 2))
- s3 (sorted-set-by c3)]
+ s3 (sorted-set-by c3)
+ s4 (sorted-set-by <)]
(assert (identical? cljs.core.PersistentTreeSet (type s1)))
(assert (identical? cljs.core.PersistentTreeSet (type s2)))
(assert (identical? compare (-comparator s1)))
- (assert (identical? c2 (-comparator s2)))
(assert (zero? (count s1)))
(assert (zero? (count s2)))
(let [s1 (conj s1 1 2 3)
s2 (conj s2 1 2 3)
- s3 (conj s3 1 2 3)]
+ s3 (conj s3 1 2 3 7 8 9)
+ s4 (conj s4 1 2 3)]
(assert (= (hash s1) (hash s2)))
(assert (= (hash s1) (hash #{1 2 3})))
(assert (= (seq s1) (list 1 2 3)))
@@ -1289,8 +1289,18 @@
(assert (= (rseq s2) (list 1 2 3)))
(assert (= (count s1) 3))
(assert (= (count s2) 3))
- (assert (= (count s3) 2))
+ (assert (= (count s3) 4))
(assert (= (get s3 0) 1))
+ (assert (= (subseq s3 > 5) (list 7 8)))
+ (assert (= (subseq s3 > 6) (list 8)))
+ (assert (= (subseq s3 >= 6) (list 7 8)))
+ (assert (= (subseq s3 >= 12) nil))
+ (assert (= (subseq s3 < 0) (list)))
+ (assert (= (subseq s3 < 5) (list 1 2)))
+ (assert (= (subseq s3 < 6) (list 1 2)))
+ (assert (= (subseq s3 <= 6) (list 1 2 7)))
+ (assert (= (subseq s3 >= 2 <= 6) (list 2 7)))
+ (assert (= (subseq s4 >= 2 < 3) (list 2)))
(let [s1 (disj s1 2)
s2 (disj s2 2)]
(assert (= (seq s1) (list 1 3)))

0 comments on commit e3ed0e7

Please sign in to comment.