Compare commits

..

No commits in common. "166fa6007a0242b1f6c3c59bcf1ca2780e6a731e" and "2b59a832a458f9a5cb14073b67533d8f9f33abb0" have entirely different histories.

4 changed files with 27 additions and 35 deletions

View file

@ -88,7 +88,7 @@ set_target_properties(BillySheet PROPERTIES
PUBLIC_HEADER "include/billy_objects.hpp;include/character_sheet.hpp;include/generic_object.hpp;include/characteristic.hpp" PUBLIC_HEADER "include/billy_objects.hpp;include/character_sheet.hpp;include/generic_object.hpp;include/characteristic.hpp"
) )
target_compile_definitions(BillySheet PUBLIC target_compile_definitions(BillySheet PRIVATE
$<$<CONFIG:Debug>:_GLIBCXX_DEBUG> $<$<CONFIG:Debug>:_GLIBCXX_DEBUG>
) )

View file

@ -9,7 +9,7 @@ add_executable(UnitTest adummy.cpp
billy_objects_tests.cpp billy_objects_tests.cpp
) )
set_target_properties(Catch2 UnitTest PROPERTIES set_target_properties(Catch2 UnitTest svector PROPERTIES
CXX_STANDARD 17 CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF CXX_EXTENSIONS OFF
@ -20,7 +20,7 @@ target_include_directories(UnitTest PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_compile_definitions(UnitTest PRIVATE ${DEF_COMP}) target_compile_definitions(UnitTest PRIVATE ${DEF_COMP})
target_compile_options(UnitTest PRIVATE ${COMPILE_FLAGS} -fdiagnostics-all-candidates) target_compile_options(UnitTest PRIVATE ${COMPILE_FLAGS} -fdiagnostics-all-candidates)
target_link_options(UnitTest PRIVATE ${LINKER_OPTIONS}) target_link_options(UnitTest PRIVATE ${LINKER_OPTIONS})
target_link_libraries(UnitTest ${LINKER_FLAGS} Catch2::Catch2WithMain nlohmann_json::nlohmann_json BillySheet) target_link_libraries(UnitTest ${LINKER_FLAGS} spdlog::spdlog_header_only Catch2::Catch2WithMain nlohmann_json::nlohmann_json svector::svector BillySheet)
enable_testing() enable_testing()
catch_discover_tests(UnitTest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} REPORTER junit OUTPUT_DIR ${CMAKE_SOURCE_DIR} OUTPUT_PREFIX cppspec- OUTPUT_SUFFIX .xml) catch_discover_tests(UnitTest WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} REPORTER junit OUTPUT_DIR ${CMAKE_SOURCE_DIR} OUTPUT_PREFIX cppspec- OUTPUT_SUFFIX .xml)

View file

@ -3,7 +3,6 @@
#include <fstream> #include <fstream>
#include "billy_objects.hpp" #include "billy_objects.hpp"
#include "character_sheet.hpp" #include "character_sheet.hpp"
#include "generic_object.hpp"
using namespace character; using namespace character;
@ -20,13 +19,6 @@ namespace character::test {
void from_json(const json &j, DummyObject &dummy) { void from_json(const json &j, DummyObject &dummy) {
BillyObjects::from_json(j, dummy.objects); 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);
}
} }
TEST_CASE("[C] Serialize empty BillyObjects", "[serialize][0]") { TEST_CASE("[C] Serialize empty BillyObjects", "[serialize][0]") {
@ -52,12 +44,10 @@ TEST_CASE("[C] Serialize full BillyObjects", "[serialize][1]") {
test::DummyObject dummy_object; test::DummyObject dummy_object;
{ {
CharacterSheet sheet; CharacterSheet sheet;
REQUIRE(gestionnaire.insert_object(sheet, weapons::Sword)); gestionnaire.push_object(weapons::Sword, sheet);
REQUIRE(gestionnaire.insert_object(sheet, tools::Fourche)); gestionnaire.push_object(tools::Fourche, sheet);
REQUIRE(gestionnaire.insert_object(sheet, equipments::MedicKit)); gestionnaire.push_object(equipments::MedicKit, sheet);
for (const auto &[obj_type, _]: sheet.get_objects()) { dummy_object.objects = sheet.get_objects();
dummy_object.objects.emplace(obj_type, test::get_obj(obj_type));
}
} }
json serializer; json serializer;
@ -88,7 +78,7 @@ TEST_CASE("[D] Deserialize empty BillyObjects", "[deserialize][0]") {
} }
TEST_CASE("[D] Deserialize full BillyObjects", "[deserialize][1]") { TEST_CASE("[D] Deserialize full BillyObjects", "[deserialize][1]") {
// BillyObjects gestionnaire{}; BillyObjects gestionnaire{};
test::DummyObject dummy_object; test::DummyObject dummy_object;
const auto deserializer = []() -> json { const auto deserializer = []() -> json {
@ -100,18 +90,21 @@ TEST_CASE("[D] Deserialize full BillyObjects", "[deserialize][1]") {
REQUIRE_FALSE(dummy_object.objects.empty()); REQUIRE_FALSE(dummy_object.objects.empty());
REQUIRE_NOTHROW(dummy_object.objects.at(weapons::Sword)); REQUIRE_FALSE(std::holds_alternative<tools>(dummy_object.objects[0]));
REQUIRE(std::get<weapons>(dummy_object.objects.at(weapons::Sword)->get_type()) == weapons::Sword); REQUIRE(std::holds_alternative<weapons>(dummy_object.objects[0]));
REQUIRE(std::get<weapons>(dummy_object.objects[0]) == weapons::Sword);
REQUIRE_NOTHROW(dummy_object.objects.at(tools::Fourche)); REQUIRE_FALSE(std::holds_alternative<weapons>(dummy_object.objects[1]));
REQUIRE(std::get<tools>(dummy_object.objects.at(tools::Fourche)->get_type()) == tools::Fourche); REQUIRE(std::holds_alternative<tools>(dummy_object.objects[1]));
REQUIRE(std::get<tools>(dummy_object.objects[1]) == tools::Fourche);
REQUIRE_NOTHROW(dummy_object.objects.at(equipments::MedicKit)); REQUIRE_FALSE(std::holds_alternative<weapons>(dummy_object.objects[2]));
REQUIRE(std::get<equipments>(dummy_object.objects.at(equipments::MedicKit)->get_type()) == equipments::MedicKit); 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]") { TEST_CASE("[D] Pushing popping BillyObjects", "[pushpop][0]") {
constexpr std::array<billyEnums, 12> all_objects{ constexpr std::array<BillyObjects::billyObject, 12> all_objects{
weapons::Sword, weapons::Sword,
weapons::Lance, weapons::Lance,
weapons::Morgenstern, weapons::Morgenstern,
@ -130,22 +123,22 @@ TEST_CASE("[D] Pushing popping BillyObjects", "[pushpop][0]") {
CharacterSheet sheet; CharacterSheet sheet;
REQUIRE(sheet.get_objects().empty()); REQUIRE(sheet.get_objects().empty());
REQUIRE(gestionnaire.insert_object(sheet, weapons::Sword)); REQUIRE_NOTHROW(gestionnaire.push_object(weapons::Sword, sheet));
REQUIRE_FALSE(sheet.get_objects().empty()); REQUIRE_FALSE(sheet.get_objects().empty());
REQUIRE_NOTHROW(sheet.get_objects().at(weapons::Sword)); REQUIRE(std::holds_alternative<weapons>(sheet.get_objects().back()));
REQUIRE(std::get<weapons>(sheet.get_objects().at(weapons::Sword)->get_type()) == weapons::Sword); REQUIRE(std::get<weapons>(sheet.get_objects().back()) == weapons::Sword);
REQUIRE_NOTHROW(gestionnaire.erase_object(sheet, weapons::Sword)); REQUIRE_NOTHROW(gestionnaire.pop_object(sheet));
REQUIRE(sheet.get_objects().empty()); REQUIRE(sheet.get_objects().empty());
for (std::size_t j = 0; j < all_objects.size(); j += 3) { for (std::size_t j = 0; j < all_objects.size(); j += 3) {
for (std::size_t i = 0; i < 3; ++i) { for (std::size_t i = 0; i < 3; ++i) {
REQUIRE_NOTHROW(gestionnaire.insert_object(sheet, all_objects[i + j])); REQUIRE_NOTHROW(gestionnaire.push_object(all_objects[i + j], sheet));
} }
REQUIRE_FALSE(sheet.get_objects().empty()); REQUIRE_FALSE(sheet.get_objects().empty());
for (std::size_t i = 0; i < 3; ++i) { for (std::size_t i = 0; i < 3; ++i) {
REQUIRE_NOTHROW(gestionnaire.erase_object(sheet, all_objects[i + j])); REQUIRE_NOTHROW(gestionnaire.pop_object(sheet));
} }
REQUIRE(sheet.get_objects().empty()); REQUIRE(sheet.get_objects().empty());
} }
@ -153,8 +146,7 @@ TEST_CASE("[D] Pushing popping BillyObjects", "[pushpop][0]") {
TEST_CASE("[D] Printing Billy's objects", "[printing]") { TEST_CASE("[D] Printing Billy's objects", "[printing]") {
for (const auto &object: BillyObjects::all_objects) { for (const auto &object: BillyObjects::all_objects) {
const std::unique_ptr<GenericObject> obj = test::get_obj(object); REQUIRE_NOTHROW(BillyObjects::billy_object_to_string(object));
REQUIRE_NOTHROW(BillyObjects::billy_object_to_string(obj));
} }
} }

View file

@ -1,7 +1,7 @@
#include <catch2/catch_all.hpp> #include <catch2/catch_all.hpp>
#include <fstream> #include "characteristic/characteristic.hpp"
#include "characteristic.hpp"
#include "character_sheet.hpp" #include "character_sheet.hpp"
#include <fstream>
using namespace character::characteristic; using namespace character::characteristic;