Make CTidy happy

This commit is contained in:
James P. Howard, II
2022-08-28 20:14:34 -04:00
parent b9b1cb12e6
commit d2ccdbea73
18 changed files with 58 additions and 46 deletions

View File

@@ -53,6 +53,9 @@
std::shared_ptr<spdlog::logger> console = nullptr; std::shared_ptr<spdlog::logger> console = nullptr;
std::shared_ptr<std::mt19937> rng = nullptr; std::shared_ptr<std::mt19937> rng = nullptr;
#pragma clang diagnostic push
#pragma ide diagnostic ignored "EmptyDeclOrStmt"
int main(int argc, char **argv) { int main(int argc, char **argv) {
std::string ident = "bankreserves"; std::string ident = "bankreserves";
std::string log_level_option = "info"; std::string log_level_option = "info";
@@ -99,3 +102,5 @@ int main(int argc, char **argv) {
console->info("JSON data report written to {}", output_file_name); console->info("JSON data report written to {}", output_file_name);
console->trace("Done."); console->trace("Done.");
} }
#pragma clang diagnostic pop

View File

@@ -85,7 +85,7 @@ std::optional<kami::AgentID> PersonAgent::do_business(std::shared_ptr<kami::Repo
return std::nullopt; return std::nullopt;
// Note, here we reverse the logic from that used in the Mesa // Note, here we reverse the logic from that used in the Mesa
// implementation. We prefer the guard clause to to the nested // implementation. We prefer the guard clause to the nested
// if statements. See Fowler. // if statements. See Fowler.
auto cell_mates = cell_mates_opt.value(); auto cell_mates = cell_mates_opt.value();
if (cell_mates->size() < 2) if (cell_mates->size() < 2)

View File

@@ -169,6 +169,9 @@ std::shared_ptr<kami::Model> BoltzmannWealthModel1D::step() {
return shared_from_this(); return shared_from_this();
} }
#pragma clang diagnostic push
#pragma ide diagnostic ignored "EmptyDeclOrStmt"
int main(int argc, char **argv) { int main(int argc, char **argv) {
std::string ident = "boltzmann1d"; std::string ident = "boltzmann1d";
std::string log_level_option = "info"; std::string log_level_option = "info";
@@ -202,3 +205,5 @@ int main(int argc, char **argv) {
console->info("Boltzmann Wealth Model simulation complete, requiring {} seconds", sw); console->info("Boltzmann Wealth Model simulation complete, requiring {} seconds", sw);
} }
#pragma clang diagnostic pop

View File

@@ -96,11 +96,10 @@ public:
/** /**
* Execute a single time-step for the model. * Execute a single time-step for the model.
*/ */
std::shared_ptr<kami::Model> step(); std::shared_ptr<kami::Model> step() final;
private: private:
unsigned int _step_count; unsigned int _step_count;
}; };
#endif // BOLTZMANN1D_H #endif // BOLTZMANN1D_H

View File

