From a801720aa52de023f68c34dac9b53cff75747298 Mon Sep 17 00:00:00 2001 From: "James P. Howard, II" Date: Thu, 11 Aug 2022 22:17:01 -0400 Subject: [PATCH] Agent reporter sketch --- conanfile.py | 1 + include/kami/data/reporter.h | 53 +++++++++++++++ test/unit-kami-data-agentreporter.cc | 97 ++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 include/kami/data/reporter.h create mode 100644 test/unit-kami-data-agentreporter.cc diff --git a/conanfile.py b/conanfile.py index 5757cf0..cba12ab 100644 --- a/conanfile.py +++ b/conanfile.py @@ -49,3 +49,4 @@ class KamiConan(ConanFile): self.requires("cli11/1.9.1") self.requires("neargye-semver/0.3.0") self.requires("gtest/cci.20210126") + self.requires("nlohmann_json/3.11.1") diff --git a/include/kami/data/reporter.h b/include/kami/data/reporter.h new file mode 100644 index 0000000..000142b --- /dev/null +++ b/include/kami/data/reporter.h @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2022 The Johns Hopkins University Applied Physics + * Laboratory LLC + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once +#ifndef KAMI_REPORTER_H +//! @cond SuppressGuard +#define KAMI_REPORTER_H +//! @endcond + +#include + +#include + +#include + +namespace kami { + + class LIBKAMIDATA_EXPORT AgentReporter{ + + private: + std::shared_ptr data; + + public: + AgentReporter(); + + virtual std::shared_ptr collect() = 0; + }; + +} + +#endif //KAMI_REPORTER_H diff --git a/test/unit-kami-data-agentreporter.cc b/test/unit-kami-data-agentreporter.cc new file mode 100644 index 0000000..98e5add --- /dev/null +++ b/test/unit-kami-data-agentreporter.cc @@ -0,0 +1,97 @@ +/*- + * Copyright (c) 2022 The Johns Hopkins University Applied Physics + * Laboratory LLC + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +#include +#include +#include + +#include + +class TestAgent : public kami::Agent { +public: + kami::AgentID step(std::shared_ptr model) override { + return get_agent_id(); + } +}; + +class TestModel : public kami::Model { +public: + std::shared_ptr step() override { + return shared_from_this(); + } + + std::shared_ptr run(unsigned int) override { + return shared_from_this(); + } +}; + +TEST(Agent, DefaultConstructor) { + const TestAgent agent_foo; + const TestAgent agent_bar; + + EXPECT_EQ(agent_foo, agent_foo); + EXPECT_NE(agent_foo, agent_bar); +} + +TEST(Agent, get_agent_id) { + const TestAgent agent_foo; + const TestAgent agent_bar; + + EXPECT_EQ(agent_foo.get_agent_id(), agent_foo.get_agent_id()); + EXPECT_NE(agent_bar.get_agent_id(), agent_foo.get_agent_id()); +} + +TEST(Agent, step) { + TestAgent agent_foo; + TestAgent agent_bar; + auto model_world = std::make_shared(); + + EXPECT_EQ(agent_foo.get_agent_id(), agent_foo.step(model_world)); + EXPECT_NE(agent_bar.get_agent_id(), agent_foo.step(model_world)); +} + +TEST(Agent, Equality) { + const TestAgent agent_foo; + const TestAgent agent_bar; + + EXPECT_TRUE(agent_foo == agent_foo); + EXPECT_TRUE(agent_bar == agent_bar); +} + +TEST(Agent, Inequality) { + const TestAgent agent_foo; + const TestAgent agent_bar; + + EXPECT_TRUE(agent_foo != agent_bar); + EXPECT_FALSE(agent_bar != agent_bar); +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} +