Skip to content

Commit

Permalink
update all test ns to reference clj-uuid.core
Browse files Browse the repository at this point in the history
  • Loading branch information
dco-lentz committed Oct 15, 2024
1 parent 8db046f commit e01cf1c
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 101 deletions.
4 changes: 2 additions & 2 deletions test/clj_uuid/api_test.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns clj-uuid.api-test
(:refer-clojure :exclude [uuid? max])
(:require [clojure.test :refer :all]
[clj-uuid :refer :all :exclude [= > <]])
(:require [clj-uuid.core :refer :all :exclude [= > <]]
[clojure.test :refer :all])
(:import
(java.lang IllegalArgumentException)))

Expand Down
21 changes: 8 additions & 13 deletions test/clj_uuid/bitmop_test.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
(ns clj-uuid.bitmop-test
(:require
[clojure.test :refer :all]
[clj-uuid.bitmop :refer :all]))
[clj-uuid.bitmop :refer :all]
[clojure.test :refer :all]))



(deftest check-bit-mask-operators
(testing "bit-mask construction..."
(is (= (mask 0 0) 0))
Expand Down Expand Up @@ -46,7 +44,7 @@
(is (= 32 (mask-width (mask 32 0))))
(is (= 31 (mask-width (mask 31 32))))
(is (= 62 (mask-width (mask 62 0))))
(is (= 48 (mask-width (mask 48 15))))
(is (= 48 (mask-width (mask 48 15))))
(is (= 64 (mask-width (mask 64 0))))
(is (= 60 (mask-width (mask 60 4))))
(is (= 31 (mask-width (mask 31 33))))
Expand Down Expand Up @@ -77,7 +75,7 @@
(for [i (range 0 61)]
(is (= 15 (ldb (mask 4 i) (mask 64 0))))))
(testing "dpb..."
(map #(is (= 0x3 %))
(map #(is (= 0x3 %))
(for [i (range 8)]
(ldb (mask 4 (* i 4))
(dpb (mask 4 (* i 4)) (mask 64 0) 0x3))))
Expand Down Expand Up @@ -124,25 +122,25 @@
(is (= (ub4 -1) 15))
(is (= (ub4 16) 0))
(is (= (ub4 15) 15))
(is (= (ub4 7) 7))
(is (= (ub4 7) 7))
(is (= (ub56 0x80) 128))
(is (= (class (ub56 0x80)) Long))))



(deftest check-byte-reassembly-roundtrip
(testing "dissasemble/reassemble-bytes..."
(testing "dissasemble/reassemble-bytes..."
(dotimes [_ 256]
(let [bytes (for [i (range 8)]
(sb8 (rand-int (mask 8 0))))]
(sb8 (rand-int (mask 8 0))))]
(is (= (seq (long->bytes (assemble-bytes bytes))) bytes))))))


(deftest check-simple-octet-hex-mapping
(testing "octet-hex mapping..."
(is (= (octet-hex 0xff) "FF"))
(is (= (octet-hex 0x00) "00"))
(is (= (octet-hex 0x7a) "7A"))
(is (= (octet-hex 0x7a) "7A"))
(is (= (octet-hex 15) "0F"))
(is (= (octet-hex 45) "2D"))
(is (= (octet-hex 250) "FA"))
Expand All @@ -160,6 +158,3 @@
(is (= (hex 255) "00000000000000FF"))
(is (= (hex 65536) "0000000000010000"))
(is (= (hex -1) "FFFFFFFFFFFFFFFF"))))



18 changes: 9 additions & 9 deletions test/clj_uuid/clock_test.clj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
(ns clj-uuid.clock-test
(:require [clojure.test :refer :all]
[clojure.set]
[clj-uuid.clock :refer :all]))
(:require [clj-uuid.clock :as clock]
[clojure.set :as set]
[clojure.test :refer :all]))