@@ -77,7 +77,7 @@ kami::AgentID MoneyAgent2D::step(std::shared_ptr<kami::Model> model) {
return this->get_agent_id(); return this->get_agent_id();
} }
std::optional<kami::GridCoord2D> MoneyAgent2D::move_agent(std::shared_ptr<kami::Model> model) { std::optional<kami::GridCoord2D> MoneyAgent2D::move_agent(const std::shared_ptr<kami::Model> &model) {
console->trace("Entering move_agent"); console->trace("Entering move_agent");
auto agent_id = get_agent_id(); auto agent_id = get_agent_id();
@@ -100,7 +100,7 @@ std::optional<kami::GridCoord2D> MoneyAgent2D::move_agent(std::shared_ptr<kami::
return new_location; return new_location;
} }
std::optional<kami::AgentID> MoneyAgent2D::give_money(std::shared_ptr<kami::Model> model) { std::optional<kami::AgentID> MoneyAgent2D::give_money(const std::shared_ptr<kami::Model> &model) {
console->trace("Entering give_money"); console->trace("Entering give_money");
auto agent_id = get_agent_id(); auto agent_id = get_agent_id();
@@ -170,6 +170,9 @@ std::shared_ptr<kami::Model> BoltzmannWealthModel2D::step() {
return shared_from_this(); return shared_from_this();
} }
#pragma clang diagnostic push
#pragma ide diagnostic ignored "EmptyDeclOrStmt"
int main(int argc, char **argv) { int main(int argc, char **argv) {
std::string ident = "boltzmann2d"; std::string ident = "boltzmann2d";
std::string log_level_option = "info"; std::string log_level_option = "info";
@@ -204,3 +207,5 @@ int main(int argc, char **argv) {
console->info("Boltzmann Wealth Model simulation complete, requiring {} seconds", sw); console->info("Boltzmann Wealth Model simulation complete, requiring {} seconds", sw);
} }
#pragma clang diagnostic pop

View File

@@ -64,17 +64,16 @@ public:
/** /**
* Move the agent to a random location on the world * Move the agent to a random location on the world
*/ */
std::optional<kami::GridCoord2D> move_agent(std::shared_ptr<kami::Model> model); std::optional<kami::GridCoord2D> move_agent(const std::shared_ptr<kami::Model> &model);
/** /**
* Give money to a random agent * Give money to a random agent
*/ */
std::optional<kami::AgentID> give_money(std::shared_ptr<kami::Model> model); std::optional<kami::AgentID> give_money(const std::shared_ptr<kami::Model> &model);
private: private:
int _step_counter; int _step_counter;
int _agent_wealth; int _agent_wealth;
}; };
/** /**
@@ -99,11 +98,10 @@ public:
/** /**
* Execute a single time-step for the model. * Execute a single time-step for the model.
*/ */
std::shared_ptr<kami::Model> step(); std::shared_ptr<kami::Model> step() final;
private: private:
unsigned int _step_count; unsigned int _step_count;
}; };
#endif // BOLTZMANN2D_H #endif // BOLTZMANN2D_H

View File

