-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen.clj
46 lines (41 loc) · 1.47 KB
/
gen.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
;; Technique for avoiding strings with a forbidden character.
(def gen-file-name
(get/fmap #(clojure.string/replace % "/" "")
gen/string-ascii))
;; Generate octal permissions.
(def gen-permissions-octal
(gen/fmap #(format "%03o" %)
(gen/large-integer {:min 0 :max 0777})))
;; Alternative for date-time generation.
(def gen-date-time-components
(gen/hash-map
:year (gen/fmap #(+ % 1903) gen/int)
:month (gen/large-integer* {:min 1 :max 12})
:day (gen/large-integer* {:min 1 :max 31})
:hour (gen/large-integer* {:min 0 :max 23})
:minute (gen/large-integer* {:min 0 :max 59})
:second (gen/large-integer* {:min 0 :max 59})
:millis (gen/large-integer* {:min 0 :max 999})))
(defn construct-date-time
[{:keys [year month day
hour minute second millis]}]
(try
(java.time.Instant/parse
(format "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ"
year month day
hour minute second millis))
(catch Exception e
(java.time.Instant/parse
(format "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ"
year month 28
hour minute second millis)))))
(def gen-date-time-2
(gen/fmap construct-date-time
gen-date-time-components))
;; Generate width first, then use bind to generate
;; a collection of vectors with the same width.
(gen/let [width gen/nat
rows (gen/vector
(gen/vector gen/large-integer
width))]
rows)