Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

test inspired by CLJ-829

  • Loading branch information...
commit b1350235eb219b76f5b7c4cc21c8255f567892b3 1 parent 6d1c8ff
Stuart Halloway authored September 09, 2011
43  src/examples/clojure/clojure/test/hash_test.clj
... ...
@@ -0,0 +1,43 @@
  1
+;   Copyright (c) Rich Hickey, Stuart Halloway, and contributors.
  2
+;   All rights reserved.
  3
+;   The use and distribution terms for this software are covered by the
  4
+;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
  5
+;   which can be found in the file epl-v10.html at the root of this distribution.
  6
+;   By using this software in any fashion, you are agreeing to be bound by
  7
+;   the terms of this license.
  8
+;   You must not remove this notice, or any other, from this software.
  9
+
  10
+(ns clojure.test.hash-test
  11
+  (:use clojure.test.generative)
  12
+  (:require [clojure.test.generative.generators :as gen]))
  13
+
  14
+(defn hash-obj
  15
+  [h]
  16
+  (reify Object (hashCode [_] h)))
  17
+
  18
+(defn poorly-keyed-map
  19
+  [vals distinct]
  20
+  (zipmap
  21
+   (map #(hash-obj (mod (hash %) distinct)) vals)
  22
+   vals))
  23
+
  24
+(defn verify-key-removal
  25
+  [m kset]
  26
+  (loop [c (count kset)
  27
+         [k & more] (seq kset)
  28
+         tmap (transient m)]
  29
+    (if k
  30
+      (do
  31
+        (assert (= (count tmap) c))
  32
+        (recur (dec c)
  33
+               more
  34
+               (dissoc! tmap k)))
  35
+      (do
  36
+        (assert (zero? (count tmap)))
  37
+        (assert (zero? (count (persistent! tmap))))))))
  38
+
  39
+(defspec transient-maps-with-key-collision
  40
+  poorly-keyed-map
  41
+  [^{:tag (vec long (uniform 0 1000))} vals
  42
+   ^{:tag (uniform 1 100)} distinct]
  43
+  (verify-key-removal % (into #{} (keys %))))

0 notes on commit b135023

Please sign in to comment.
Something went wrong with that request. Please try again.