Created
May 12, 2018 12:14
-
-
Save eerohele/264cfd70794dca0f559e7e5170c95765 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def app-db | |
{:nurses {"Nurse ID A" "Name A" | |
"Nurse ID B" "Name B"} | |
:patients [{:patient-id "Patient ID A"} | |
{:patient-id "Patient ID B"}] | |
;; A map that shows which nurse is assigned to which patient. | |
:assignments {"Patient ID A" "Nurse ID A" | |
"Patient ID B" "Nurse ID B"}}) | |
(require '[clojure.spec.alpha :as spec] | |
'[clojure.string :as string] | |
'[clojure.test.check.generators :as gen]) | |
(spec/def ::non-blank-string | |
(spec/and string? (complement string/blank?))) | |
(spec/def ::nurse-id ::non-blank-string) | |
(spec/def ::nurse-name ::non-blank-string) | |
(spec/def ::patient-id ::non-blank-string) | |
(spec/def ::nurses | |
(spec/map-of ::nurse-id ::nurse-name)) | |
(spec/def ::patient | |
(spec/keys :req-un [::patient-id])) | |
(spec/def ::patients | |
(spec/coll-of ::patient)) | |
(spec/def ::assignments | |
(spec/map-of ::patient-id ::nurse-id :min-size 1)) | |
(spec/def ::app-db | |
(spec/keys :req-un [::nurses ::patients ::assignments])) | |
(comment | |
;; Is there a way to generate examples of the spec such that every | |
;; entry in assignment uses a key generated by ::patient-id and a val | |
;; generated by ::nurse-id? | |
(gen/generate (spec/gen ::app-db) 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment