Skip to content

Commit

Permalink
CLJ-1328: Make several Clojure tests independent of hash function
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Halloway <stu@cognitect.com>
  • Loading branch information
jafingerhut authored and stuarthalloway committed Feb 7, 2014
1 parent 99012bd commit 91dd867
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
6 changes: 3 additions & 3 deletions test/clojure/test_clojure/control.clj
Expand Up @@ -366,9 +366,9 @@
^Object y (Long. -1)] ^Object y (Long. -1)]
(is (= :diff (case x -1 :oops :diff))) (is (= :diff (case x -1 :oops :diff)))
(is (= :same (case y -1 :same :oops))))) (is (= :same (case y -1 :same :oops)))))
;;FIXME - these are no longer collisions (testing "test correct behavior on hash collision"
#_(testing "test correct behavior on hash collision" ;; case uses Java .hashCode to put values into hash buckets.
(is (== (hash 1) (hash 9223372039002259457N))) (is (== (.hashCode 1) (.hashCode 9223372039002259457N)))
(are [result input] (= result (case input (are [result input] (= result (case input
1 :long 1 :long
9223372039002259457N :big 9223372039002259457N :big
Expand Down
42 changes: 21 additions & 21 deletions test/clojure/test_clojure/multimethods.clj
Expand Up @@ -205,30 +205,30 @@


(deftest remove-all-methods-test (deftest remove-all-methods-test
(testing "Core function remove-all-methods works" (testing "Core function remove-all-methods works"
(defmulti simple identity) (defmulti simple1 identity)
(defmethod simple :a [x] :a) (defmethod simple1 :a [x] :a)
(defmethod simple :b [x] :b) (defmethod simple1 :b [x] :b)
(is (= {} (methods (remove-all-methods simple)))))) (is (= {} (methods (remove-all-methods simple1))))))


(deftest methods-test (deftest methods-test
(testing "Core function methods works" (testing "Core function methods works"
(defmulti simple identity) (defmulti simple2 identity)
(defmethod simple :a [x] :a) (defmethod simple2 :a [x] :a)
(defmethod simple :b [x] :b) (defmethod simple2 :b [x] :b)
(is (= #{:a :b} (into #{} (keys (methods simple))))) (is (= #{:a :b} (into #{} (keys (methods simple2)))))
(is (= :a ((:a (methods simple)) 1))) (is (= :a ((:a (methods simple2)) 1)))
(defmethod simple :c [x] :c) (defmethod simple2 :c [x] :c)
(is (= #{:a :b :c} (into #{} (keys (methods simple))))) (is (= #{:a :b :c} (into #{} (keys (methods simple2)))))
(remove-method simple :a) (remove-method simple2 :a)
(is (= #{:b :c} (into #{} (keys (methods simple))))))) (is (= #{:b :c} (into #{} (keys (methods simple2)))))))


(deftest get-method-test (deftest get-method-test
(testing "Core function get-method works" (testing "Core function get-method works"
(defmulti simple identity) (defmulti simple3 identity)
(defmethod simple :a [x] :a) (defmethod simple3 :a [x] :a)
(defmethod simple :b [x] :b) (defmethod simple3 :b [x] :b)
(is (fn? (get-method simple :a))) (is (fn? (get-method simple3 :a)))
(= (:a ((get-method simple :a) 1))) (is (= (:a ((get-method simple3 :a) 1))))
(is (fn? (get-method simple :b))) (is (fn? (get-method simple3 :b)))
(= (:b ((get-method simple :b) 1))) (is (= (:b ((get-method simple3 :b) 1))))
(is (nil? (get-method simple :xyz))))) (is (nil? (get-method simple3 :c)))))
19 changes: 19 additions & 0 deletions test/clojure/test_clojure/pprint/test_pretty.clj
Expand Up @@ -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]))) (binding [*print-length* 8] (with-out-str (pprint [1 2 3 4 5 6])))
"[1 2 3 4 5 6]\n" "[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])))) (binding [*print-length* 1] (with-out-str (pprint (int-array [1 2 3 4 5 6]))))
"[1, ...]\n" "[1, ...]\n"
(binding [*print-length* 2] (with-out-str (pprint (int-array [1 2 3 4 5 6])))) (binding [*print-length* 2] (with-out-str (pprint (int-array [1 2 3 4 5 6]))))
Expand Down
6 changes: 3 additions & 3 deletions test/clojure/test_clojure/sequences.clj
Expand Up @@ -1114,10 +1114,10 @@
[1 2 3 4 5] `(1 2 3 4 5) [1 2 3 4 5] `(1 2 3 4 5)
;maps ;maps
[] {:a 1 :b 2} [] {: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}
;;[:a :b 1 :c 2] (seq {[:a :b] 1 :c 2}) [:a :b 1 :c 2] (sort-by val {[:a :b] 1 :c 2})
;;[:a 1 2 :b 3] (seq {:a [1 2] :b 3}) [:a 1 2 :b 3] (sort-by key {:a [1 2] :b 3})
;Strings ;Strings
[] "12345" [] "12345"
[\1 \2 \3 \4 \5] (seq "12345") [\1 \2 \3 \4 \5] (seq "12345")
Expand Down

0 comments on commit 91dd867

Please sign in to comment.