Add new unit tests for Agent and AgentID

This commit is contained in:
James P. Howard, II
2022-08-04 22:12:42 -04:00
parent 2d88d32bd6
commit 25b14c8aff
2 changed files with 168 additions and 0 deletions

92
test/unit-kami-agent.cc Normal file
View File

@@ -0,0 +1,92 @@
/*-
* 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 <memory>
#include <kami/agent.h>
#include <kami/model.h>
#include <gtest/gtest.h>
class TestAgent : public kami::Agent {
public:
kami::AgentID step(std::shared_ptr<kami::Model> model) override {
return get_agent_id();
}
};
class TestModel : public kami::Model {
public:
void step() override {}
void run(unsigned int) override {}
};
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<TestModel>();
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();
}

76
test/unit-kami-agentid.cc Normal file
View File

@@ -0,0 +1,76 @@
/*-
* 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 <kami/agent.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
TEST(AgentID, DefaultConstructor) {
const kami::AgentID agent_id_foo;
const kami::AgentID agent_id_bar;
EXPECT_EQ(agent_id_foo, agent_id_foo);
EXPECT_NE(agent_id_foo, agent_id_bar);
}
TEST(AgentID, to_string) {
const kami::AgentID agent_id_foo;
const kami::AgentID agent_id_bar;
EXPECT_THAT(agent_id_foo.to_string(), testing::MatchesRegex("[0-9]+"));
EXPECT_THAT(agent_id_bar.to_string(), testing::MatchesRegex("[0-9]+"));
}
TEST(AgentID, Equality) {
const kami::AgentID agent_id_foo;
const kami::AgentID agent_id_bar;
EXPECT_TRUE(agent_id_foo == agent_id_foo);
EXPECT_TRUE(agent_id_bar == agent_id_bar);
EXPECT_FALSE(agent_id_foo == agent_id_bar);
}
TEST(AgentID, Inequality) {
const kami::AgentID agent_id_foo;
const kami::AgentID agent_id_bar;
EXPECT_TRUE(agent_id_foo != agent_id_bar);
EXPECT_FALSE(agent_id_bar != agent_id_bar);
}
TEST(AgentID, Ordering) {
const kami::AgentID agent_id_foo;
const kami::AgentID agent_id_bar;
EXPECT_TRUE(agent_id_foo < agent_id_bar);
EXPECT_FALSE(agent_id_bar < agent_id_foo);
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}