Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test inspired by CLJ-829

  • Loading branch information...
commit b1350235eb219b76f5b7c4cc21c8255f567892b3 1 parent 6d1c8ff
Stuart Halloway stuarthalloway authored
Showing with 43 additions and 0 deletions.
  1. +43 −0 src/examples/clojure/clojure/test/hash_test.clj
43 src/examples/clojure/clojure/test/hash_test.clj
View
@@ -0,0 +1,43 @@
+; Copyright (c) Rich Hickey, Stuart Halloway, and contributors.
+; All rights reserved.
+; The use and distribution terms for this software are covered by the
+; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+; which can be found in the file epl-v10.html at the root of this distribution.
+; By using this software in any fashion, you are agreeing to be bound by
+; the terms of this license.
+; You must not remove this notice, or any other, from this software.
+
+(ns clojure.test.hash-test
+ (:use clojure.test.generative)
+ (:require [clojure.test.generative.generators :as gen]))
+
+(defn hash-obj
+ [h]
+ (reify Object (hashCode [_] h)))
+
+(defn poorly-keyed-map
+ [vals distinct]
+ (zipmap
+ (map #(hash-obj (mod (hash %) distinct)) vals)
+ vals))
+
+(defn verify-key-removal
+ [m kset]
+ (loop [c (count kset)
+ [k & more] (seq kset)
+ tmap (transient m)]
+ (if k
+ (do
+ (assert (= (count tmap) c))
+ (recur (dec c)
+ more
+ (dissoc! tmap k)))
+ (do
+ (assert (zero? (count tmap)))
+ (assert (zero? (count (persistent! tmap))))))))
+
+(defspec transient-maps-with-key-collision
+ poorly-keyed-map
+ [^{:tag (vec long (uniform 0 1000))} vals
+ ^{:tag (uniform 1 100)} distinct]
+ (verify-key-removal % (into #{} (keys %))))
Please sign in to comment.
Something went wrong with that request. Please try again.