Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for calculate_index function #495

Merged
merged 18 commits into from
Oct 14, 2024
Merged

Conversation

TinyMarsh
Copy link
Contributor

@TinyMarsh TinyMarsh commented Aug 15, 2024

Turns out that I thought it would be worth creating a separate PR for implementing this test as I've decided to be more thorough with things.

While creating the test fixtures I noticed that there existed some code in Simulation.Test.cpp to help create the fixtures I was using in AnalysisModule.Test.cpp. I have moved much of this code to simulation.h/.cpp and have both test files include this header.

Closes #470

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/HealthGPS.Tests/AnalysisModule.Test.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/HealthGPS.Tests/AnalysisModule.Test.cpp Outdated Show resolved Hide resolved
src/HealthGPS.Tests/AnalysisModule.Test.cpp Outdated Show resolved Hide resolved
src/HealthGPS.Tests/simulation.h Outdated Show resolved Hide resolved
@TinyMarsh TinyMarsh linked an issue Aug 27, 2024 that may be closed by this pull request
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

src/HealthGPS.Tests/AnalysisModule.Test.cpp Outdated Show resolved Hide resolved
src/HealthGPS.Tests/AnalysisModule.Test.cpp Show resolved Hide resolved
src/HealthGPS.Tests/simulation.h Outdated Show resolved Hide resolved
@TinyMarsh TinyMarsh marked this pull request as ready for review September 5, 2024 12:29
@TinyMarsh
Copy link
Contributor Author

Hey @jamesturner246 , @alexdewar. This is ready for a review now, when you have time. The Windows build is failing for reasons I can't quite get to the bottom of, but I'll have more of a poke around and see if I can fixt that.

@alexdewar
Copy link
Contributor

@TinyMarsh The Windows build is failing because of a missing #include. It must have changed in MSVC's standard lib...

I had the same problem on my branch. Fix here:

git cherry-pick 3481ff4958e3b838a9062ef8a76d213f666555fb

Copy link
Contributor

@alexdewar alexdewar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good on the whole -- and the test module seems useful. There are a couple of unused functions you've added though and I think we could do with a few more test cases for calculate_index.

src/HealthGPS.Tests/AnalysisModule.Test.cpp Show resolved Hide resolved
src/HealthGPS.Tests/AnalysisModule.Test.cpp Show resolved Hide resolved
src/HealthGPS.Tests/AnalysisModule.Test.cpp Show resolved Hide resolved
src/HealthGPS.Tests/RiskFactorData.cpp Outdated Show resolved Hide resolved
src/HealthGPS/analysis_module.cpp Show resolved Hide resolved

size_t index_1 = analysis_module->calculate_index(test_person_1);

ASSERT_EQ(index_1, 29);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to test some more indexes here? E.g. you could check it works with 1, 2 and 3 dimensional matrices

@TinyMarsh
Copy link
Contributor Author

Thanks @alexdewar. Yes absolutely we could probably do with more test cases. I meant to do that but I think I just got excited that I actually managed to get a test running and rushed out a PR 😄. I will add some more cases and clean up the code per your other comments.

Copy link
Contributor

@jamesturner246 jamesturner246 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good! Much has already been stated, just a couple minor things and a question.

As @alexdewar says, maybe a couple more tests/cases in this PR and looks god to go!

src/HealthGPS/analysis_module.h Show resolved Hide resolved
src/HealthGPS.Tests/simulation.h Outdated Show resolved Hide resolved
src/HealthGPS.Tests/simulation.cpp Outdated Show resolved Hide resolved
src/HealthGPS.Tests/CMakeLists.txt Outdated Show resolved Hide resolved
src/HealthGPS.Tests/AnalysisModule.Test.cpp Show resolved Hide resolved
src/HealthGPS.Tests/AnalysisModule.Test.cpp Show resolved Hide resolved
Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 97.05882% with 2 lines in your changes missing coverage. Please review.

Please upload report for BASE (extend_analysis@52e23d9). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/HealthGPS/analysis_module.cpp 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##             extend_analysis     #495   +/-   ##
==================================================
  Coverage                   ?   49.92%           
==================================================
  Files                      ?      160           
  Lines                      ?     7732           
  Branches                   ?     1027           
==================================================
  Hits                       ?     3860           
  Misses                     ?     3677           
  Partials                   ?      195           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TinyMarsh
Copy link
Contributor Author

Hi @alexdewar @jamesturner246 this should be ready for a re-review now. I have made some changes based on your feedback.

I noticed an error in the logic of the calculate_index function (this is why we do tests I suppose!) which was a big head-scratcher that ended up being a small adjustment. So I have fixed that and also increased the population age diversity and included an extra test to cover an extra age value.

The testing of varying dimensions will have to be done later (I will create an issue), as we currently have it hard-coded for 2 dimensions (age and gender in factors_to_calculate_).

Copy link
Contributor

@alexdewar alexdewar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some mysterious commented-out code, but other than that, this LGTM!

std::ref(context), std::ref(result));
// auto handle = core::run_async(&AnalysisModule::calculate_historical_statistics, this,
// std::ref(context), std::ref(result));
// handle.get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good spot. It shouldn't be commented out. This is left over from when I was trying to debug the test failing. With these two lines uncommented, I get the following test failure;

        Start 236: TestAnalysisModule.CalculateIndex
236/236 Test #236: TestAnalysisModule.CalculateIndex ..............................***Failed    0.07 sec

Initialising with a custom GTest main function.

Using default test data store ...

Test location..: /home/ryan/projects/healthgps/out/build/linux-debug/src/HealthGPS.Tests
Test data store: /home/ryan/projects/healthgps/data

Note: Google Test filter = TestAnalysisModule.CalculateIndex
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from TestAnalysisModule
[ RUN      ] TestAnalysisModule.CalculateIndex
unknown file: Failure
C++ exception with description "map::at" thrown in the test fixture's constructor.

[  FAILED  ] TestAnalysisModule.CalculateIndex (57 ms)
[----------] 1 test from TestAnalysisModule (57 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (57 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] TestAnalysisModule.CalculateIndex

 1 FAILED TEST


99% tests passed, 1 tests failed out of 236

Total Test time (real) =  15.35 sec

The following tests FAILED:
        236 - TestAnalysisModule.CalculateIndex (Failed)
Errors while running CTest

I think this is because the RuntimeContext object that is created in the test fixture constructor is not properly initialised with the required map elements for some map that the commented-out handle.get() function above is trying to access.

Not quite there yet then. I feel like this is going to be a pain to sort out.

Copy link
Contributor Author

@TinyMarsh TinyMarsh Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed and wasn't too bad in the end. The RuntimeContext needed the current year to be set.

@TinyMarsh TinyMarsh merged commit 6c592d3 into extend_analysis Oct 14, 2024
7 checks passed
@TinyMarsh TinyMarsh deleted the calculate_index_test branch October 14, 2024 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add test for calculate_index function in the analysis module
3 participants