diff --git a/build.boot b/build.boot index 636d87f..7cff438 100644 --- a/build.boot +++ b/build.boot @@ -2,7 +2,9 @@ :resource-paths #{"src"} :dependencies '[[adzerk/boot-cljs "0.0-3308-0" :scope "test"] [adzerk/boot-cljs-repl "0.1.9" :scope "test"] - [crisptrutski/boot-cljs-test "0.1.0-SNAPSHOT" :scope "test"]]) + [crisptrutski/boot-cljs-test "0.1.0-SNAPSHOT" :scope "test"] + [collection-check "0.1.6" :scope "test" + :exclusions [org.clojure/clojure]]]) (require '[adzerk.boot-cljs :refer [cljs]] diff --git a/src/linked/map.cljc b/src/linked/map.cljc index f39a9ef..2433909 100644 --- a/src/linked/map.cljc +++ b/src/linked/map.cljc @@ -5,6 +5,7 @@ Counted IObj IFn + IHashEq ILookup IPersistentCollection IPersistentVector @@ -118,13 +119,16 @@ ;; IEditableCollection + IHashEq + (hasheq [this] (.hasheq (into {} this))) + Object (toString [this] (str "{" (string/join ", " (for [[k v] this] (str k " " v))) "}")) (equals [this other] (.equiv this other)) (hashCode [this] - (hash (into {} this)))] + (.hashCode (into {} this)))] :cljs [Object (toString [coll] @@ -163,7 +167,7 @@ (-equiv [coll other] (equiv-map coll other)) IHash - (-hash [coll] (hash-unordered-coll coll)) + (-hash [coll] (hash (into {} coll))) ISequential diff --git a/src/linked/set.cljc b/src/linked/set.cljc index b73bc0d..31b023b 100644 --- a/src/linked/set.cljc +++ b/src/linked/set.cljc @@ -5,6 +5,7 @@ #?(:clj (:import (clojure.lang Counted IObj IFn + IHashEq ILookup IPersistentCollection IPersistentSet @@ -70,11 +71,14 @@ (withMeta [this m] (LinkedSet. (.withMeta ^IObj linked-map m))) + IHashEq + (hasheq [this] (.hasheq (into #{} this))) + Object (toString [this] (str "[" (string/join " " (map str this)) "]")) (hashCode [this] - (reduce + (map hash (.seq this)))) + (.hashCode (into #{} this))) (equals [this other] (.equiv this other))] :cljs @@ -109,7 +113,7 @@ other))) IHash - (-hash [coll] (hash-unordered-coll coll)) + (-hash [coll] (hash (into #{} coll))) ISeqable (-seq [coll] (when-let [s (seq linked-map)] (map key s))) diff --git a/test/linked/map_test.cljc b/test/linked/map_test.cljc index 8beedc6..7d56335 100644 --- a/test/linked/map_test.cljc +++ b/test/linked/map_test.cljc @@ -1,9 +1,15 @@ (ns linked.map-test (:require [linked.core :as linked] - #?(:clj [clojure.test :refer :all] - :cljs [cljs.test :refer-macros [is are testing deftest run-tests]]) + #?@(:clj [[clojure.test :refer :all] + [collection-check :refer :all] + [clojure.test.check.generators :as gen]] + :cljs [[cljs.test :refer-macros [is are testing deftest run-tests]]]) #?(:cljs [cljs.reader :refer [read-string]]))) +#?(:clj + (deftest check + (assert-map-like (linked/map) gen/int gen/int))) + #?(:clj (deftest implementations (let [basic (linked/map)] diff --git a/test/linked/set_test.cljc b/test/linked/set_test.cljc index 618d482..11d8f93 100644 --- a/test/linked/set_test.cljc +++ b/test/linked/set_test.cljc @@ -1,9 +1,16 @@ (ns linked.set-test (:require [linked.core :as linked] - #?(:clj [clojure.test :refer :all] - :cljs [cljs.test :refer-macros [is are testing deftest run-tests]]) + #?@(:clj [[clojure.test :refer :all] + [collection-check :refer :all] + [clojure.test.check.generators :as gen]] + :cljs [[cljs.test :refer-macros [is are testing deftest run-tests]]]) #?(:cljs [cljs.reader :refer [read-string]]))) + +#?(:clj + (deftest check + (assert-set-like (linked/set) gen/int))) + #?(:clj (deftest implementations (let [s (linked/set)]