(deftest check-single-threaded
(let [iterations 1000000
groups 10
check #(mapv (fn [_] (%)) (range iterations))]
(testing "monotonic-time..."
(dotimes [_ groups]
(let [result (check monotonic-time)]
(let [result (check clock/monotonic-time)]
(is (= (count result) (count (set result)))))))
(testing "monotonic-unix-time-and-random-counter..."
(dotimes [_ groups]
(let [result (check monotonic-unix-time-and-random-counter)]
(let [result (check clock/monotonic-unix-time-and-random-counter)]
(is (= (count result) (count (set result)))))))))

(deftest check-multi-threaded-monotonic-time
Expand All @@ -22,13 +22,13 @@
agents (mapv agent (repeat concur nil))
working (mapv #(send-off %
(fn [state]
(repeatedly extent monotonic-time)))
(repeatedly extent clock/monotonic-time)))
agents)
_ (apply await working)
answers (mapv deref working)]
(testing (str "concurrent timestamp uniqueness (" concur " threads)...")
(is (= (* concur extent)
(count (apply clojure.set/union (map set answers))))))
(count (apply set/union (map set answers))))))
(testing (str "concurrent monotonic increasing (" concur " threads)...")
(is (every? identity
(map #(apply < %) answers)))))))
Expand All @@ -40,14 +40,14 @@
working (mapv #(send-off %
(fn [state]
(repeatedly extent
monotonic-unix-time-and-random-counter)))
clock/monotonic-unix-time-and-random-counter)))
agents)
_ (apply await working)
answers (mapv deref working)]
(testing (str "concurrent timestamp uniqueness (" concur " threads)...")
(is (=
(* concur extent)
(count (apply clojure.set/union (map set answers))))))
(count (apply set/union (map set answers))))))
(testing (str "concurrent monotonic increasing (" concur " threads)...")
(doseq [answer answers]
(let [[time counter] (first answer)]
Expand Down
16 changes: 8 additions & 8 deletions test/clj_uuid/node_test.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(ns clj-uuid.node-test
(:require [clojure.test :refer :all]
[clj-uuid.node :refer :all]))
(:require [clj-uuid.node :as node]
[clojure.test :refer :all]))


(deftest check-node-id
(testing "existance and type of node id...")
(is (= (node-id) (node-id)))
(is (coll? (node-id)))
(is (= 6 (count (node-id))))
(is (every? number? (node-id)))
(is (= 1 (bit-and 0x01 @+node-id+)))
(is (instance? Long @+node-id+)))
(is (= (node/node-id) (node/node-id)))
(is (coll? (node/node-id)))
(is (= 6 (count (node/node-id))))
(is (every? number? (node/node-id)))
(is (= 1 (bit-and 0x01 @node/+node-id+)))
(is (instance? Long @node/+node-id+)))
18 changes: 9 additions & 9 deletions test/clj_uuid/v1_test.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
(ns clj-uuid.v1-test
"Time based UUIDs tests"
(:require [clojure.test :refer :all]
[clojure.set]
[clj-uuid :as uuid :refer [v1 get-timestamp]]
[clj-uuid.clock :as clock]))
(:require [clj-uuid.clock :as clock]
[clj-uuid.core :as uuid]
[clojure.set :as set]
[clojure.test :refer :all]))

