diff options
Diffstat (limited to 'core/tests')
| -rw-r--r-- | core/tests/participant.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/core/tests/participant.cpp b/core/tests/participant.cpp index 99e7fa4..6ca3f02 100644 --- a/core/tests/participant.cpp +++ b/core/tests/participant.cpp @@ -2,8 +2,11 @@ #include "turns/core/disposition.hpp" +#include <catch2/catch_approx.hpp> #include <catch2/catch_test_macros.hpp> +#include <nlohmann/json.hpp> + #include <compare> namespace turns::core::tests @@ -109,4 +112,63 @@ namespace turns::core::tests } } + TEST_CASE("Serializing a participant") + { + auto instance = participant::create("Participant #0", 17.2, disposition::friendly); + auto serialized = instance->serialize(); + + SECTION("the active state is de-serialized correctly") + { + REQUIRE_FALSE(serialized.at("active")); + } + + SECTION("the disposition is serialized correctly") + { + REQUIRE(serialized.at("disposition") == disposition::friendly); + } + + SECTION("the name is serialized correctly") + { + REQUIRE(serialized.at("name") == "Participant #0"); + } + + SECTION("the priority is serialized correctly") + { + REQUIRE(serialized.at("priority") == Catch::Approx{17.2}); + } + } + + TEST_CASE("De-Serializing a participant") + { + auto serialized = nlohmann::json::parse(R"( + { + "name": "Participant #1", + "priority": -2.3, + "disposition": 2, + "active": true + } + )"); + auto instance = participant::create(serialized); + + SECTION("the active state is de-serialized correctly") + { + REQUIRE(instance->is_active()); + } + + SECTION("the disposition is de-serialized correctly") + { + REQUIRE(instance->disposition() == disposition::hostile); + } + + SECTION("the name is de-serialized correctly") + { + REQUIRE(instance->name() == "Participant #1"); + } + + SECTION("the priority is de-serialized correctly") + { + REQUIRE(instance->priority() == Catch::Approx{-2.3}); + } + } + } // namespace turns::core::tests
\ No newline at end of file |
