Adding two more tests.

Deleting useless default case.
This commit is contained in:
Pcornat 2024-03-08 16:30:38 +01:00
parent 2c3d736d5f
commit b2f4f31abd
Signed by: Pcornat
GPG Key ID: E0326CC678A00BDD
2 changed files with 61 additions and 3 deletions

View File

@ -105,3 +105,64 @@ TEST_CASE("[D] Deserialize full BillyObjects", "[deserialize][1]") {
REQUIRE(std::holds_alternative<equipments>(dummy_object.objects[2]));
REQUIRE(std::get<equipments>(dummy_object.objects[2]) == equipments::MedicKit);
}
TEST_CASE("[D] Pushing popping BillyObjects", "[pushpop][0]") {
constexpr std::array<BillyObjects::billyObject, 12> all_objects{
weapons::Sword,
weapons::Lance,
weapons::Morgenstern,
weapons::Bow,
equipments::Chainmail,
equipments::CookingPot,
equipments::PamphletTourist,
equipments::MedicKit,
tools::Fourche,
tools::Dagger,
tools::RockClimbingKit,
tools::SackOfGrain,
};
BillyObjects gestionnaire{};
CharacterSheet sheet;
REQUIRE(sheet.get_objects().empty());
REQUIRE_NOTHROW(gestionnaire.push_object(weapons::Sword, sheet));
REQUIRE_FALSE(sheet.get_objects().empty());
REQUIRE(std::holds_alternative<weapons>(sheet.get_objects().back()));
REQUIRE(std::get<weapons>(sheet.get_objects().back()) == weapons::Sword);
REQUIRE_NOTHROW(gestionnaire.pop_object(sheet));
REQUIRE(sheet.get_objects().empty());
for (std::size_t j = 0; j < all_objects.size(); j += 3) {
for (std::size_t i = 0; i < 3; ++i) {
REQUIRE_NOTHROW(gestionnaire.push_object(all_objects[i + j], sheet));
}
REQUIRE_FALSE(sheet.get_objects().empty());
for (std::size_t i = 0; i < 3; ++i) {
REQUIRE_NOTHROW(gestionnaire.pop_object(sheet));
}
REQUIRE(sheet.get_objects().empty());
}
}
TEST_CASE("[D] Printing Billy's objects", "[printing]") {
constexpr std::array<BillyObjects::billyObject, 12> all_objects{
weapons::Sword,
weapons::Lance,
weapons::Morgenstern,
weapons::Bow,
equipments::Chainmail,
equipments::CookingPot,
equipments::PamphletTourist,
equipments::MedicKit,
tools::Fourche,
tools::Dagger,
tools::RockClimbingKit,
tools::SackOfGrain,
};
for (const auto &object: all_objects) {
REQUIRE_NOTHROW(BillyObjects::billy_object_to_string(object));
}
}

View File

@ -229,9 +229,6 @@ namespace character {
case toolsHash:
billy.push_back(static_cast<tools>(value));
break;
default:
SPDLOG_CRITICAL("Deserialize billy objects error, wrong hash.");
throw std::runtime_error("Deserialize billy objects error, wrong hash.");
}
}
}