Permalink
Browse files

CLJ-1328: Make several Clojure tests independent of hash function

Signed-off-by: Stuart Halloway <stu@cognitect.com>
  • Loading branch information...
1 parent 99012bd commit 91dd867b4229a31d4d915aece97f41b3811cf4d4 @jafingerhut jafingerhut committed with stuarthalloway Jan 31, 2014
View
6 test/clojure/test_clojure/control.clj
@@ -366,9 +366,9 @@
^Object y (Long. -1)]
(is (= :diff (case x -1 :oops :diff)))
(is (= :same (case y -1 :same :oops)))))
- ;;FIXME - these are no longer collisions
- #_(testing "test correct behavior on hash collision"
- (is (== (hash 1) (hash 9223372039002259457N)))
+ (testing "test correct behavior on hash collision"
+ ;; case uses Java .hashCode to put values into hash buckets.
+ (is (== (.hashCode 1) (.hashCode 9223372039002259457N)))
(are [result input] (= result (case input
1 :long
9223372039002259457N :big
View
42 test/clojure/test_clojure/multimethods.clj
@@ -205,30 +205,30 @@
(deftest remove-all-methods-test
(testing "Core function remove-all-methods works"
- (defmulti simple identity)
- (defmethod simple :a [x] :a)
- (defmethod simple :b [x] :b)
- (is (= {} (methods (remove-all-methods simple))))))
+ (defmulti simple1 identity)
+ (defmethod simple1 :a [x] :a)
+ (defmethod simple1 :b [x] :b)
+ (is (= {} (methods (remove-all-methods simple1))))))
(deftest methods-test
(testing "Core function methods works"
- (defmulti simple identity)
- (defmethod simple :a [x] :a)
- (defmethod simple :b [x] :b)
- (is (= #{:a :b} (into #{} (keys (methods simple)))))
- (is (= :a ((:a (methods simple)) 1)))
- (defmethod simple :c [x] :c)
- (is (= #{:a :b :c} (into #{} (keys (methods simple)))))
- (remove-method simple :a)
- (is (= #{:b :c} (into #{} (keys (methods simple)))))))
+ (defmulti simple2 identity)
+ (defmethod simple2 :a [x] :a)
+ (defmethod simple2 :b [x] :b)
+ (is (= #{:a :b} (into #{} (keys (methods simple2)))))
+ (is (= :a ((:a (methods simple2)) 1)))
+ (defmethod simple2 :c [x] :c)
+ (is (= #{:a :b :c} (into #{} (keys (methods simple2)))))
+ (remove-method simple2 :a)
+ (is (= #{:b :c} (into #{} (keys (methods simple2)))))))
(deftest get-method-test
(testing "Core function get-method works"
- (defmulti simple identity)
- (defmethod simple :a [x] :a)
- (defmethod simple :b [x] :b)
- (is (fn? (get-method simple :a)))
- (= (:a ((get-method simple :a) 1)))
- (is (fn? (get-method simple :b)))
- (= (:b ((get-method simple :b) 1)))
- (is (nil? (get-method simple :xyz)))))
+ (defmulti simple3 identity)
+ (defmethod simple3 :a [x] :a)
+ (defmethod simple3 :b [x] :b)
+ (is (fn? (get-method simple3 :a)))
+ (is (= (:a ((get-method simple3 :a) 1))))
+ (is (fn? (get-method simple3 :b)))
+ (is (= (:b ((get-method simple3 :b) 1))))
+ (is (nil? (get-method simple3 :c)))))
View
19 test/clojure/test_clojure/pprint/test_pretty.clj
@@ -294,6 +294,25 @@ It is implemented with a number of custom enlive templates.\"
(binding [*print-length* 8] (with-out-str (pprint [1 2 3 4 5 6])))
"[1 2 3 4 5 6]\n"
+ (binding [*print-length* 1] (with-out-str (pprint (sorted-set 1 2 3 4 5 6))))
+ "#{1 ...}\n"
+ (binding [*print-length* 2] (with-out-str (pprint (sorted-set 1 2 3 4 5 6))))
+ "#{1 2 ...}\n"
+ (binding [*print-length* 6] (with-out-str (pprint (sorted-set 1 2 3 4 5 6))))
+ "#{1 2 3 4 5 6}\n"
+ (binding [*print-length* 8] (with-out-str (pprint (sorted-set 1 2 3 4 5 6))))
+ "#{1 2 3 4 5 6}\n"
+
+ (binding [*print-length* 1] (with-out-str (pprint (sorted-map 1 2, 3 4, 5 6, 7 8, 9 10, 11 12))))
+ "{1 2, ...}\n"
+ (binding [*print-length* 2] (with-out-str (pprint (sorted-map 1 2, 3 4, 5 6, 7 8, 9 10, 11 12))))
+ "{1 2, 3 4, ...}\n"
+ (binding [*print-length* 6] (with-out-str (pprint (sorted-map 1 2, 3 4, 5 6, 7 8, 9 10, 11 12))))
+ "{1 2, 3 4, 5 6, 7 8, 9 10, 11 12}\n"
+ (binding [*print-length* 8] (with-out-str (pprint (sorted-map 1 2, 3 4, 5 6, 7 8, 9 10, 11 12))))
+ "{1 2, 3 4, 5 6, 7 8, 9 10, 11 12}\n"
+
+
(binding [*print-length* 1] (with-out-str (pprint (int-array [1 2 3 4 5 6]))))
"[1, ...]\n"
(binding [*print-length* 2] (with-out-str (pprint (int-array [1 2 3 4 5 6]))))
View
6 test/clojure/test_clojure/sequences.clj
@@ -1114,10 +1114,10 @@
[1 2 3 4 5] `(1 2 3 4 5)
;maps
[] {:a 1 :b 2}
- ;;[:a 1 :b 2] (seq {:a 1 :b 2})
+ [:a 1 :b 2] (sort-by key {:a 1 :b 2})
[] {[:a :b] 1 :c 2}
- ;;[:a :b 1 :c 2] (seq {[:a :b] 1 :c 2})
- ;;[:a 1 2 :b 3] (seq {:a [1 2] :b 3})
+ [:a :b 1 :c 2] (sort-by val {[:a :b] 1 :c 2})
+ [:a 1 2 :b 3] (sort-by key {:a [1 2] :b 3})
;Strings
[] "12345"
[\1 \2 \3 \4 \5] (seq "12345")

0 comments on commit 91dd867

Please sign in to comment.