@@ -132,7 +132,7 @@ namespace kami {
* @returns false if the agent is not placed at the specified * @returns false if the agent is not placed at the specified
* location, otherwise, true. * location, otherwise, true.
*/ */
virtual std::optional<AgentID> add_agent(const AgentID agent_id, const GridCoord1D &coord) = 0; virtual std::optional<AgentID> add_agent(AgentID agent_id, const GridCoord1D &coord) = 0;
/** /**
* @brief Remove agent from the grid. * @brief Remove agent from the grid.
@@ -141,7 +141,7 @@ namespace kami {
* *
* @returns the `AgentID` of the `Agent` deleted * @returns the `AgentID` of the `Agent` deleted
*/ */
std::optional<AgentID> delete_agent(const AgentID agent_id); std::optional<AgentID> delete_agent(AgentID agent_id);
/** /**
* @brief Remove agent from the grid at the specified location * @brief Remove agent from the grid at the specified location
@@ -151,7 +151,7 @@ namespace kami {
* *
* @returns the `AgentID` of the `Agent` deleted * @returns the `AgentID` of the `Agent` deleted
*/ */
std::optional<AgentID> delete_agent(const AgentID agent_id, const GridCoord1D &coord); std::optional<AgentID> delete_agent(AgentID agent_id, const GridCoord1D &coord);
/** /**
* @brief Move an agent to the specified location. * @brief Move an agent to the specified location.
@@ -159,7 +159,7 @@ namespace kami {
* @param[in] agent_id the `AgentID` of the agent to move. * @param[in] agent_id the `AgentID` of the agent to move.
* @param[in] coord the coordinates of the agent. * @param[in] coord the coordinates of the agent.
*/ */
std::optional<AgentID> move_agent(const AgentID agent_id, const GridCoord1D &coord); std::optional<AgentID> move_agent(AgentID agent_id, const GridCoord1D &coord);
/** /**
* @brief Inquire if the specified location is empty. * @brief Inquire if the specified location is empty.
@@ -220,7 +220,7 @@ namespace kami {
* for all adjacent points. * for all adjacent points.
*/ */
[[nodiscard]] std::optional<std::shared_ptr<std::unordered_set<GridCoord1D>>> [[nodiscard]] std::optional<std::shared_ptr<std::unordered_set<GridCoord1D>>>
get_neighborhood(const AgentID agent_id, const bool include_center) const; get_neighborhood(AgentID agent_id, const bool include_center) const;
/** /**
* @brief Return the neighborhood of the specified location * @brief Return the neighborhood of the specified location
@@ -233,7 +233,7 @@ namespace kami {
* for all adjacent points. * for all adjacent points.
*/ */
[[nodiscard]] std::optional<std::shared_ptr<std::unordered_set<GridCoord1D>>> [[nodiscard]] std::optional<std::shared_ptr<std::unordered_set<GridCoord1D>>>
get_neighborhood(const GridCoord1D &coord, const bool include_center) const; get_neighborhood(const GridCoord1D &coord, bool include_center) const;
/** /**
* @brief Get the size of the grid in the `x` dimension. * @brief Get the size of the grid in the `x` dimension.

View File

@@ -154,7 +154,7 @@ namespace kami {
* @returns false if the agent is not placed at the specified * @returns false if the agent is not placed at the specified
* location, otherwise, true. * location, otherwise, true.
*/ */
virtual std::optional<AgentID> add_agent(const AgentID agent_id, const GridCoord2D &coord) = 0; virtual std::optional<AgentID> add_agent(AgentID agent_id, const GridCoord2D &coord) = 0;
/** /**
* @brief Remove agent from the grid. * @brief Remove agent from the grid.
@@ -163,7 +163,7 @@ namespace kami {
* *
* @returns false if the agent is not removed, otherwise, true. * @returns false if the agent is not removed, otherwise, true.
*/ */
std::optional<AgentID> delete_agent(const AgentID agent_id); std::optional<AgentID> delete_agent(AgentID agent_id);
/** /**
* @brief Remove agent from the grid at the specified location * @brief Remove agent from the grid at the specified location
@@ -173,7 +173,7 @@ namespace kami {
* *
* @returns false if the agent is not removed, otherwise, true. * @returns false if the agent is not removed, otherwise, true.
*/ */
std::optional<AgentID> delete_agent(const AgentID agent_id, const GridCoord2D &coord); std::optional<AgentID> delete_agent(AgentID agent_id, const GridCoord2D &coord);
/** /**
* @brief Move an agent to the specified location. * @brief Move an agent to the specified location.
@@ -181,7 +181,7 @@ namespace kami {
* @param[in] agent_id the `AgentID` of the agent to move. * @param[in] agent_id the `AgentID` of the agent to move.
* @param[in] coord the coordinates of the agent. * @param[in] coord the coordinates of the agent.
*/ */
std::optional<AgentID> move_agent(const AgentID agent_id, const GridCoord2D &coord); std::optional<AgentID> move_agent(AgentID agent_id, const GridCoord2D &coord);
/** /**
* @brief Inquire if the specified location is empty. * @brief Inquire if the specified location is empty.

View File

@@ -65,7 +65,7 @@ namespace kami {
* @returns false if the agent is not placed at the specified * @returns false if the agent is not placed at the specified
* location, otherwise, true * location, otherwise, true
*/ */
std::optional<AgentID> add_agent(const AgentID agent_id, const GridCoord1D &coord) override; std::optional<AgentID> add_agent(AgentID agent_id, const GridCoord1D &coord) override;
}; };
} // namespace kami } // namespace kami

View File

@@ -69,7 +69,7 @@ namespace kami {
* @returns false if the agent is not placed at the specified * @returns false if the agent is not placed at the specified
* location, otherwise, true * location, otherwise, true
*/ */
std::optional<AgentID> add_agent(const AgentID agent_id, const GridCoord2D &coord) override; std::optional<AgentID> add_agent(AgentID agent_id, const GridCoord2D &coord) override;
}; };
} // namespace kami } // namespace kami

View File

@@ -37,9 +37,9 @@
namespace kami { namespace kami {
typedef std::variant< typedef std::variant<
kami::GridCoord1D, GridCoord1D,
kami::GridCoord2D, GridCoord2D,
kami::HexCoord HexCoord
> Position; > Position;
} }

View File

@@ -37,7 +37,7 @@
namespace kami { namespace kami {
/** /**
* @brief A one-dimensional grid where each cell may contain one agenta * @brief A one-dimensional grid where each cell may contain one agents
* *
* @details The grid is linear and may wrap around in its only dimension. * @details The grid is linear and may wrap around in its only dimension.
* *
@@ -64,7 +64,7 @@ namespace kami {
* @returns false if the agent is not placed at the specified * @returns false if the agent is not placed at the specified
* location, otherwise, true * location, otherwise, true
*/ */
std::optional<AgentID> add_agent(const AgentID agent_id, const GridCoord1D &coord) override; std::optional<AgentID> add_agent(AgentID agent_id, const GridCoord1D &coord) override;
}; };
} // namespace kami } // namespace kami

