File tree Expand file tree Collapse file tree
src/examples/clojure/clojure/test Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 %))))
You can’t perform that action at this time.
0 commit comments