Compare commits
2 commits
8117dc357f
...
0dc0329770
Author | SHA1 | Date | |
---|---|---|---|
0dc0329770 | |||
a5ce3c378f |
6 changed files with 121 additions and 0 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -7,3 +7,6 @@
|
||||||
[submodule "external/json"]
|
[submodule "external/json"]
|
||||||
path = external/json
|
path = external/json
|
||||||
url = https://github.com/nlohmann/json.git
|
url = https://github.com/nlohmann/json.git
|
||||||
|
[submodule "external/catch2"]
|
||||||
|
path = external/catch2
|
||||||
|
url = https://github.com/catchorg/Catch2.git
|
||||||
|
|
|
@ -82,6 +82,12 @@ add_subdirectory(external/spdlog)
|
||||||
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
set(JSON_BuildTests OFF CACHE INTERNAL "")
|
||||||
add_subdirectory(external/json)
|
add_subdirectory(external/json)
|
||||||
|
|
||||||
|
option(CATCH_INSTALL_DOCS "Install documentation alongside library" OFF)
|
||||||
|
option(CATCH_INSTALL_EXTRAS "Install extras alongside library" OFF)
|
||||||
|
add_subdirectory(external/catch2)
|
||||||
|
|
||||||
|
add_subdirectory("Unit testing")
|
||||||
|
|
||||||
set(COMPILE_FLAGS
|
set(COMPILE_FLAGS
|
||||||
-pipe
|
-pipe
|
||||||
-march=skylake # change to native or your architecture.
|
-march=skylake # change to native or your architecture.
|
||||||
|
|
46
Unit testing/CMakeLists.txt
Normal file
46
Unit testing/CMakeLists.txt
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(UnitTest CXX)
|
||||||
|
|
||||||
|
set(COMPILE_FLAGS
|
||||||
|
-pipe
|
||||||
|
-march=skylake # change to native or your architecture.
|
||||||
|
-mtune=skylake # same as above
|
||||||
|
-mrdseed # be careful about this, this is linked to the x86 architecture.
|
||||||
|
-mrdrnd # same as above
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-Wpedantic
|
||||||
|
# -Wpadded
|
||||||
|
-pedantic
|
||||||
|
-ffunction-sections
|
||||||
|
-fdata-sections
|
||||||
|
-fuse-ld=gold
|
||||||
|
-funroll-loops
|
||||||
|
-fdevirtualize-at-ltrans
|
||||||
|
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
|
||||||
|
)
|
||||||
|
set(LINKER_OPTIONS
|
||||||
|
-Wl,--sort-common,--as-needed,--gc-sections,--strip-all
|
||||||
|
-fuse-ld=gold
|
||||||
|
-fdevirtualize-at-ltrans
|
||||||
|
)
|
||||||
|
|
||||||
|
set(LINKER_FLAGS
|
||||||
|
jemalloc
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(UnitTest adummy.cpp characteristics_tests.cpp)
|
||||||
|
|
||||||
|
set_target_properties(Catch2 UnitTest PROPERTIES
|
||||||
|
CXX_STANDARD 17
|
||||||
|
CXX_STANDARD_REQUIRED ON
|
||||||
|
CXX_EXTENSIONS OFF
|
||||||
|
INTERPROCEDURAL_OPTIMIZATION ON
|
||||||
|
UNITY_BUILD ON)
|
||||||
|
|
||||||
|
target_include_directories(UnitTest PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
||||||
|
target_compile_definitions(UnitTest PRIVATE ${DEF_COMP})
|
||||||
|
target_compile_options(UnitTest PRIVATE ${COMPILE_FLAGS})
|
||||||
|
target_link_options(UnitTest PRIVATE ${LINKER_OPTIONS})
|
||||||
|
target_link_libraries(UnitTest ${LINKER_FLAGS} Catch2 nlohmann_json::nlohmann_json)
|
2
Unit testing/adummy.cpp
Normal file
2
Unit testing/adummy.cpp
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include <catch2/catch.hpp>
|
63
Unit testing/characteristics_tests.cpp
Normal file
63
Unit testing/characteristics_tests.cpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
#include "characteristic/adresse.hpp"
|
||||||
|
#include "characteristic/chance.hpp"
|
||||||
|
#include "characteristic/endurance.hpp"
|
||||||
|
#include "characteristic/habilete.hpp"
|
||||||
|
|
||||||
|
using namespace character::characteristic;
|
||||||
|
|
||||||
|
TEST_CASE("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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("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);
|
||||||
|
}
|
1
external/catch2
vendored
Submodule
1
external/catch2
vendored
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 216713a4066b79d9803d374f261ccb30c0fb451f
|
Loading…
Add table
Add a link
Reference in a new issue