Unit tests done.

This commit is contained in:
Pcornat 2022-01-16 18:47:24 +01:00
parent 0dc0329770
commit 733d949937
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0
2 changed files with 87 additions and 5 deletions

View File

@ -37,7 +37,8 @@ set_target_properties(Catch2 UnitTest PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
INTERPROCEDURAL_OPTIMIZATION ON
UNITY_BUILD ON)
# UNITY_BUILD ON
)
target_include_directories(UnitTest PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_compile_definitions(UnitTest PRIVATE ${DEF_COMP})

View File

@ -3,10 +3,11 @@
#include "characteristic/chance.hpp"
#include "characteristic/endurance.hpp"
#include "characteristic/habilete.hpp"
#include <fstream>
using namespace character::characteristic;
TEST_CASE("Serialize adresse", "[serialize][0]") {
TEST_CASE("[A] Serialize adresse", "[serialize][0]") {
Adresse adresse;
json serializer;
@ -18,9 +19,14 @@ TEST_CASE("Serialize adresse", "[serialize][0]") {
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("Serialize chance", "[serialize][1]") {
TEST_CASE("[A] Serialize chance", "[serialize][1]") {
Chance chance;
json serializer;
@ -32,9 +38,14 @@ TEST_CASE("Serialize chance", "[serialize][1]") {
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("Serialize endurance", "[serialize][2]") {
TEST_CASE("[A] Serialize endurance", "[serialize][2]") {
Endurance endurance;
json serializer;
@ -46,9 +57,14 @@ TEST_CASE("Serialize endurance", "[serialize][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("Serialize habilete", "[serialize][3]") {
TEST_CASE("[A] Serialize habilete", "[serialize][3]") {
Habilete habilete;
json serializer;
@ -60,4 +76,69 @@ TEST_CASE("Serialize habilete", "[serialize][3]") {
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);
}());
}