From 4f2a90f123c4bae0d7789b24f01c989794b74968 Mon Sep 17 00:00:00 2001 From: Seb Bailey Date: Wed, 21 Aug 2019 16:19:08 +0100 Subject: [PATCH 01/10] Added full stop --- doc/dsdr/0001-joiners-as-poisson-process.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dsdr/0001-joiners-as-poisson-process.md b/doc/dsdr/0001-joiners-as-poisson-process.md index 0c3cb32..19c6899 100644 --- a/doc/dsdr/0001-joiners-as-poisson-process.md +++ b/doc/dsdr/0001-joiners-as-poisson-process.md @@ -14,7 +14,7 @@ general population for each age as is done in witan.send. ## Status -Accepted +Accepted. ## Consequences From 6b6ecaea3d8c7478bb66949928378990e1d3197e Mon Sep 17 00:00:00 2001 From: Seb Bailey Date: Wed, 21 Aug 2019 16:19:37 +0100 Subject: [PATCH 02/10] Apply birthdays tests & dsdr --- doc/dsdr/0006-apply-birthdays.md | 17 ++++++++++++ test/cic/projection_test.clj | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 doc/dsdr/0006-apply-birthdays.md create mode 100644 test/cic/projection_test.clj diff --git a/doc/dsdr/0006-apply-birthdays.md b/doc/dsdr/0006-apply-birthdays.md new file mode 100644 index 0000000..843f9de --- /dev/null +++ b/doc/dsdr/0006-apply-birthdays.md @@ -0,0 +1,17 @@ +### Applying birthdays with only a year of birth + +## Context + +In order to aid in preventing re-identification episode data only birth years have been provided. However in order to provide a more realistic distribution of ages and birthdays for modelling, arbitary birth dates are required. + +## Decision + +Each projection will use randomly generated birthdays with corresponding random ages of admission, EACH CONTROLLED WITH A SEED (not yet implemented). This allows the output to account for uncertainty in the input. + +## Status + +Accepted. + +## Consequences + +Actual counts of individuals at particular ages are simply approximations and only generally reflect the "real" population. This methodology does not capture any trends that may be present in age distribution, for example if more children are born in August. diff --git a/test/cic/projection_test.clj b/test/cic/projection_test.clj new file mode 100644 index 0000000..860f7b9 --- /dev/null +++ b/test/cic/projection_test.clj @@ -0,0 +1,45 @@ +(ns cic.projection-test + (:require [cic.projection :refer :all] + [clojure.test :refer :all] + [cic.core :as c] + [cic.model :as m] + [clj-time.core :as t])) + +(def example (c/episodes->periods (c/episodes (map c/format-episode '({:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-02-18", :id "120", :report-year "2017", :placement "K1", :report-date "2017-02-10"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-04-18", :id "120", :report-year "2017", :placement "K2", :report-date "2017-02-18"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2015-02-18", :id "120", :report-year "2015", :placement "U1", :report-date "2015-02-10"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2014-02-18", :id "120", :report-year "2014", :placement "U1", :report-date "2014-02-10"} + {:sex "2", :care-status "B1", :legal-status "C1", :uasc "False", :dob "2000", :ceased nil, :id "121", :report-year "2017", :placement "U1", :report-date "2017-02-10"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1998", :ceased "2017-05-18", :id "122", :report-year "2017", :placement "U2", :report-date "2017-05-10"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1998", :ceased nil, :id "122", :report-year "2018", :placement "U2", :report-date "2018-05-10"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"} + {:sex "2", :care-status "N1", :legal-status "V3", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"} + {:sex "2", :care-status "N1", :legal-status "V4", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"}))))) + +(def d-model (m/duration-model {0 [[0 0 0] [1 6 17] [35 56 83]] + 1 [[0 0 0] [1 6 17] [35 56 83]] + 2 [[0 0 0] [1 6 17] [35 56 83]] + 3 [[0 0 0] [1 6 17] [35 56 83]] + 4 [[0 0 0] [1 6 17] [35 56 83]] + 5 [[0 0 0] [1 6 17] [35 56 83]] + 6 [[0 0 0] [1 6 17] [35 56 83]] + 7 [[0 0 0] [1 6 17] [35 56 83]] + 8 [[0 0 0] [1 6 17] [35 56 83]] + 9 [[0 0 0] [1 6 17] [35 56 83]] + 10 [[0 0 0] [1 6 17] [35 56 83]] + 11 [[0 0 0] [1 6 17] [35 56 83]] + 12 [[0 0 0] [1 6 17] [35 56 83]] + 13 [[0 0 0] [1 6 17] [35 56 83]] + 14 [[0 0 0] [1 6 17] [35 56 83]] + 15 [[0 0 0] [1 6 17] [35 56 83]] + 16 [[0 0 0] [1 6 17] [35 56 83]] + 17 [[0 0 0] [1 6 17] [35 56 83]] + 18 [[0 0 0] [1 6 17] [35 56 83]]})) + +(deftest prepare-ages-test + (let [result (first (prepare-ages example))] + (testing "birthday is within correct year" + (is (= 14 (t/in-years (t/interval (:birthday (first (prepare-ages example))) (t/date-time 2014)))))) + (testing "admission age in correctly calculated" + (is (= (- (t/in-years (t/interval (t/date-time 1999) (t/date-time 2014))) 1) + (:admission-age (first (prepare-ages example)))))))) From 1da9db376d80d23eadda7ad1102a05b8d9c49530 Mon Sep 17 00:00:00 2001 From: Seb Bailey Date: Wed, 21 Aug 2019 16:56:34 +0100 Subject: [PATCH 03/10] Fix core tests with rebase --- test/cic/core_test.clj | 59 +++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/test/cic/core_test.clj b/test/cic/core_test.clj index 47f951f..f71b1c9 100644 --- a/test/cic/core_test.clj +++ b/test/cic/core_test.clj @@ -23,32 +23,33 @@ (testing "3 unmodelled episodes removed corresponding to UASC, V3 and V4" (is (= 7 (count (remove-unmodelled-episodes data)))))) -#_(deftest episodes-test - (testing "remove invalid records" - (is (= 5 (count (episodes data)))))) - - -#_(deftest assoc-period-id-test - (testing "id 120 consists of 3 periods" - (let [child (filter #(= (:child-id %) 120) (episodes data)) - result (assoc-period-id child)] - (is (= 3 (count (distinct result)))) - (is (= '("120-0" "120-1" "120-2") (map :period-id result)))))) - - -#_(deftest summarise-periods-at-test - (let [result (->> (episodes data) - (assoc-period-id) - (group-by :period-id) - (vals) - (map #(summarise-periods-at % projection-start)))] - (testing "a single open episode" - (is (= 1 (count (filter #(= true (:open? %)) result))))) - (testing "duration in care calculated" - (is (= 1550 (:duration (first (filter #(= (:period-id %) "120-0") result)))))) - (testing "multiple episodes in a period" - (is (= [{:offset 0, :placement :K1} {:offset 8, :placement :K2}] - (->> result - (filter #(= (:period-id %) "120-2")) - first - :episodes)))))) +(deftest episodes-test + (testing "remove invalid records" + (is (= 6 (count (episodes data)))))) + + +(deftest assoc-period-id-test + (testing "id 120 consists of 3 periods" + (let [child (filter #(= (:child-id %) 120) (episodes data)) + result (assoc-period-id child)] + (is (= 4 (count (distinct result)))) + (is (= '("120-0" "120-1" "120-2") (distinct (map :period-id result))))))) + + +(deftest summarise-periods-test + (let [result (->> (episodes data) + (assoc-period-id) + (group-by :period-id) + (vals) + (map (comp #(assoc-open-at % projection-start) + summarise-periods)))] + (testing "remove open episodes" + (is (= (- (count (episodes data)) 1) (count result)))) + (testing "duration in care calculated" + (is (= 8 (:duration (first (filter #(= (:period-id %) "120-0") result)))))) + (testing "multiple episodes in a period" + (is (= [{:offset 0, :placement :K1} {:offset 8, :placement :K2}] + (->> result + (filter #(= (:period-id %) "120-2")) + first + :episodes)))))) From fc134e77a2e4372513673190ee6b5cc2522e4ac6 Mon Sep 17 00:00:00 2001 From: Seb Bailey Date: Thu, 22 Aug 2019 16:58:36 +0100 Subject: [PATCH 04/10] Fixed prepare-ages test --- test/cic/projection_test.clj | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/cic/projection_test.clj b/test/cic/projection_test.clj index 860f7b9..4605ff5 100644 --- a/test/cic/projection_test.clj +++ b/test/cic/projection_test.clj @@ -3,7 +3,8 @@ [clojure.test :refer :all] [cic.core :as c] [cic.model :as m] - [clj-time.core :as t])) + [clj-time.core :as t] + [clojure.test.check.random :as r])) (def example (c/episodes->periods (c/episodes (map c/format-episode '({:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-02-18", :id "120", :report-year "2017", :placement "K1", :report-date "2017-02-10"} {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-04-18", :id "120", :report-year "2017", :placement "K2", :report-date "2017-02-18"} @@ -37,9 +38,9 @@ 18 [[0 0 0] [1 6 17] [35 56 83]]})) (deftest prepare-ages-test - (let [result (first (prepare-ages example))] + (let [result (prepare-ages example (r/make-random 50))] (testing "birthday is within correct year" - (is (= 14 (t/in-years (t/interval (:birthday (first (prepare-ages example))) (t/date-time 2014)))))) + (is (= 14 (t/in-years (t/interval (:birthday (first result)) (t/date-time 2014)))))) (testing "admission age in correctly calculated" - (is (= (- (t/in-years (t/interval (t/date-time 1999) (t/date-time 2014))) 1) - (:admission-age (first (prepare-ages example)))))))) + (is (= (t/in-years (t/interval (t/date-time 1999) (t/date-time 2014))) + (:admission-age (first result))))))) From 10959c3fbf23516ead8fc644f9a2972ec9f35e05 Mon Sep 17 00:00:00 2001 From: Seb Bailey Date: Thu, 29 Aug 2019 16:26:00 +0100 Subject: [PATCH 05/10] day-seq test --- test/cic/projection_test.clj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/cic/projection_test.clj b/test/cic/projection_test.clj index 4605ff5..8ead142 100644 --- a/test/cic/projection_test.clj +++ b/test/cic/projection_test.clj @@ -44,3 +44,9 @@ (testing "admission age in correctly calculated" (is (= (t/in-years (t/interval (t/date-time 1999) (t/date-time 2014))) (:admission-age (first result))))))) + +(deftest days-seq-test + (let [start (clj-time.format/parse date-format "2010-03-31") + end (clj-time.format/parse date-format "2010-04-30")] + (testing "a months period creates date for 4 weeks + 1 initial week" + (is (= 5 (count (day-seq start end))))))) From 6b899b30784b7c632b55c7f6ab222e6032f08b34 Mon Sep 17 00:00:00 2001 From: Seb Bailey Date: Mon, 2 Sep 2019 10:57:18 +0100 Subject: [PATCH 06/10] Daily summary test --- test/cic/projection_test.clj | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/cic/projection_test.clj b/test/cic/projection_test.clj index 8ead142..fcbdfe8 100644 --- a/test/cic/projection_test.clj +++ b/test/cic/projection_test.clj @@ -4,6 +4,7 @@ [cic.core :as c] [cic.model :as m] [clj-time.core :as t] + [clj-time.format :as f] [clojure.test.check.random :as r])) (def example (c/episodes->periods (c/episodes (map c/format-episode '({:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-02-18", :id "120", :report-year "2017", :placement "K1", :report-date "2017-02-10"} @@ -37,6 +38,9 @@ 17 [[0 0 0] [1 6 17] [35 56 83]] 18 [[0 0 0] [1 6 17] [35 56 83]]})) +(def date-format + (f/formatter :date)) + (deftest prepare-ages-test (let [result (prepare-ages example (r/make-random 50))] (testing "birthday is within correct year" @@ -46,7 +50,16 @@ (:admission-age (first result))))))) (deftest days-seq-test - (let [start (clj-time.format/parse date-format "2010-03-31") - end (clj-time.format/parse date-format "2010-04-30")] + (let [start (f/parse date-format "2010-03-31") + end (f/parse date-format "2010-04-30")] (testing "a months period creates date for 4 weeks + 1 initial week" (is (= 5 (count (day-seq start end))))))) + +(deftest daily-summary-test + (let [result (daily-summary (prepare-ages example (r/make-random 50)) + (f/parse date-format "2015-02-10") + (f/parse date-format "2015-02-28"))] + (testing "frequency count of one 15yr old in Q1 for two weeks out of a possible three" + (= 3 (count result)) + (is (= 2 (reduce + (map #(get (val %) 15) result)))) + (is (= 2 (reduce + (map #(get (val %) :Q1) result))))))) From 79ccb498c41a6f5161ffecb4d942b4e6e0799a2b Mon Sep 17 00:00:00 2001 From: Seb Bailey Date: Tue, 3 Sep 2019 13:29:27 +0100 Subject: [PATCH 07/10] Tidy projection_test ns --- test/cic/projection_test.clj | 39 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/test/cic/projection_test.clj b/test/cic/projection_test.clj index fcbdfe8..4b113d0 100644 --- a/test/cic/projection_test.clj +++ b/test/cic/projection_test.clj @@ -7,16 +7,22 @@ [clj-time.format :as f] [clojure.test.check.random :as r])) -(def example (c/episodes->periods (c/episodes (map c/format-episode '({:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-02-18", :id "120", :report-year "2017", :placement "K1", :report-date "2017-02-10"} - {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-04-18", :id "120", :report-year "2017", :placement "K2", :report-date "2017-02-18"} - {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2015-02-18", :id "120", :report-year "2015", :placement "U1", :report-date "2015-02-10"} - {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2014-02-18", :id "120", :report-year "2014", :placement "U1", :report-date "2014-02-10"} - {:sex "2", :care-status "B1", :legal-status "C1", :uasc "False", :dob "2000", :ceased nil, :id "121", :report-year "2017", :placement "U1", :report-date "2017-02-10"} - {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1998", :ceased "2017-05-18", :id "122", :report-year "2017", :placement "U2", :report-date "2017-05-10"} - {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1998", :ceased nil, :id "122", :report-year "2018", :placement "U2", :report-date "2018-05-10"} - {:sex "2", :care-status "N1", :legal-status "C2", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"} - {:sex "2", :care-status "N1", :legal-status "V3", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"} - {:sex "2", :care-status "N1", :legal-status "V4", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"}))))) +(def example-data '({:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-02-18", :id "120", :report-year "2017", :placement "K1", :report-date "2017-02-10"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-04-18", :id "120", :report-year "2017", :placement "K2", :report-date "2017-02-18"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2015-02-18", :id "120", :report-year "2015", :placement "U1", :report-date "2015-02-10"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2014-02-18", :id "120", :report-year "2014", :placement "U1", :report-date "2014-02-10"} + {:sex "2", :care-status "B1", :legal-status "C1", :uasc "False", :dob "2000", :ceased nil, :id "121", :report-year "2017", :placement "U1", :report-date "2017-02-10"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1998", :ceased "2017-05-18", :id "122", :report-year "2017", :placement "U2", :report-date "2017-05-10"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1998", :ceased nil, :id "122", :report-year "2018", :placement "U2", :report-date "2018-05-10"} + {:sex "2", :care-status "N1", :legal-status "C2", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"} + {:sex "2", :care-status "N1", :legal-status "V3", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"} + {:sex "2", :care-status "N1", :legal-status "V4", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"})) + +(def example (prepare-ages (->> example-data + (map c/format-episode) + c/episodes + c/episodes->periods) + (r/make-random 50))) (def d-model (m/duration-model {0 [[0 0 0] [1 6 17] [35 56 83]] 1 [[0 0 0] [1 6 17] [35 56 83]] @@ -42,12 +48,11 @@ (f/formatter :date)) (deftest prepare-ages-test - (let [result (prepare-ages example (r/make-random 50))] - (testing "birthday is within correct year" - (is (= 14 (t/in-years (t/interval (:birthday (first result)) (t/date-time 2014)))))) - (testing "admission age in correctly calculated" - (is (= (t/in-years (t/interval (t/date-time 1999) (t/date-time 2014))) - (:admission-age (first result))))))) + (testing "birthday is within correct year" + (is (= 14 (t/in-years (t/interval (:birthday (first example)) (t/date-time 2014)))))) + (testing "admission age in correctly calculated" + (is (= (t/in-years (t/interval (t/date-time 1999) (t/date-time 2014))) + (:admission-age (first example)))))) (deftest days-seq-test (let [start (f/parse date-format "2010-03-31") @@ -56,7 +61,7 @@ (is (= 5 (count (day-seq start end))))))) (deftest daily-summary-test - (let [result (daily-summary (prepare-ages example (r/make-random 50)) + (let [result (daily-summary example (f/parse date-format "2015-02-10") (f/parse date-format "2015-02-28"))] (testing "frequency count of one 15yr old in Q1 for two weeks out of a possible three" From b18e8b9c4da5394424535ed3819e978ffab777b4 Mon Sep 17 00:00:00 2001 From: Seb Bailey Date: Wed, 4 Sep 2019 17:22:38 +0100 Subject: [PATCH 08/10] Add dependencies --- test/cic/projection_test.clj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/cic/projection_test.clj b/test/cic/projection_test.clj index 4b113d0..36ac25e 100644 --- a/test/cic/projection_test.clj +++ b/test/cic/projection_test.clj @@ -5,7 +5,9 @@ [cic.model :as m] [clj-time.core :as t] [clj-time.format :as f] - [clojure.test.check.random :as r])) + [clojure.test.check.random :as r] + [kixi.stats.distribution :as d] + [kixi.stats.protocols :as p])) (def example-data '({:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-02-18", :id "120", :report-year "2017", :placement "K1", :report-date "2017-02-10"} {:sex "2", :care-status "N1", :legal-status "C2", :uasc "False", :dob "1999", :ceased "2017-04-18", :id "120", :report-year "2017", :placement "K2", :report-date "2017-02-18"} From 6ccf140eaf6cb50c3cf38e47651429e05681e84a Mon Sep 17 00:00:00 2001 From: Seb Bailey Date: Wed, 4 Sep 2019 17:22:58 +0100 Subject: [PATCH 09/10] Bespoke duration model --- test/cic/projection_test.clj | 55 ++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/test/cic/projection_test.clj b/test/cic/projection_test.clj index 36ac25e..3b13242 100644 --- a/test/cic/projection_test.clj +++ b/test/cic/projection_test.clj @@ -20,31 +20,44 @@ {:sex "2", :care-status "N1", :legal-status "V3", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"} {:sex "2", :care-status "N1", :legal-status "V4", :uasc "True", :dob "1999", :ceased "2017-07-18", :id "124", :report-year "2017", :placement "U2", :report-date "2017-06-10"})) +(def seed (r/make-random 50)) + (def example (prepare-ages (->> example-data (map c/format-episode) c/episodes - c/episodes->periods) - (r/make-random 50))) + c/episodes->periods) seed)) + +(defn duration-model-for-testing + "Given an admitted date and age of a child in care, + returns an expected duration in days - copied from + witan.cic.model" + [coefs] + (fn [age seed] + (let [empirical (get coefs (max 0 (min age 17))) + [r1 r2] (r/split seed) + quantile (int (p/sample-1 (d/uniform {:a 1 :b 3}) r1)) + [lower median upper] (get empirical quantile)] + (m/sample-ci lower median upper r2)))) -(def d-model (m/duration-model {0 [[0 0 0] [1 6 17] [35 56 83]] - 1 [[0 0 0] [1 6 17] [35 56 83]] - 2 [[0 0 0] [1 6 17] [35 56 83]] - 3 [[0 0 0] [1 6 17] [35 56 83]] - 4 [[0 0 0] [1 6 17] [35 56 83]] - 5 [[0 0 0] [1 6 17] [35 56 83]] - 6 [[0 0 0] [1 6 17] [35 56 83]] - 7 [[0 0 0] [1 6 17] [35 56 83]] - 8 [[0 0 0] [1 6 17] [35 56 83]] - 9 [[0 0 0] [1 6 17] [35 56 83]] - 10 [[0 0 0] [1 6 17] [35 56 83]] - 11 [[0 0 0] [1 6 17] [35 56 83]] - 12 [[0 0 0] [1 6 17] [35 56 83]] - 13 [[0 0 0] [1 6 17] [35 56 83]] - 14 [[0 0 0] [1 6 17] [35 56 83]] - 15 [[0 0 0] [1 6 17] [35 56 83]] - 16 [[0 0 0] [1 6 17] [35 56 83]] - 17 [[0 0 0] [1 6 17] [35 56 83]] - 18 [[0 0 0] [1 6 17] [35 56 83]]})) +(def d-model (duration-model-for-testing {0 [[0 0 0] [1 6 17] [35 56 83]] + 1 [[0 0 0] [1 6 17] [35 56 83]] + 2 [[0 0 0] [1 6 17] [35 56 83]] + 3 [[0 0 0] [1 6 17] [35 56 83]] + 4 [[0 0 0] [1 6 17] [35 56 83]] + 5 [[0 0 0] [1 6 17] [35 56 83]] + 6 [[0 0 0] [1 6 17] [35 56 83]] + 7 [[0 0 0] [1 6 17] [35 56 83]] + 8 [[0 0 0] [1 6 17] [35 56 83]] + 9 [[0 0 0] [1 6 17] [35 56 83]] + 10 [[0 0 0] [1 6 17] [35 56 83]] + 11 [[0 0 0] [1 6 17] [35 56 83]] + 12 [[0 0 0] [1 6 17] [35 56 83]] + 13 [[0 0 0] [1 6 17] [35 56 83]] + 14 [[0 0 0] [1 6 17] [35 56 83]] + 15 [[0 0 0] [1 6 17] [35 56 83]] + 16 [[0 0 0] [1 6 17] [35 56 83]] + 17 [[0 0 0] [1 6 17] [35 56 83]] + 18 [[0 0 0] [1 6 17] [35 56 83]]})) (def date-format (f/formatter :date)) From aa63d6bc48f787e1edf48fe5cce5236391d05ecb Mon Sep 17 00:00:00 2001 From: Seb Bailey Date: Wed, 4 Sep 2019 17:23:13 +0100 Subject: [PATCH 10/10] Project period close tests --- test/cic/projection_test.clj | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/cic/projection_test.clj b/test/cic/projection_test.clj index 3b13242..5ca4e06 100644 --- a/test/cic/projection_test.clj +++ b/test/cic/projection_test.clj @@ -83,3 +83,14 @@ (= 3 (count result)) (is (= 2 (reduce + (map #(get (val %) 15) result)))) (is (= 2 (reduce + (map #(get (val %) :Q1) result))))))) + +(def e-model (m/episodes-model example)) + +(deftest project-period-close-test + (let [open-data (-> example first (assoc :open? true)) + result (project-period-close d-model e-model open-data seed)] + (testing "duration increases" + (is (> (:duration result) (:duration (first example))))) + (testing "duration is different with alternate seed" + (is (not= (:duration (project-period-close d-model e-model open-data (r/make-random 49))) + (:duration (first example)))))))