Back
hash-set (clj)
(source)function
(hash-set)
(hash-set & keys)
Returns a new hash set with supplied keys. Any equal keys are
handled as if by repeated uses of conj.
Examples
aphyr/tesser
(ns tesser.simple-test
(:require [clojure.test :refer :all]
[clojure.test.check :as tc]
[clojure.test.check [clojure-test :refer :all]
[generators :as gen]
[properties :as prop]]
[multiset.core :refer [multiset]]
[tesser.simple :as s]
[clojure.core.reducers :as r]
[clojure.set :as set]))
(defspec fold-spec
test-opts
(let [reducer (r/monoid conj hash-set)]
(prop/for-all [xs flat-ints]
(and (is (= (r/fold + xs)
(s/fold + xs)))
(is (= (r/fold set/union reducer xs)
(s/fold set/union reducer xs)))))))
uncomplicate/fluokitten
(ns uncomplicate.fluokitten.core-test
(:use [uncomplicate.fluokitten algo jvm core test utils])
(:use [midje.sweet :exclude [just]])
(:require [clojure.string :as s]
[clojure.core.reducers :as r]))
(monad-law1-left-identity #{} (comp hash-set inc) 6)
(monad-law1-left-identity #{} (comp hash-set +) 6 7 99)
(monad-law3-associativity (comp hash-set inc) (comp hash-set (partial * 10)) #{5 -56 30})
(data-structures-should-preserve-metadata inc + hash-set #{1 2 3} #{4 5 6})
(bind (apply hash-set (range 1 500)) returning-f) => (apply hash-set (distinct (range 2 501)))
(bind (apply hash-set (range 1 500)) (apply hash-set (range 1 500))
(apply hash-set (range 1 500)) returning-f)
=> (apply hash-set (distinct (range 3 1500 3)))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
cc/set (t/All [x] [(t/Seqable x) :-> #?(:cljs (t/Set x)
:default (PersistentHashSet x))])
cc/hash-set (t/All [x] [x :* :-> #?(:cljs (t/Set x)
:default (PersistentHashSet x))])
;TODO
;cc/hash-map (t/All [x y z :..]
; (t/IFn [(t/cat z z) :.. z :-> (t/Assoc '{} z :.. z)]
; [(t/cat x y) :* :-> (t/Map x y)]))
cc/hash-map (t/All [x y] [(t/cat x y) :* :-> (t/Map x y)])
cc/array-map (t/All [x y] [(t/cat x y) :* :-> (t/Map x y)])
cc/sorted-map (t/All [x y] [(t/cat x y) :* :-> (t/SortedMap x y)])
cc/sorted-map-by (t/All [x y] [[x x :-> t/Int] (t/cat x y) :* :-> (t/SortedMap x y)])
cc/sorted-set (t/All [x] [x :* :-> (t/SortedSet x)])
;;FIXME use t/Comparator for first arg
cc/sorted-set-by (t/All [x] [[x x :-> t/Int] x :* :-> (t/SortedSet x)])
cc/list (t/All [x] [x :* :-> (#?(:clj PersistentList :cljs t/List) x)])
;cc/list* (t/All [x] [x :* (t/Seqable x) :-> (t/NilableNonEmptyASeq x)])
cc/list* (t/All [x] (t/IFn [(t/Seqable x) :-> (t/NilableNonEmptyASeq x)]
[x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]
[x x x x x x x x x x (t/Seqable x) :-> (t/NonEmptyASeq x)]))
bnyeggen/soac
(ns soac.test.hopscotch
(:use clojure.test
soac.hopscotch)
(:require [clojure.core.reducers :as r])
(:import [java.util HashMap HashSet]))
(deftest test-set
(let [a (prim-hash-set :int)
b (into #{} (repeatedly 100 #(rand-int 200)))
c (into a b)]
(is (every? #(contains? c %) b))
(is (= b c))))
(deftest test-set-disj
(let [a (into #{} (repeatedly 100 #(rand-int 200)))
b (take 30 (shuffle (vec a)))
d (reduce disj (into (prim-hash-set :int) a) b)
e (reduce disj a b)]
(is (= d e))
(is (empty? (reduce disj (into (prim-hash-set :int) (range 100)) (range 100))))))
(deftest test-overwrite
(is (== 1 (count (into (prim-hash-set :int) [4 4]))))
(let [a (-> (prim-hash-map :int :double) (assoc 1 2.0) (assoc 1 3.0))]
(is (== 1 (count a)))
(is (== 3.0 (get a 1)))))
(deftest test-boxing
(is (contains? (conj (prim-hash-set :int) (int 4)) (long 4)))
(is (== 1 (count (into (prim-hash-set :int) [(long 4) (int 4)])))))
(deftest test-reducers
(is (->> [1 2 3 4 5] (into (prim-hash-set :int)) (r/reduce +) (== 15)))
(is (->> [[0 1][2 3][4 5]] (into (prim-hash-map :int :int)) (r/reduce +) (== 15) )))
(deftest ^:performance test-speed
(let [to-insert (long-array (repeatedly 1000000 #(rand-int Integer/MAX_VALUE)))
clj-set (do (print "Clojure set insert: ")
(time (into #{} to-insert)))
java-set (do (print "Java set insert: ")
(time (let [a (HashSet.)]
(doseq [e to-insert] (.add ^HashSet a e))
a)))
imm-set (do (print "Immutable primitive set insert: ")
(time (into (prim-hash-set :long) to-insert)))]
(println)
(print "Clojure set lookup: ")
(time (every? #(contains? clj-set %) to-insert))
(print "Java set lookup: ")
(time (every? #(.contains ^HashSet java-set %) to-insert))
(print "Immutable primitive set lookup: ")
(time (every? #(contains? imm-set %) to-insert))
(println)
(print "Clojure set removal: ")
(time (reduce disj clj-set to-insert))
(print "Java set removal: ")
(time (doseq [e to-insert] (.remove ^HashSet java-set e)))
(print "Immutable primitive set removal: ")
(time (reduce disj imm-set to-insert))
(println)
(print "Clojure set traversal: ")
(time (doseq [e clj-set]))
(print "Java set traversal: ")
(time (doseq [e java-set]))
(print "Immutable primitive set traversal: ")
(time (doseq [e imm-set]))))
howonlee/mertonon
(ns mertonon.services.matrix-service-test
(:require [clojure.core.matrix :as cm]
[clojure.data :as cd]
[clojure.test :refer :all]
[clojure.test.check :as tc]
[clojure.test.check.clojure-test :refer :all]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop]
[mertonon.generators.aug-net :as aug-net-gen]
[mertonon.generators.net :as net-gen]
[mertonon.services.graph-service :as gs]
[mertonon.services.matrix-service :as ms]
[mertonon.test-utils :as tu]))
;; Do not let matrix rows sum to zero because we l1-normalize matrix rows and what's normalization of a zero row anyways
(defspec matrix-rows-do-not-sum-to-zero
tu/many
(prop/for-all [matrix-weights net-gen/generate-matrix-weights]
(let [elem-set (->> matrix-weights ms/weights->matrix :matrix
cm/slices (mapv cm/esum) (apply hash-set))]
(every? #(not (zero? %)) elem-set))))