2022-01-14 23:36:38 +01:00
|
|
|
#include <catch2/catch.hpp>
|
2022-01-14 23:48:58 +01:00
|
|
|
#include "characteristic/adresse.hpp"
|
|
|
|
#include "characteristic/chance.hpp"
|
|
|
|
#include "characteristic/endurance.hpp"
|
|
|
|
#include "characteristic/habilete.hpp"
|
2022-01-16 18:47:24 +01:00
|
|
|
#include <fstream>
|
2022-01-14 23:48:58 +01:00
|
|
|
|
|
|
|
using namespace character::characteristic;
|
2022-01-14 23:36:38 +01:00
|
|
|
|
2022-01-16 18:47:24 +01:00
|
|
|
TEST_CASE("[A] Serialize adresse", "[serialize][0]") {
|
2022-01-14 23:48:58 +01:00
|
|
|
Adresse adresse;
|
|
|
|
json serializer;
|
|
|
|
|
|
|
|
REQUIRE_NOTHROW(serializer.emplace("adresse", adresse));
|
|
|
|
|
|
|
|
const auto &tester = serializer.at("adresse");
|
2022-01-14 23:36:38 +01:00
|
|
|
|
2022-01-14 23:48:58 +01:00
|
|
|
REQUIRE_NOTHROW(tester.at("base") == 1);
|
|
|
|
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
|
|
|
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
|
|
|
REQUIRE_NOTHROW(tester.at("additional") == 0);
|
2022-01-16 18:47:24 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
std::ofstream file{ "adresse.json" };
|
|
|
|
file << serializer << std::flush;
|
|
|
|
}
|
2022-01-14 23:36:38 +01:00
|
|
|
}
|
|
|
|
|
2022-01-16 18:47:24 +01:00
|
|
|
TEST_CASE("[A] Serialize chance", "[serialize][1]") {
|
2022-01-14 23:48:58 +01:00
|
|
|
Chance chance;
|
|
|
|
json serializer;
|
|
|
|
|
|
|
|
REQUIRE_NOTHROW(serializer.emplace("chance", chance));
|
|
|
|
|
|
|
|
const auto &tester = serializer.at("chance");
|
2022-01-14 23:36:38 +01:00
|
|
|
|
2022-01-14 23:48:58 +01:00
|
|
|
REQUIRE_NOTHROW(tester.at("base") == 3);
|
|
|
|
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
|
|
|
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
|
|
|
REQUIRE_NOTHROW(tester.at("additional") == 0);
|
2022-01-16 18:47:24 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
std::ofstream file{ "chance.json" };
|
|
|
|
file << serializer << std::flush;
|
|
|
|
}
|
2022-01-14 23:36:38 +01:00
|
|
|
}
|
|
|
|
|
2022-01-16 18:47:24 +01:00
|
|
|
TEST_CASE("[A] Serialize endurance", "[serialize][2]") {
|
2022-01-14 23:48:58 +01:00
|
|
|
Endurance endurance;
|
|
|
|
json serializer;
|
2022-01-14 23:36:38 +01:00
|
|
|
|
2022-01-14 23:48:58 +01:00
|
|
|
REQUIRE_NOTHROW(serializer.emplace("endurance", endurance));
|
|
|
|
|
|
|
|
const auto &tester = serializer.at("endurance");
|
|
|
|
|
|
|
|
REQUIRE_NOTHROW(tester.at("base") == 2);
|
|
|
|
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
|
|
|
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
|
|
|
REQUIRE_NOTHROW(tester.at("additional") == 0);
|
2022-01-16 18:47:24 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
std::ofstream file{ "endurance.json" };
|
|
|
|
file << serializer << std::flush;
|
|
|
|
}
|
2022-01-14 23:36:38 +01:00
|
|
|
}
|
|
|
|
|
2022-01-16 18:47:24 +01:00
|
|
|
TEST_CASE("[A] Serialize habilete", "[serialize][3]") {
|
2022-01-14 23:48:58 +01:00
|
|
|
Habilete habilete;
|
|
|
|
json serializer;
|
|
|
|
|
|
|
|
REQUIRE_NOTHROW(serializer.emplace("habilete", habilete));
|
|
|
|
|
|
|
|
const auto &tester = serializer.at("habilete");
|
2022-01-14 23:36:38 +01:00
|
|
|
|
2022-01-14 23:48:58 +01:00
|
|
|
REQUIRE_NOTHROW(tester.at("base") == 2);
|
|
|
|
REQUIRE_NOTHROW(tester.at("carac") == 0);
|
|
|
|
REQUIRE_NOTHROW(tester.at("materiel") == 0);
|
|
|
|
REQUIRE_NOTHROW(tester.at("additional") == 0);
|
2022-01-16 18:47:24 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
std::ofstream file{ "habilete.json" };
|
|
|
|
file << serializer << std::flush;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("[B] Deserialize adresse", "[deserialize][0]") {
|
|
|
|
const json deserializer = []() -> json {
|
|
|
|
std::ifstream file{ "adresse.json" };
|
|
|
|
json des = json::parse(file);
|
|
|
|
return des;
|
|
|
|
}();
|
|
|
|
REQUIRE_NOTHROW([&]() -> void {
|
|
|
|
const auto adresse = deserializer.at("adresse").get<Adresse>();
|
|
|
|
REQUIRE(adresse.get_base() == 1);
|
|
|
|
REQUIRE(adresse.get_carac() == 0);
|
|
|
|
REQUIRE(adresse.get_materiel() == 0);
|
|
|
|
REQUIRE(adresse.get_additional() == 0);
|
|
|
|
}());
|
2022-01-14 23:36:38 +01:00
|
|
|
}
|
2022-01-16 18:47:24 +01:00
|
|
|
|
|
|
|
TEST_CASE("[B] Deserialize chance", "[deserialize][1]") {
|
|
|
|
const json deserializer = []() -> json {
|
|
|
|
std::ifstream file{ "chance.json" };
|
|
|
|
json des = json::parse(file);
|
|
|
|
return des;
|
|
|
|
}();
|
|
|
|
REQUIRE_NOTHROW([&]() -> void {
|
|
|
|
const auto adresse = deserializer.at("chance").get<Adresse>();
|
|
|
|
REQUIRE(adresse.get_base() == 3);
|
|
|
|
REQUIRE(adresse.get_carac() == 0);
|
|
|
|
REQUIRE(adresse.get_materiel() == 0);
|
|
|
|
REQUIRE(adresse.get_additional() == 0);
|
|
|
|
}());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("[B] Deserialize endurance", "[deserialize][2]") {
|
|
|
|
const json deserializer = []() -> json {
|
|
|
|
std::ifstream file{ "endurance.json" };
|
|
|
|
json des = json::parse(file);
|
|
|
|
return des;
|
|
|
|
}();
|
|
|
|
REQUIRE_NOTHROW([&]() -> void {
|
|
|
|
const auto adresse = deserializer.at("endurance").get<Adresse>();
|
|
|
|
REQUIRE(adresse.get_base() == 2);
|
|
|
|
REQUIRE(adresse.get_carac() == 0);
|
|
|
|
REQUIRE(adresse.get_materiel() == 0);
|
|
|
|
REQUIRE(adresse.get_additional() == 0);
|
|
|
|
}());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("[B] Deserialize habilete", "[deserialize][3]") {
|
|
|
|
const json deserializer = []() -> json {
|
|
|
|
std::ifstream file{ "habilete.json" };
|
|
|
|
json des = json::parse(file);
|
|
|
|
return des;
|
|
|
|
}();
|
|
|
|
REQUIRE_NOTHROW([&]() -> void {
|
|
|
|
const auto adresse = deserializer.at("habilete").get<Adresse>();
|
|
|
|
REQUIRE(adresse.get_base() == 2);
|
|
|
|
REQUIRE(adresse.get_carac() == 0);
|
|
|
|
REQUIRE(adresse.get_materiel() == 0);
|
|
|
|
REQUIRE(adresse.get_additional() == 0);
|
|
|
|
}());
|
|
|
|
}
|