Skip to content

Commit ee831ee

Browse files
committed
fix: improved model tests and tightened some scenarios
1 parent 72cc84c commit ee831ee

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
@@ -280,8 +280,8 @@ func TestQueryFilterByCohortPairsHelper(t *testing.T) {
280280
query = models.QueryFilterByCohortPairsHelper(filterCohortPairs, resultsDataSource, population.Id, "unionAndIntersect").
281281
Select("subject_id")
282282
_ = query.Scan(&subjectIds)
283-
// in this case we expect overlap the size of the largestCohort-5:
284-
if len(subjectIds) != (largestCohort.CohortSize - 5) {
283+
// in this case we expect overlap the size of the largestCohort-6 (where 6 is the size of the overlap between extendedCopyOfSecondLargestCohort and largestCohort):
284+
if len(subjectIds) != (largestCohort.CohortSize - 6) {
285285
t.Errorf("Expected %d overlap, found %d", largestCohort.CohortSize-5, len(subjectIds))
286286
}
287287

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

@@ -494,8 +494,10 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairsW
494494
if len(stats) > len(stats2) {
495495
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))
496496
}
497-
// test filtering with smallest cohort, lenght should be 1, since that's the size of the smallest cohort:
498-
// setting the same cohort id here (artificial...normally it should be two different ids):
497+
498+
// test filtering with secondLargestCohort, smallest and largestCohort.
499+
// Lenght of result set should be 2 persons (one HIS, one ASN), since there is a overlap of 1 between secondLargestCohort and smallest cohort,
500+
// and overlap of 2 between secondLargestCohort and largestCohort, BUT only 1 has a HARE value:
499501
filterCohortPairs = []utils.CustomDichotomousVariableDef{
500502
{
501503
CohortId1: smallestCohort.Id,
@@ -505,7 +507,14 @@ func TestRetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairsW
505507
stats3, _ := conceptModel.RetrieveBreakdownStatsBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(testSourceId,
506508
secondLargestCohort.Id, filterIds, filterCohortPairs, breakdownConceptId)
507509
if len(stats3) != 2 {
508-
t.Errorf("Expected only two items in resultset, found %d", len(stats))
510+
t.Errorf("Expected only two items in resultset, found %d", len(stats3))
511+
}
512+
countPersons := 0
513+
for _, stat := range stats3 {
514+
countPersons = countPersons + stat.NpersonsInCohortWithValue
515+
}
516+
if countPersons != 2 {
517+
t.Errorf("Expected only two persons in resultset, found %d", countPersons)
509518
}
510519
}
511520

@@ -633,9 +642,9 @@ func TestRetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(t
633642
filterConceptIds := []int64{}
634643
filterCohortPairs := []utils.CustomDichotomousVariableDef{}
635644
data, _ := cohortDataModel.RetrieveHistogramDataBySourceIdAndCohortIdAndConceptIdsAndCohortPairs(testSourceId, largestCohort.Id, histogramConceptId, filterConceptIds, filterCohortPairs)
636-
// everyone in the largestCohort has the histogramConceptId:
637-
if len(data) != largestCohort.CohortSize {
638-
t.Errorf("expected 10 or more histogram data but got %d", len(data))
645+
// everyone in the largestCohort has the histogramConceptId, but one person has NULL in the value_as_number:
646+
if len(data) != largestCohort.CohortSize-1 {
647+
t.Errorf("expected %d histogram data but got %d", largestCohort.CohortSize, len(data))
639648
}
640649

641650
// now filter on the extendedCopyOfSecondLargestCohort
@@ -775,11 +784,11 @@ func TestRetrieveCohortOverlapStats(t *testing.T) {
775784
CohortId2: extendedCopyOfSecondLargestCohort.Id,
776785
ProvidedName: "test"},
777786
}
778-
// then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort:
787+
// then we expect overlap of 6 for extendedCopyOfSecondLargestCohort and largestCohort:
779788
stats, _ = cohortDataModel.RetrieveCohortOverlapStats(testSourceId, caseCohortId, controlCohortId,
780789
otherFilterConceptIds, filterCohortPairs)
781-
if stats.CaseControlOverlap != 5 {
782-
t.Errorf("Expected nr persons to be %d, found %d", 5, stats.CaseControlOverlap)
790+
if stats.CaseControlOverlap != 6 {
791+
t.Errorf("Expected nr persons to be %d, found %d", 6, stats.CaseControlOverlap)
783792
}
784793

785794
// extra test: different parameters that should return the same as above ^:
@@ -788,10 +797,10 @@ func TestRetrieveCohortOverlapStats(t *testing.T) {
788797
filterCohortPairs = []utils.CustomDichotomousVariableDef{}
789798
otherFilterConceptIds = []int64{histogramConceptId} // extra filter, to cover this part of the code...
790799
// then we expect overlap of 5 for extendedCopyOfSecondLargestCohort and largestCohort (the filter on histogramConceptId should not matter
791-
// since all in largestCohort have an observation for this concept id):
800+
// since all in largestCohort have an observation for this concept id except one person who has it but has value_as_number as NULL):
792801
stats2, _ := cohortDataModel.RetrieveCohortOverlapStats(testSourceId, caseCohortId, controlCohortId,
793802
otherFilterConceptIds, filterCohortPairs)
794-
if stats2.CaseControlOverlap != stats.CaseControlOverlap {
803+
if stats2.CaseControlOverlap != stats.CaseControlOverlap-1 {
795804
t.Errorf("Expected nr persons to be %d, found %d", stats.CaseControlOverlap, stats2.CaseControlOverlap)
796805
}
797806

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)