Skip to content

Commit 6b46606

Browse files
committed
fix: improved model tests and tightened some scenarios
1 parent a08162d commit 6b46606

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

tests/models_tests/models_test.go

+23-14
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
281281
query = models.QueryFilterByCohortPairsHelper(filterCohortPairs, resultsDataSource, population.Id, "unionAndIntersect").
282282
Select("subject_id")
283283
_ = query.Scan(&subjectIds)
284-
// in this case we expect overlap the size of the largestCohort-5:
285-
if len(subjectIds) != (largestCohort.CohortSize - 5) {
284+
// in this case we expect overlap the size of the largestCohort-6 (where 6 is the size of the overlap between extendedCopyOfSecondLargestCohort and largestCohort):
285+
if len(subjectIds) != (largestCohort.CohortSize - 6) {
286286
t.Errorf("Expected %d overlap, found %d", largestCohort.CohortSize-5, len(subjectIds))
287287
}
288288

@@ -304,7 +304,7 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
304304
Select("subject_id")
305305
_ = query.Scan(&subjectIds)
306306
// in this case we expect same as previous test above:
307-
if len(subjectIds) != (largestCohort.CohortSize - 5) {
307+
if len(subjectIds) != (largestCohort.CohortSize - 6) {
308308
t.Errorf("Expected %d overlap, found %d", largestCohort.CohortSize-5, len(subjectIds))
309309
}
310310

@@ -495,8 +495,10 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairsW
495495
if len(stats) > len(stats2) {
496496
t.Errorf("First query is more restrictive, so its stats should not be larger than stats2 of second query. Got %d and %d", len(stats), len(stats2))
497497
}
498-
// test filtering with smallest cohort, lenght should be 1, since that's the size of the smallest cohort:
499-
// setting the same cohort id here (artificial...normally it should be two different ids):
498+
499+
// test filtering with secondLargestCohort, smallest and largestCohort.
500+
// Lenght of result set should be 2 persons (one HIS, one ASN), since there is a overlap of 1 between secondLargestCohort and smallest cohort,
501+
// and overlap of 2 between secondLargestCohort and largestCohort, BUT only 1 has a HARE value:
500502
filterCohortPairs = []utils.CustomDichotomousVariableDef{
501503
{
502504
CohortDefinitionId1: smallestCohort.Id,
@@ -506,7 +508,14 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairsW
506508
stats3, _ := conceptModel.RetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(testSourceId,
507509
secondLargestCohort.Id, filterIds, filterCohortPairs, breakdownConceptId)
508510
if len(stats3) != 2 {
509-
t.Errorf("Expected only two items in resultset, found %d", len(stats))
511+
t.Errorf("Expected only two items in resultset, found %d", len(stats3))
512+
}
513+
countPersons := 0
514+
for _, stat := range stats3 {
515+
countPersons = countPersons + stat.NpersonsInCohortWithValue
516+
}
517+
if countPersons != 2 {
518+
t.Errorf("Expected only two persons in resultset, found %d", countPersons)
510519
}
511520
}
512521

@@ -731,9 +740,9 @@ func TestRetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(t
731740
filterConceptIds := []int64{}
732741
filterCohortPairs := []utils.CustomDichotomousVariableDef{}
733742
data, _ := cohortDataModel.RetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(testSourceId, largestCohort.Id, histogramConceptId, filterConceptIds, filterCohortPairs)
734-
// everyone in the largestCohort has the histogramConceptId:
735-
if len(data) != largestCohort.CohortSize {
736-
t.Errorf("expected 10 or more histogram data but got %d", len(data))
743+
// everyone in the largestCohort has the histogramConceptId, but one person has NULL in the value_as_number:
744+
if len(data) != largestCohort.CohortSize-1 {
745+
t.Errorf("expected %d histogram data but got %d", largestCohort.CohortSize, len(data))
737746
}
738747

739748
// now filter on the extendedCopyOfSecondLargestCohort
@@ -873,11 +882,11 @@ func TestRetrieveCohortOverlapStats(t *testing.T) {
873882
CohortDefinitionId2: extendedCopyOfSecondLargestCohort.Id,
874883
ProvidedName: "test"},
875884
}
876-
// then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort:
885+
// then we expect overlap of 6 for extendedCopyOfSecondLargestCohort and largestCohort:
877886
stats, _ = cohortDataModel.RetrieveCohortOverlapStats(testSourceId, caseCohortId, controlCohortId,
878887
otherFilterConceptIds, filterCohortPairs)
879-
if stats.CaseControlOverlap != 5 {
880-
t.Errorf("Expected nr persons to be %d, found %d", 5, stats.CaseControlOverlap)
888+
if stats.CaseControlOverlap != 6 {
889+
t.Errorf("Expected nr persons to be %d, found %d", 6, stats.CaseControlOverlap)
881890
}
882891

883892
// extra test: different parameters that should return the same as above ^:
@@ -886,10 +895,10 @@ func TestRetrieveCohortOverlapStats(t *testing.T) {
886895
filterCohortPairs = []utils.CustomDichotomousVariableDef{}
887896
otherFilterConceptIds = []int64{histogramConceptId} // extra filter, to cover this part of the code...
888897
// then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort (the filter on histogramConceptId should not matter
889-
// since all in largestCohort have an observation for this concept id):
898+
// since all in largestCohort have an observation for this concept id except one person who has it but has value_as_number as NULL):
890899
stats2, _ := cohortDataModel.RetrieveCohortOverlapStats(testSourceId, caseCohortId, controlCohortId,
891900
otherFilterConceptIds, filterCohortPairs)
892-
if stats2.CaseControlOverlap != stats.CaseControlOverlap {
901+
if stats2.CaseControlOverlap != stats.CaseControlOverlap-1 {
893902
t.Errorf("Expected nr persons to be %d, found %d", stats.CaseControlOverlap, stats2.CaseControlOverlap)
894903
}
895904

tests/setup_local_db/test_data_results_and_cdm.sql

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ values
6868
(nextval('observation_id_seq'), 3,0,'1993-10-24','1993-10-24 00:00:00',38000276,NULL,'M',0,0,0,NULL,81,0,'713197008',0,NULL,NULL,NULL,0,NULL),
6969
(nextval('observation_id_seq'), 3,0,'1967-12-02','1967-12-02 00:00:00',38000276,NULL,NULL,0,0,0,NULL,114,0,'53741008',0,NULL,NULL,NULL,0,NULL),
7070
(nextval('observation_id_seq'), 4,0,'2012-06-06','2012-06-06 00:00:00',38000276,NULL,NULL,0,0,0,NULL,170,0,'403191005',0,NULL,NULL,NULL,0,NULL),
71+
-- person 5 has null in value_as_number here:
7172
(nextval('observation_id_seq'), 5,2000006885,'1993-11-17','1993-11-17 00:00:00',38000276,NULL,NULL,0,0,0,NULL,179,0,'162864005',0,NULL,NULL,NULL,0,NULL),
7273
(nextval('observation_id_seq'), 5,0,'2014-01-31','2014-01-31 00:00:00',38000276,NULL,NULL,0,0,0,NULL,197,0,'278860009',0,NULL,NULL,NULL,0,NULL),
7374
(nextval('observation_id_seq'), 6,2000006885,'2014-01-31','2014-01-31 00:00:00',38000276,5.41,NULL,0,0,0,NULL,197,0,'278860009',0,NULL,NULL,NULL,0,NULL),
@@ -156,6 +157,7 @@ values
156157
(32,9),
157158
(32,10),
158159
-- extra large cohort for testing histogram: (aka "largestCohort" in models_test.go script)
160+
(4,5),
159161
(4,6),
160162
(4,7),
161163
(4,8),

0 commit comments

Comments
 (0)