View File

@@ -66,7 +66,7 @@ namespace kami {
* @returns false if the agent is not placed at the specified * @returns false if the agent is not placed at the specified
* location, otherwise, true * location, otherwise, true
*/ */
std::optional<AgentID> add_agent(const AgentID agent_id, const GridCoord2D &coord) override; std::optional<AgentID> add_agent(AgentID agent_id, const GridCoord2D &coord) override;
}; };

View File

@@ -51,7 +51,7 @@ protected:
shared_ptr<TestModel> model_world = nullptr; shared_ptr<TestModel> model_world = nullptr;
void SetUp() override { void SetUp() override {
auto model_world = make_shared<TestModel>(); model_world = make_shared<TestModel>();
} }
}; };

View File

@@ -45,7 +45,7 @@ public:
class TestModel : public Model { class TestModel : public Model {
public: public:
shared_ptr<Model> step() { shared_ptr<Model> step() final {
return shared_from_this(); return shared_from_this();
} }
}; };
@@ -61,24 +61,24 @@ TEST(Model, DefaultConstructor) {
TEST(Model, set_population) { TEST(Model, set_population) {
auto model_foo = make_shared<TestModel>(); auto model_foo = make_shared<TestModel>();
auto popul_foo = make_shared<Population>(); auto pop_foo = make_shared<Population>();
auto popul_bar = model_foo->set_population(popul_foo); auto pop_bar = model_foo->set_population(pop_foo);
EXPECT_EQ(popul_foo, popul_bar); EXPECT_EQ(pop_foo, pop_bar);
} }
TEST(Model, get_population) { TEST(Model, get_population) {
auto model_foo = make_shared<TestModel>(); auto model_foo = make_shared<TestModel>();
auto popul_foo = make_shared<Population>(); auto pop_foo = make_shared<Population>();
auto popul_nul = model_foo->get_population(); auto pop_nul = model_foo->get_population();
auto popul_bar = model_foo->set_population(popul_foo); auto pop_bar = model_foo->set_population(pop_foo);
auto popul_baz = model_foo->get_population(); auto pop_baz = model_foo->get_population();
EXPECT_TRUE(popul_baz); EXPECT_TRUE(pop_baz);
EXPECT_EQ(popul_foo, popul_baz); EXPECT_EQ(pop_foo, pop_baz);
EXPECT_EQ(popul_bar, popul_baz); EXPECT_EQ(pop_bar, pop_baz);
} }
TEST(Model, set_scheduler) { TEST(Model, set_scheduler) {

View File

@@ -65,7 +65,7 @@ protected:
shared_ptr<TestModel> model_world = nullptr; shared_ptr<TestModel> model_world = nullptr;
void SetUp() override { void SetUp() override {
auto model_world = make_shared<TestModel>(); model_world = make_shared<TestModel>();
} }
}; };

View File

@@ -65,16 +65,16 @@ protected:
void SetUp() override { void SetUp() override {
mod = make_shared<TestModel>(); mod = make_shared<TestModel>();
auto popul_foo = make_shared<Population>(); auto pop_foo = make_shared<Population>();
auto sched_foo = make_shared<SequentialScheduler>(); auto sched_foo = make_shared<SequentialScheduler>();
// Domain is not required for this test // Domain is not required for this test
static_cast<void>(mod->set_population(popul_foo)); static_cast<void>(mod->set_population(pop_foo));
static_cast<void>(mod->set_scheduler(sched_foo)); static_cast<void>(mod->set_scheduler(sched_foo));
for (auto i = 0; i < 10; i++) { for (auto i = 0; i < 10; i++) {
auto agent_foo = make_shared<TestAgent>(); auto agent_foo = make_shared<TestAgent>();
static_cast<void>(popul_foo->add_agent(agent_foo)); static_cast<void>(pop_foo->add_agent(agent_foo));
} }
} }
}; };

View File

@@ -55,7 +55,7 @@ protected:
shared_ptr<TestModel> model_world = nullptr; shared_ptr<TestModel> model_world = nullptr;
void SetUp() override { void SetUp() override {
auto model_world = make_shared<TestModel>(); model_world = make_shared<TestModel>();
} }
}; };