(deftest check-v1-single-threaded
(let [iterations 1000000
groups 10]
(testing "single-thread v1 uuid uniqueness..."
(dotimes [_ groups]
(let [result (repeatedly iterations v1)]
(let [result (repeatedly iterations uuid/v1)]
(is (= (count result) (count (set result)))))))))

(deftest check-v1-concurrency
Expand All @@ -19,19 +19,19 @@
agents (map agent (repeat concur nil))
working (map #(send-off %
(fn [state]
(repeatedly extent v1)))
(repeatedly extent uuid/v1)))
agents)
_ (apply await working)
answers (map deref working)]
(testing (str "concurrent v1 uuid uniqueness (" concur " threads)...")
(is (= (* concur extent)
(count (apply clojure.set/union (map set answers))))))
(count (apply set/union (map set answers))))))
(testing (str "concurrent v1 monotonic increasing (" concur " threads)...")
(is (every? identity
(map #(apply < (map get-timestamp %)) answers)))))))
(map #(apply < (map uuid/get-timestamp %)) answers)))))))

(deftest check-get-timestamp
(let [time (clock/monotonic-time)]
(with-redefs [clock/monotonic-time (constantly time)]
(is (= time (uuid/get-timestamp (v1)))
(is (= time (uuid/get-timestamp (uuid/v1)))
"Timestamp should be retrievable from v1 UUID"))))
21 changes: 10 additions & 11 deletions test/clj_uuid/v3_test.clj
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
(ns clj-uuid.v3-test
(:refer-clojure :exclude [uuid? max])
(:require [clojure.test :refer :all]
[clj-uuid :refer :all :exclude [> < =]]))
(:require [clj-uuid.core :as uuid]
[clojure.test :refer :all]))


(deftest check-v3-special-cases
(testing "v3 special case correctness..."
(is (=
(v3 +null+ "")
(uuid/v3 uuid/+null+ "")
#uuid "4ae71336-e44b-39bf-b9d2-752e234818a5"))
(is (=
(v3 +namespace-x500+ "")
(uuid/v3 uuid/+namespace-x500+ "")
#uuid "7AAF118C-F174-3EBA-9EC5-680CD791A020"))
(is (=
(v3 +namespace-oid+ "")
(uuid/v3 uuid/+namespace-oid+ "")
#uuid "596B79DC-00DD-3991-A72F-D3696C38C64F"))
(is (=
(v3 +namespace-dns+ "")
(uuid/v3 uuid/+namespace-dns+ "")
#uuid "C87EE674-4DDC-3EFE-A74E-DFE25DA5D7B3"))
(is (=
(v3 +namespace-url+ "")
(uuid/v3 uuid/+namespace-url+ "")
#uuid "14CDB9B4-DE01-3FAA-AFF5-65BC2F771745"))))


Expand Down Expand Up @@ -125,7 +124,7 @@
(deftest check-v3-null-ns-cases
(testing "v3 null-ns case-based correctness..."
(doseq [case +v3-null-ns-cases+]
(is (= (second case) (v3 +null+ (first case)))))))
(is (= (second case) (uuid/v3 uuid/+null+ (first case)))))))
(def +v3-dns-ns-cases+
Expand Down Expand Up @@ -230,7 +229,7 @@
(deftest check-v3-dns-ns-cases
(testing "v3 dns-ns case-based correctness..."
(doseq [case +v3-dns-ns-cases+]
(is (= (second case) (v3 +namespace-dns+ (first case)))))))
(is (= (second case) (uuid/v3 uuid/+namespace-dns+ (first case)))))))
(def +v3-oid-ns-cases+
Expand Down Expand Up @@ -335,4 +334,4 @@
(deftest check-v3-oid-ns-cases
(testing "v3 oid-ns case-based correctness..."
(doseq [case +v3-oid-ns-cases+]
(is (= (second case) (v3 +namespace-oid+ (first case)))))))
(is (= (second case) (uuid/v3 uuid/+namespace-oid+ (first case)))))))
15 changes: 7 additions & 8 deletions test/clj_uuid/v4_test.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
(ns clj-uuid.v4-test
"Custom UUIDs tests"
(:refer-clojure :exclude [uuid? max])
(:require [clojure.test :refer :all]
[clj-uuid :refer :all :exclude [> < =]]))
(:require [clj-uuid.core :as uuid]
[clojure.test :refer :all]))

(deftest check-v4-special-cases
(testing "v4 special case correctness..."
(is (= (v4 0 0) #uuid "00000000-0000-4000-8000-000000000000"))
(is (= (v4 0 1) #uuid "00000000-0000-4000-8000-000000000001"))
(is (= (v4 0 -1) #uuid "00000000-0000-4000-bfff-ffffffffffff"))
(is (= (v4 -1 0) #uuid "ffffffff-ffff-4fff-8000-000000000000"))
(is (= (v4 -1 -1) #uuid "ffffffff-ffff-4fff-bfff-ffffffffffff"))))
(is (= (uuid/v4 0 0) #uuid "00000000-0000-4000-8000-000000000000"))
(is (= (uuid/v4 0 1) #uuid "00000000-0000-4000-8000-000000000001"))
(is (= (uuid/v4 0 -1) #uuid "00000000-0000-4000-bfff-ffffffffffff"))
(is (= (uuid/v4 -1 0) #uuid "ffffffff-ffff-4fff-8000-000000000000"))
(is (= (uuid/v4 -1 -1) #uuid "ffffffff-ffff-4fff-bfff-ffffffffffff"))))
27 changes: 11 additions & 16 deletions test/clj_uuid/v5_test.clj
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
(ns clj-uuid.v5-test
(:refer-clojure :exclude [uuid? max])
(:require [clojure.test :refer :all]
[clj-uuid :refer :all :exclude [> < =]]))


(:require [clj-uuid.core :as uuid]
[clojure.test :refer :all]))

(deftest check-v5-special-cases
(testing "v5 special case correctness..."
(is (=
(v5 +null+ "")
(uuid/v5 uuid/+null+ "")
#uuid "E129F27C-5103-5C5C-844B-CDF0A15E160D"))
(is (=
(v5 +namespace-x500+ "")
(uuid/v5 uuid/+namespace-x500+ "")
#uuid "B4BDF874-8C03-5BD8-8FD7-5E409DFD82C0"))
(is (=
(v5 +namespace-oid+ "")
(uuid/v5 uuid/+namespace-oid+ "")
#uuid "0A68EB57-C88A-5F34-9E9D-27F85E68AF4F"))
(is (=
(v5 +namespace-dns+ "")
(uuid/v5 uuid/+namespace-dns+ "")
#uuid "4EBD0208-8328-5D69-8C44-EC50939C0967"))
(is (=
(v5 +namespace-url+ "")
(uuid/v5 uuid/+namespace-url+ "")
#uuid "1B4DB7EB-4057-5DDF-91E0-36DEC72071F5"))))

(def +v5-null-ns-cases+
Expand Down Expand Up @@ -118,15 +115,13 @@
("{|}~ !\"#$%&'()*+,-./012345" #uuid "37CDD9D8-A94F-5BB5-AA57-97A92ACA22FC")
("|}~ !\"#$%&'()*+,-./0123456" #uuid "BB23D8C2-29F0-5EC5-BF50-B7092FA62204")
("}~ !\"#$%&'()*+,-./01234567" #uuid "AD3AD027-A2ED-5F09-B581-78AD87D86A7C")
("~ !\"#$%&'()*+,-./012345678" #uuid "093B7461-98EF-55DC-8616-890210247499")
))
("~ !\"#$%&'()*+,-./012345678" #uuid "093B7461-98EF-55DC-8616-890210247499")))
(deftest check-v5-null-ns-cases
(testing "v5 null-ns case-based correctness..."
(doseq [case +v5-null-ns-cases+]
(is (= (second case) (v5 +null+ (first case)))))))
(is (= (second case) (uuid/v5 uuid/+null+ (first case)))))))
(def +v5-dns-ns-cases+
Expand Down Expand Up @@ -231,7 +226,7 @@
(deftest check-v5-dns-ns-cases
(testing "v5 dns-ns case-based correctness..."
(doseq [case +v5-dns-ns-cases+]
(is (= (second case) (v5 +namespace-dns+ (first case)))))))
(is (= (second case) (uuid/v5 uuid/+namespace-dns+ (first case)))))))
(def +v5-oid-ns-cases+
Expand Down Expand Up @@ -336,4 +331,4 @@
(deftest check-v5-oid-ns-cases
(testing "v5 oid-ns case-based correctness..."
(doseq [case +v5-oid-ns-cases+]
(is (= (second case) (v5 +namespace-oid+ (first case)))))))
(is (= (second case) (uuid/v5 uuid/+namespace-oid+ (first case)))))))
18 changes: 9 additions & 9 deletions test/clj_uuid/v6_test.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
(ns clj-uuid.v6-test
"Time based UUIDs tests"
(:require [clojure.test :refer :all]
[clojure.set]
[clj-uuid :as uuid :refer [v6 get-timestamp]]
[clj-uuid.clock :as clock]))
"Time based UUID tests"
(:require [clj-uuid.clock :as clock]
[clj-uuid.core :as uuid]
[clojure.set :as set]
[clojure.test :refer :all]))

(deftest check-v6-single-threaded
(let [iterations 1000000
groups 10]
(testing "single-thread v6 uuid uniqueness..."
(dotimes [_ groups]
(let [result (repeatedly iterations v6)]
(let [result (repeatedly iterations uuid/v6)]
(is (= (count result) (count (set result)))))))))

(deftest check-v6-concurrency
Expand All @@ -19,19 +19,19 @@
agents (map agent (repeat concur nil))
working (map #(send-off %
(fn [state]
(repeatedly extent v6)))
(repeatedly extent uuid/v6)))
agents)
_ (apply await working)
answers (map deref working)]
(testing (str "concurrent v6 uuid uniqueness (" concur " threads)...")
(is (= (* concur extent)
(count (apply clojure.set/union (map set answers))))))
(count (apply set/union (map set answers))))))
(testing (str "concurrent v6 monotonic increasing (" concur " threads)...")
(is (every? identity (map (partial apply uuid/<) answers)))))))

(deftest check-get-timestamp
(dotimes [_ 1000000]
(let [time (clock/monotonic-time)]
(with-redefs [clock/monotonic-time (constantly time)]
(is (= time (uuid/get-timestamp (v6)))
(is (= time (uuid/get-timestamp (uuid/v6)))
"Timestamp should be retrievable from v6 UUID")))))
Loading

0 comments on commit e01cf1c

Please sign in to comment.