Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env planck -D org.clojure/test.check:0.10.0-alpha2 -K
  2. (ns generate-calls
  3.   (:require [clojure.spec.alpha :as s]
  4.             [clojure.test.check.generators :as gen])
  5.   (:require-macros [clojure.test.check.generators :as gen]))
  6.  
  7. (s/def ::direction #{"inbound" "outbound"})
  8. (s/def ::duration pos-int?)
  9. (s/def ::id pos-int?)
  10. (s/def ::agent_id (s/with-gen pos-int? #(s/gen (set (range 10)))))
  11. (s/def ::group_id (s/with-gen pos-int? #(s/gen (set (range 3)))))
  12. (s/def ::start_time (s/int-in 0 (-> (js/Date.) .getTime)))
  13. (s/def ::end_time (s/int-in 0 (-> (js/Date.) .getTime)))
  14.  
  15. (def call-no-constraints-map (s/keys :req-un [::direction ::duration ::agent_id ::group_id ::id ::start_time ::end_time]))
  16. (defn call-gen []
  17.   (gen/let [e (s/gen call-no-constraints-map)
  18.             duration (s/gen (s/int-in 1 3600))]
  19.     (assoc e :end_time (+ (:start_time e) duration)
  20.              :duration duration)))
  21. (s/def ::call (s/with-gen call-no-constraints-map call-gen))
  22.  
  23. (let [argv1 (first *command-line-args*)]
  24.   (dotimes [i (if argv1 (js/parseInt argv1) 1000000)]
  25.     (println (.stringify js/JSON (clj->js (assoc (gen/generate (s/gen ::call)) :id i))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement