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

Update classes and tests #2

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 94 additions & 1 deletion promts/generate_gtest.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,97 @@
```
```angular2html
Here is example unit test code

#include <date/date.h>
#include <gtest/gtest.h>

#include "Configuration/ModelSettings.h"

class ModelSettingsTest : public ::testing::Test {
protected:
ModelSettings default_settings;

void SetUp() override {
// Initialize default ModelSettings object using setters
default_settings.set_days_between_stdout_output(10);
default_settings.set_initial_seed_number(123);
default_settings.set_record_genome_db(true);
default_settings.set_starting_date(
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}});
default_settings.set_start_of_comparison_period(
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}});
default_settings.set_ending_date(
date::year_month_day{date::year{2024}, date::month{10}, date::day{2}});
default_settings.set_start_collect_data_day(1);
}
};

// Test encoding functionality
TEST_F(ModelSettingsTest, EncodeModelSettings) {
YAML::Node node = YAML::convert<ModelSettings>::encode(default_settings);

EXPECT_EQ(node["days_between_stdout_output"].as<int>(),
default_settings.get_days_between_stdout_output());
EXPECT_EQ(node["initial_seed_number"].as<int>(),
default_settings.get_initial_seed_number());
EXPECT_EQ(node["record_genome_db"].as<bool>(),
default_settings.get_record_genome_db());
EXPECT_EQ(node["starting_date"].as<date::year_month_day>(),
default_settings.get_starting_date());
EXPECT_EQ(node["start_of_comparison_period"].as<date::year_month_day>(),
default_settings.get_start_of_comparison_period());
EXPECT_EQ(node["ending_date"].as<date::year_month_day>(),
default_settings.get_ending_date());
EXPECT_EQ(node["start_collect_data_day"].as<int>(),
default_settings.get_start_collect_data_day());
}

// Test decoding functionality
TEST_F(ModelSettingsTest, DecodeModelSettings) {
YAML::Node node;
node["days_between_stdout_output"] = 10;
node["initial_seed_number"] = 123;
node["record_genome_db"] = true;
node["starting_date"] =
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}};
node["start_of_comparison_period"] =
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}};
node["ending_date"] =
date::year_month_day{date::year{2024}, date::month{10}, date::day{2}};
node["start_collect_data_day"] = 1;

ModelSettings decoded_settings;
EXPECT_NO_THROW(YAML::convert<ModelSettings>::decode(node, decoded_settings));

EXPECT_EQ(decoded_settings.get_days_between_stdout_output(), 10);
EXPECT_EQ(decoded_settings.get_initial_seed_number(), 123);
EXPECT_EQ(decoded_settings.get_record_genome_db(), true);

auto expected_starting_date =
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}};
EXPECT_EQ(decoded_settings.get_starting_date(), expected_starting_date);

auto expected_start_of_comparison_period =
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}};
EXPECT_EQ(decoded_settings.get_start_of_comparison_period(),
expected_start_of_comparison_period);

auto expected_ending_date =
date::year_month_day{date::year{2024}, date::month{10}, date::day{2}};
EXPECT_EQ(decoded_settings.get_ending_date(), expected_ending_date);

EXPECT_EQ(decoded_settings.get_start_collect_data_day(), 1);
}

// Test missing fields during decoding
TEST_F(ModelSettingsTest, DecodeModelSettingsMissingField) {
YAML::Node node;
node["initial_seed_number"] = 123; // intentionally omit other fields

ModelSettings decoded_settings;
EXPECT_THROW(YAML::convert<ModelSettings>::decode(node, decoded_settings),
std::runtime_error);
}

As an expert in C++ programming, would you mind help me to write a gtest for the following function.
Suggest me a test file name and using Test Fixture class.

Expand Down
10 changes: 5 additions & 5 deletions sample_inputs/input.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# ---------------------------------------------------------------
# 1. Execution Settings
# ---------------------------------------------------------------
execution_settings:
model_settings:
# The number of days between each output to the standard output (stdout).
# This variable defines the frequency at which notifications or logs
# are sent to stdout, measured in days.
Expand Down Expand Up @@ -87,8 +87,8 @@ spatial_settings:
district_raster: "../input/kag_district.asc"

# Raster files defining treatment probabilities (comment these out for beta calibration)
p_treatment_under_5: "../input/kag_treatment.asc"
p_treatment_over_5: "../input/kag_treatment.asc"
p_treatment_under_5_raster: "../input/kag_treatment.asc"
p_treatment_over_5_raster: "../input/kag_treatment.asc"

# Probability that an infected and symptomatic person receives treatment; single value for the entire country
# If set to '-1', these values are read from 'pr_treatment_under5' and 'pr_treatment_over5' above
Expand Down Expand Up @@ -244,7 +244,7 @@ genotype_parameters:
mutation_mask: "||||111||1111111,0||||||000000000010|1"

# Daily probability that a parasite will mutate at a given locus when drug concentration is not zero
mutation_probability_by_locus: 0.001
mutation_probability_per_locus: 0.001

pf_genotype_info:
- chromosome: 5
Expand Down Expand Up @@ -826,7 +826,7 @@ epidemiological_parameters:

# Relapse rate used to increase parasite density after treatment failure
# Multiply by sqrt(20) per day
relapseRate: 4.4721
relapse_rate: 4.4721

# Minimum update frequency for a host's attributes (especially parasite density)
# NOTE: consider remove this value as Person will be updated daily
Expand Down
Loading
Loading