-
Notifications
You must be signed in to change notification settings - Fork 1
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
Initial pass at implementing test fixtures #316
base: main
Are you sure you want to change the base?
Changes from 2 commits
1f72805
5b5896c
33516bd
306ef2f
486d702
c411aa3
e07ca7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,186 @@ | ||||||
#include "pch.h" | ||||||
|
||||||
#include "HealthGPS/static_linear_model.h" | ||||||
|
||||||
// Create a test fixture for the StaticLinearModel parameters | ||||||
class ModelParameters : public ::testing::Test { | ||||||
public: | ||||||
hgps::RiskFactorSexAgeTable expected; | ||||||
std::vector<hgps::core::Identifier> names; | ||||||
std::vector<hgps::LinearModelParams> models; | ||||||
std::vector<double> lambda; | ||||||
std::vector<double> stddev; | ||||||
Eigen::Matrix2d correlation; | ||||||
Eigen::MatrixXd cholesky; | ||||||
std::vector<hgps::LinearModelParams> policy_models; | ||||||
std::vector<hgps::core::DoubleInterval> policy_ranges; | ||||||
Eigen::MatrixXd policy_cholesky; | ||||||
|
||||||
void SetUp() override { | ||||||
auto expected = hgps::RiskFactorSexAgeTable{}; | ||||||
std::vector<double> factorsMale = {200.,40.,30.,2000.,1.,1000.,3.,50.}; | ||||||
std::vector<double> factorsFemale = {200.,40.,30.,2000.,1.,1000.,3.,50.}; | ||||||
|
||||||
std::unordered_map<hgps::core::Identifier, std::vector<double>> factorsMale = { | ||||||
Check failure on line 24 in src/HealthGPS.Tests/StaticLinearModel.Test.cpp GitHub Actions / Build and test (linux, ubuntu-22.04, gcc-latest, false)
|
||||||
TinyMarsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
{hgps::core::Identifier{"0"}, factorsMale}, | ||||||
{hgps::core::Identifier{"1"}, factorsMale} | ||||||
TinyMarsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}; | ||||||
|
||||||
std::unordered_map<hgps::core::Identifier, std::vector<double>> factorsFemale = { | ||||||
Check failure on line 29 in src/HealthGPS.Tests/StaticLinearModel.Test.cpp GitHub Actions / Build and test (linux, ubuntu-22.04, gcc-latest, false)
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: redefinition of 'factorsFemale' with a different type: 'std::unordered_map<hgps::core::Identifier, std::vector>' vs 'std::vector' [clang-diagnostic-error] std::unordered_map<hgps::core::Identifier, std::vector<double>> factorsFemale = {
^ Additional contextsrc/HealthGPS.Tests/StaticLinearModel.Test.cpp:21: previous definition is here std::vector<double> factorsFemale = {200.,40.,30.,2000.,1.,1000.,3.,50.};
^ |
||||||
{hgps::core::Identifier{"0"}, factorsFemale}, | ||||||
{hgps::core::Identifier{"1"}, factorsFemale} | ||||||
}; | ||||||
|
||||||
expected.emplace_row(hgps::core::Gender::male, factorsMale); | ||||||
expected.emplace_row(hgps::core::Gender::female, factorsFemale); | ||||||
|
||||||
std::vector<hgps::core::Identifier> names = {"FoodCarbohydrate", "FoodFat"}; | ||||||
|
||||||
// Define models | ||||||
// We will define 2 RiskFactorModels: carb_model and fat_model | ||||||
std::vector<hgps::LinearModelParams> models; | ||||||
hgps::LinearModelParams carb_model; | ||||||
carb_model.intercept = -0.241505734056409; | ||||||
std::unordered_map<hgps::core::Identifier, double> coefficients = { | ||||||
TinyMarsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
{"Gender", 0.00191412437431455}, | ||||||
{"Age", -0.000545257990453302}, | ||||||
{"Age2", 3.06434596341924e-6}, | ||||||
{"Age3", 5.24468215546687e-9}, | ||||||
{"Sector", 0.0967308121487847}, | ||||||
{"Income", 0.0810023788842083} | ||||||
}; | ||||||
carb_model.coefficients = coefficients; | ||||||
|
||||||
hgps::LinearModelParams fat_model; | ||||||
fat_model.intercept = -0.693521187677; | ||||||
coefficients = { | ||||||
TinyMarsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
{"Gender", 0.00385126434589752}, | ||||||
{"Age", -0.00433711587715954}, | ||||||
{"Age2", 3.11799231385975e-5}, | ||||||
{"Age3", 3.4291809335544e-8}, | ||||||
{"Sector", -0.0629531974852436}, | ||||||
{"Income", 0.373256996730791} | ||||||
}; | ||||||
fat_model.coefficients = coefficients; | ||||||
|
||||||
models.emplace_back(std::move(carb_model)); | ||||||
models.emplace_back(std::move(fat_model)); | ||||||
|
||||||
std::vector<double> lambda = {0.262626262626263, 0.141414141414141}; | ||||||
std::vector<double> stddev = {0.337810256621877, 0.436763527499362}; | ||||||
|
||||||
Eigen::Matrix2d correlation; | ||||||
correlation << 1.0, 0.322065425, 0.322065425,1.0; | ||||||
auto cholesky = Eigen::MatrixXd{Eigen::LLT<Eigen::Matrix2d>{correlation}.matrixL()}; | ||||||
|
||||||
Eigen::MatrixXd policy_covariance; | ||||||
policy_covariance << 0.1,0.1,0.1,0.41; | ||||||
auto policy_cholesky = Eigen::MatrixXd{Eigen::LLT<Eigen::MatrixXd>{policy_covariance}.matrixL()}; | ||||||
|
||||||
// Define policy models | ||||||
std::vector<hgps::LinearModelParams> policy_models; | ||||||
std::vector<hgps::core::DoubleInterval> policy_ranges; | ||||||
|
||||||
// We need 2 policy models for the 2 risk factor models | ||||||
hgps::LinearModelParams carb_policy_model; | ||||||
carb_policy_model.intercept = -1.29385215316281; | ||||||
coefficients = { | ||||||
{"Gender", 0.00845121355575458}, | ||||||
{"Age", 0.000386003599279214}, | ||||||
{"Sector", 0.0621763530502617}, | ||||||
{"Income", 0.0560558815729017} | ||||||
}; | ||||||
carb_policy_model.coefficients = coefficients; | ||||||
std::unordered_map<hgps::core::Identifier, double> log_coefficients = { | ||||||
{"FoodCarbohydrate", 0.577638667323293}, | ||||||
{"FoodFat", -0.0801300827856402}, | ||||||
{"FoodProtein", -0.480946893299471}, | ||||||
{"FoodSodium", -0.0396319735508116} | ||||||
}; | ||||||
carb_policy_model.log_coefficients = log_coefficients; | ||||||
policy_ranges.emplace_back(hgps::core::DoubleInterval{-2.31063, 0.37526}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unnecessary temporary object created while calling emplace_back [modernize-use-emplace]
Suggested change
|
||||||
|
||||||
hgps::LinearModelParams fat_policy_model; | ||||||
fat_policy_model.intercept = -0.734121205356728; | ||||||
coefficients = { | ||||||
{"Gender", 0.023422206650121}, | ||||||
{"Age", 0.000557687923688474}, | ||||||
{"Sector", 0.00166651997223223}, | ||||||
{"Income", -0.498755023022772} | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: expected ';' after expression [clang-diagnostic-error]
Suggested change
|
||||||
fat_policy_model.coefficients = coefficients; | ||||||
Check failure on line 111 in src/HealthGPS.Tests/StaticLinearModel.Test.cpp GitHub Actions / Build and test (linux, ubuntu-22.04, gcc-latest, false)
|
||||||
log_coefficients = { | ||||||
{"FoodCarbohydrate", 0.652615267035516}, | ||||||
{"FoodFat", 0.743457905132894}, | ||||||
{"FoodProtein", -1.2648185364167}, | ||||||
{"FoodSodium", -0.17181077457271} | ||||||
}; | ||||||
fat_policy_model.log_coefficients = log_coefficients; | ||||||
policy_ranges.emplace_back(hgps::core::DoubleInterval{-4.87205, -0.10346}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unnecessary temporary object created while calling emplace_back [modernize-use-emplace]
Suggested change
|
||||||
|
||||||
policy_models.emplace_back(std::move(carb_policy_model)); | ||||||
policy_models.emplace_back(std::move(fat_policy_model)); | ||||||
|
||||||
const double info_speed = 0.1; | ||||||
Check failure on line 124 in src/HealthGPS.Tests/StaticLinearModel.Test.cpp GitHub Actions / Build and test (linux, ubuntu-22.04, gcc-latest, false)
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unused variable 'info_speed' [clang-diagnostic-unused-variable] const double info_speed = 0.1;
^ |
||||||
|
||||||
std::unordered_map<hgps::core::Identifier, std::unordered_map<hgps::core::Gender, double>> rural_prevalence; | ||||||
rural_prevalence["Under18"] = {{hgps::core::Gender::female, 0.65},{hgps::core::Gender::male, 0.65}}; | ||||||
rural_prevalence["Over18"] = {{hgps::core::Gender::female, 0.6},{hgps::core::Gender::male, 0.6}}; | ||||||
|
||||||
std::unordered_map<hgps::core::Income, hgps::LinearModelParams> income_models; | ||||||
|
||||||
hgps::LinearModelParams income_model_low; | ||||||
income_model_low.intercept = 0.0; | ||||||
coefficients = {} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: expected ';' after expression [clang-diagnostic-error]
Suggested change
|
||||||
income_model_low.coefficients = coefficients; | ||||||
Check failure on line 135 in src/HealthGPS.Tests/StaticLinearModel.Test.cpp GitHub Actions / Build and test (linux, ubuntu-22.04, gcc-latest, false)
|
||||||
|
||||||
hgps::LinearModelParams income_model_middle; | ||||||
income_model_middle.intercept = -0.0023671151435328; | ||||||
coefficients = { | ||||||
{"Gender", 0.0244784583947992}, | ||||||
{"Over18", 0.276669591410528}, | ||||||
{"Sector", -0.491794449118805} | ||||||
}; | ||||||
income_model_middle.coefficients = coefficients; | ||||||
|
||||||
hgps::LinearModelParams income_model_high; | ||||||
income_model_high.intercept = 0.0187952471153142; | ||||||
coefficients = { | ||||||
{"Gender", 0.02018185354194}, | ||||||
{"Over18", 0.607099252829797}, | ||||||
{"Sector", -1.5870837069653} | ||||||
}; | ||||||
income_model_high.coefficients = coefficients; | ||||||
|
||||||
income_models.emplace(hgps::core::Income::low, std::move(income_model_low)); | ||||||
income_models.emplace(hgps::core::Income::middle, std::move(income_model_middle)); | ||||||
income_models.emplace(hgps::core::Income::high, std::move(income_model_high)); | ||||||
|
||||||
const double physical_activity_stddev = 0.06; | ||||||
Check failure on line 159 in src/HealthGPS.Tests/StaticLinearModel.Test.cpp GitHub Actions / Build and test (linux, ubuntu-22.04, gcc-latest, false)
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unused variable 'physical_activity_stddev' [clang-diagnostic-unused-variable] const double physical_activity_stddev = 0.06;
^ |
||||||
|
||||||
}; | ||||||
}; | ||||||
|
||||||
// Create test fixture for a StaticLinearModel class instance | ||||||
class StaticLinearModelTestFixture : public::testing::Test { | ||||||
public: | ||||||
StaticLinearModel testModel( | ||||||
Check failure on line 167 in src/HealthGPS.Tests/StaticLinearModel.Test.cpp GitHub Actions / Build and test (linux, ubuntu-22.04, gcc-latest, false)
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'StaticLinearModel'; did you mean 'hgps::StaticLinearModel'? [clang-diagnostic-error]
Suggested change
Additional contextsrc/HealthGPS/static_linear_model.h:22: 'hgps::StaticLinearModel' declared here class StaticLinearModel final : public RiskFactorAdjustableModel {
^ |
||||||
expected, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'expected' [clang-diagnostic-error] expected,
^ |
||||||
names, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'names' [clang-diagnostic-error] names,
^ |
||||||
models, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'models'; did you mean 'mode_t'? [clang-diagnostic-error]
Suggested change
Additional context/usr/include/x86_64-linux-gnu/sys/types.h:68: 'mode_t' declared here typedef __mode_t mode_t;
^ |
||||||
lambda, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'lambda' [clang-diagnostic-error] lambda,
^ |
||||||
stddev, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'stddev' [clang-diagnostic-error] stddev,
^ |
||||||
cholesky, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'cholesky' [clang-diagnostic-error] cholesky,
^ |
||||||
policy_models, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'policy_models' [clang-diagnostic-error] policy_models,
^ |
||||||
policy_ranges, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'policy_ranges' [clang-diagnostic-error] policy_ranges,
^ |
||||||
policy_cholesky, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'policy_cholesky' [clang-diagnostic-error] policy_cholesky,
^ |
||||||
info_speed, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'info_speed' [clang-diagnostic-error] info_speed,
^ |
||||||
rural_prevalence, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'rural_prevalence' [clang-diagnostic-error] rural_prevalence,
^ |
||||||
income_models, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'income_models' [clang-diagnostic-error] income_models,
^ |
||||||
physical_activity_stddev | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: unknown type name 'physical_activity_stddev' [clang-diagnostic-error] physical_activity_stddev
^ |
||||||
); | ||||||
}; | ||||||
|
||||||
TEST_F(StaticLinearModelTestFixture, InitialiseFactors) { | ||||||
// Test logic goes here | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: redefinition of 'factorsMale' with a different type: 'std::unordered_map<hgps::core::Identifier, std::vector>' vs 'std::vector' [clang-diagnostic-error]
std::unordered_map<hgps::core::Identifier, std::vector<double>> factorsMale = { ^
Additional context
src/HealthGPS.Tests/StaticLinearModel.Test.cpp:20: previous definition is here