Skip to content

Commit 5686c8c

Browse files
authored
Merge pull request #2 from KienTTran/main
Update classes and tests
2 parents 6a0bf1c + 5f8fd1f commit 5686c8c

25 files changed

+2920
-7
lines changed

promts/generate_gtest.md

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,97 @@
1-
```
1+
```angular2html
2+
Here is example unit test code
3+
4+
#include <date/date.h>
5+
#include <gtest/gtest.h>
6+
7+
#include "Configuration/ModelSettings.h"
8+
9+
class ModelSettingsTest : public ::testing::Test {
10+
protected:
11+
ModelSettings default_settings;
12+
13+
void SetUp() override {
14+
// Initialize default ModelSettings object using setters
15+
default_settings.set_days_between_stdout_output(10);
16+
default_settings.set_initial_seed_number(123);
17+
default_settings.set_record_genome_db(true);
18+
default_settings.set_starting_date(
19+
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}});
20+
default_settings.set_start_of_comparison_period(
21+
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}});
22+
default_settings.set_ending_date(
23+
date::year_month_day{date::year{2024}, date::month{10}, date::day{2}});
24+
default_settings.set_start_collect_data_day(1);
25+
}
26+
};
27+
28+
// Test encoding functionality
29+
TEST_F(ModelSettingsTest, EncodeModelSettings) {
30+
YAML::Node node = YAML::convert<ModelSettings>::encode(default_settings);
31+
32+
EXPECT_EQ(node["days_between_stdout_output"].as<int>(),
33+
default_settings.get_days_between_stdout_output());
34+
EXPECT_EQ(node["initial_seed_number"].as<int>(),
35+
default_settings.get_initial_seed_number());
36+
EXPECT_EQ(node["record_genome_db"].as<bool>(),
37+
default_settings.get_record_genome_db());
38+
EXPECT_EQ(node["starting_date"].as<date::year_month_day>(),
39+
default_settings.get_starting_date());
40+
EXPECT_EQ(node["start_of_comparison_period"].as<date::year_month_day>(),
41+
default_settings.get_start_of_comparison_period());
42+
EXPECT_EQ(node["ending_date"].as<date::year_month_day>(),
43+
default_settings.get_ending_date());
44+
EXPECT_EQ(node["start_collect_data_day"].as<int>(),
45+
default_settings.get_start_collect_data_day());
46+
}
47+
48+
// Test decoding functionality
49+
TEST_F(ModelSettingsTest, DecodeModelSettings) {
50+
YAML::Node node;
51+
node["days_between_stdout_output"] = 10;
52+
node["initial_seed_number"] = 123;
53+
node["record_genome_db"] = true;
54+
node["starting_date"] =
55+
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}};
56+
node["start_of_comparison_period"] =
57+
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}};
58+
node["ending_date"] =
59+
date::year_month_day{date::year{2024}, date::month{10}, date::day{2}};
60+
node["start_collect_data_day"] = 1;
61+
62+
ModelSettings decoded_settings;
63+
EXPECT_NO_THROW(YAML::convert<ModelSettings>::decode(node, decoded_settings));
64+
65+
EXPECT_EQ(decoded_settings.get_days_between_stdout_output(), 10);
66+
EXPECT_EQ(decoded_settings.get_initial_seed_number(), 123);
67+
EXPECT_EQ(decoded_settings.get_record_genome_db(), true);
68+
69+
auto expected_starting_date =
70+
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}};
71+
EXPECT_EQ(decoded_settings.get_starting_date(), expected_starting_date);
72+
73+
auto expected_start_of_comparison_period =
74+
date::year_month_day{date::year{2024}, date::month{10}, date::day{1}};
75+
EXPECT_EQ(decoded_settings.get_start_of_comparison_period(),
76+
expected_start_of_comparison_period);
77+
78+
auto expected_ending_date =
79+
date::year_month_day{date::year{2024}, date::month{10}, date::day{2}};
80+
EXPECT_EQ(decoded_settings.get_ending_date(), expected_ending_date);
81+
82+
EXPECT_EQ(decoded_settings.get_start_collect_data_day(), 1);
83+
}
84+
85+
// Test missing fields during decoding
86+
TEST_F(ModelSettingsTest, DecodeModelSettingsMissingField) {
87+
YAML::Node node;
88+
node["initial_seed_number"] = 123; // intentionally omit other fields
89+
90+
ModelSettings decoded_settings;
91+
EXPECT_THROW(YAML::convert<ModelSettings>::decode(node, decoded_settings),
92+
std::runtime_error);
93+
}
94+
295
As an expert in C++ programming, would you mind help me to write a gtest for the following function.
396
Suggest me a test file name and using Test Fixture class.
497

sample_inputs/input.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# ---------------------------------------------------------------
88
# 1. Execution Settings
99
# ---------------------------------------------------------------
10-
execution_settings:
10+
model_settings:
1111
# The number of days between each output to the standard output (stdout).
1212
# This variable defines the frequency at which notifications or logs
1313
# are sent to stdout, measured in days.
@@ -87,8 +87,8 @@ spatial_settings:
8787
district_raster: "../input/kag_district.asc"
8888

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

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

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

249249
pf_genotype_info:
250250
- chromosome: 5
@@ -826,7 +826,7 @@ epidemiological_parameters:
826826

827827
# Relapse rate used to increase parasite density after treatment failure
828828
# Multiply by sqrt(20) per day
829-
relapseRate: 4.4721
829+
relapse_rate: 4.4721
830830

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

0 commit comments

Comments
 (0)