Updated tests

This commit is contained in:
Pcornat 2024-11-25 16:46:51 +01:00
commit 7a5d36f6ea
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
5 changed files with 57 additions and 31 deletions

View file

@ -20,12 +20,14 @@ namespace character::test {
void from_json(const json &j, DummyObject &dummy) {
BillyObjects::from_json(j, dummy.objects);
}
static std::unique_ptr<GenericObject> get_obj(const billyEnums &object) noexcept {
return std::visit(overloaded{
[](const weapons &arg) { return std::unique_ptr<GenericObject>(std::make_unique<Weapons>(arg)); },
[](const equipments &arg) { return std::unique_ptr<GenericObject>(std::make_unique<Equipments>(arg)); },
[](const tools &arg) { return std::unique_ptr<GenericObject>(std::make_unique<Tools>(arg)); },
}, object);
},
object);
}
}
@ -39,9 +41,7 @@ TEST_CASE("[C] Serialize empty BillyObjects", "[serialize][0]") {
serializer.clear();
REQUIRE_NOTHROW(tester.empty() == true);
REQUIRE(tester.empty());
{
REQUIRE(tester.empty()); {
std::ofstream file{ "billy_objects_empty.json" };
file << tester << std::flush;
}
@ -49,8 +49,7 @@ TEST_CASE("[C] Serialize empty BillyObjects", "[serialize][0]") {
TEST_CASE("[C] Serialize full BillyObjects", "[serialize][1]") {
BillyObjects gestionnaire{};
test::DummyObject dummy_object;
{
test::DummyObject dummy_object; {
CharacterSheet sheet;
REQUIRE(gestionnaire.insert_object(sheet, weapons::Sword));
REQUIRE(gestionnaire.insert_object(sheet, tools::Fourche));
@ -65,9 +64,7 @@ TEST_CASE("[C] Serialize full BillyObjects", "[serialize][1]") {
const auto &tester = serializer.at("sheet").at(BillyObjects::json_key);
REQUIRE_FALSE(tester.empty());
{
REQUIRE_FALSE(tester.empty()); {
std::ofstream file{ "billy_objects_full.json" };
file << tester << std::flush;
}
@ -88,7 +85,6 @@ TEST_CASE("[D] Deserialize empty BillyObjects", "[deserialize][0]") {
}
TEST_CASE("[D] Deserialize full BillyObjects", "[deserialize][1]") {
// BillyObjects gestionnaire{};
test::DummyObject dummy_object;
const auto deserializer = []() -> json {
@ -112,18 +108,18 @@ TEST_CASE("[D] Deserialize full BillyObjects", "[deserialize][1]") {
TEST_CASE("[D] Pushing popping BillyObjects", "[pushpop][0]") {
constexpr std::array<billyEnums, 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,
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{};
@ -160,9 +156,9 @@ TEST_CASE("[D] Printing Billy's objects", "[printing]") {
TEST_CASE("[Z] Cleaning after all tests", "[cleaning]") {
namespace fs = std::filesystem;
const auto pwd = is_directory(fs::current_path()) ?
fs::directory_iterator(fs::current_path()) :
fs::directory_iterator(fs::current_path().root_directory());
const auto pwd = is_directory(fs::current_path())
? fs::directory_iterator(fs::current_path())
: fs::directory_iterator(fs::current_path().root_directory());
for (const auto &entry: pwd) {
if (entry.is_regular_file() && entry.path().extension() == ".json") {
fs::remove(entry);