BillySheet/Unit testing/characteristics_tests.cpp

144 lines
4.3 KiB
C++

#include <catch2/catch_all.hpp>
#include "characteristic/adresse.hpp"
#include "characteristic/chance.hpp"
#include "characteristic/endurance.hpp"
#include "characteristic/habilete.hpp"
#include <fstream>
using namespace character::characteristic;
TEST_CASE("[A] Serialize adresse", "[serialize][0]") {
Adresse adresse;
json serializer;
REQUIRE_NOTHROW(serializer.emplace("adresse", adresse));
const auto &tester = serializer.at("adresse");
REQUIRE_NOTHROW(tester.at("base") == 1);
REQUIRE_NOTHROW(tester.at("carac") == 0);
REQUIRE_NOTHROW(tester.at("materiel") == 0);
REQUIRE_NOTHROW(tester.at("additional") == 0);
{
std::ofstream file{ "adresse.json" };
file << serializer << std::flush;
}
}
TEST_CASE("[A] Serialize chance", "[serialize][1]") {
Chance chance;
json serializer;
REQUIRE_NOTHROW(serializer.emplace("chance", chance));
const auto &tester = serializer.at("chance");
REQUIRE_NOTHROW(tester.at("base") == 3);
REQUIRE_NOTHROW(tester.at("carac") == 0);
REQUIRE_NOTHROW(tester.at("materiel") == 0);
REQUIRE_NOTHROW(tester.at("additional") == 0);
{
std::ofstream file{ "chance.json" };
file << serializer << std::flush;
}
}
TEST_CASE("[A] Serialize endurance", "[serialize][2]") {
Endurance endurance;
json serializer;
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);
{
std::ofstream file{ "endurance.json" };
file << serializer << std::flush;
}
}
TEST_CASE("[A] Serialize habilete", "[serialize][3]") {
Habilete habilete;
json serializer;
REQUIRE_NOTHROW(serializer.emplace("habilete", habilete));
const auto &tester = serializer.at("habilete");
REQUIRE_NOTHROW(tester.at("base") == 2);
REQUIRE_NOTHROW(tester.at("carac") == 0);
REQUIRE_NOTHROW(tester.at("materiel") == 0);
REQUIRE_NOTHROW(tester.at("additional") == 0);
{
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);
}());
}
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);
}());
}