From ccbe976e466ac7bddce4054dce250d5ab7ca9291 Mon Sep 17 00:00:00 2001 From: Bryce Ferenczi Date: Sat, 10 Aug 2024 21:44:25 +1000 Subject: [PATCH] update test exe path in gh-wf, bump cpm, cxxopts and spdlog version, add formatter for Action::TargetType Signed-off-by: Bryce Ferenczi --- .github/workflows/test.yml | 5 ++--- CMakeLists.txt | 4 ++-- cmake/CPM.cmake | 4 ++-- include/data_structures/common.hpp | 24 ++++++++++++++++++++++++ include/data_structures/enums.hpp | 12 ++++++------ test/test_vectorization.cpp | 9 +++++++++ 6 files changed, 45 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 70bb21e..1c7094e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,12 +39,11 @@ jobs: run: | export CC="/usr/bin/gcc-${{ matrix.gcc-version }}" export CXX="/usr/bin/g++-${{ matrix.gcc-version }}" - cmake -B /home/runner/work/sc2-serializer/build -G Ninja -DSC2_PY_READER=OFF -DSC2_TESTS=ON -DBUILD_API_EXAMPLES=OFF + cmake -B /home/runner/work/sc2-serializer/build -G Ninja -DSC2_PY_READER=OFF -DSC2_TESTS=ON -DBUILD_API_EXAMPLES=OFF -DBUILD_API_TESTS=OFF - name: Build and run tests run: | cmake --build /home/runner/work/sc2-serializer/build --parallel --config Release - /home/runner/work/sc2-serializer/build/test_database - /home/runner/work/sc2-serializer/build/test_readwrite + /home/runner/work/sc2-serializer/build/sc2_tests - name: Archive build artifacts uses: actions/upload-artifact@v4 with: diff --git a/CMakeLists.txt b/CMakeLists.txt index d640a2f..12e8b8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ cpmaddpackage( GITHUB_REPOSITORY jarro2783/cxxopts VERSION - 2.2.1 + 3.2.0 OPTIONS "CXXOPTS_BUILD_EXAMPLES NO" "CXXOPTS_BUILD_TESTS NO" @@ -41,7 +41,7 @@ cpmaddpackage( GITHUB_REPOSITORY gabime/spdlog VERSION - 1.12.0 + 1.14.1 OPTIONS "SPDLOG_BUILD_PIC ON") diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index 8993c49..ba6ecba 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -2,8 +2,8 @@ # # SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors -set(CPM_DOWNLOAD_VERSION 0.38.6) -set(CPM_HASH_SUM "11c3fa5f1ba14f15d31c2fb63dbc8628ee133d81c8d764caad9a8db9e0bacb07") +set(CPM_DOWNLOAD_VERSION 0.40.2) +set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d") if(CPM_SOURCE_CACHE) set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") diff --git a/include/data_structures/common.hpp b/include/data_structures/common.hpp index 66a13c5..2abc30a 100644 --- a/include/data_structures/common.hpp +++ b/include/data_structures/common.hpp @@ -300,4 +300,28 @@ template auto enumToOneHot(Action::TargetType e) noexcept -> std::ve return detail::enumToOneHot_helper(e, vals); } + }// namespace cvt + +/** + * @brief fmt formatter specialization for cvt::Action::TargetType + */ +template<> struct fmt::formatter : formatter +{ + auto format(cvt::Action::TargetType a, format_context &ctx) const -> format_context::iterator + { + string_view ret = "Invalid"; + switch (a) { + case cvt::Action::TargetType::Self: + ret = "Self"; + break; + case cvt::Action::TargetType::OtherUnit: + ret = "OtherUnit"; + break; + case cvt::Action::TargetType::Position: + ret = "Position"; + break; + } + return formatter::format(ret, ctx); + } +}; diff --git a/include/data_structures/enums.hpp b/include/data_structures/enums.hpp index 6d784b8..67a6263 100644 --- a/include/data_structures/enums.hpp +++ b/include/data_structures/enums.hpp @@ -135,7 +135,7 @@ auto enumToOneHot(E e) noexcept -> std::vector */ template<> struct fmt::formatter : formatter { - auto format(cvt::Alliance a, format_context &ctx) const + auto format(cvt::Alliance a, format_context &ctx) const -> format_context::iterator { string_view ret = "Invalid"; switch (a) { @@ -162,7 +162,7 @@ template<> struct fmt::formatter : formatter */ template<> struct fmt::formatter : formatter { - auto format(cvt::CloakState c, format_context &ctx) const + auto format(cvt::CloakState c, format_context &ctx) const -> format_context::iterator { string_view ret = "Invalid"; switch (c) { @@ -192,7 +192,7 @@ template<> struct fmt::formatter : formatter template<> struct fmt::formatter : formatter { // auto format(cvt::Visibility v, format_context &ctx) const; - auto format(cvt::Visibility v, format_context &ctx) const + auto format(cvt::Visibility v, format_context &ctx) const -> format_context::iterator { string_view ret = "Invalid"; switch (v) { @@ -215,7 +215,7 @@ template<> struct fmt::formatter : formatter */ template<> struct fmt::formatter : formatter { - auto format(cvt::AddOn a, format_context &ctx) const + auto format(cvt::AddOn a, format_context &ctx) const -> format_context::iterator { string_view ret = "Invalid"; switch (a) { @@ -238,7 +238,7 @@ template<> struct fmt::formatter : formatter */ template<> struct fmt::formatter : formatter { - auto format(cvt::Race r, format_context &ctx) const + auto format(cvt::Race r, format_context &ctx) const -> format_context::iterator { string_view ret = "Invalid"; switch (r) { @@ -264,7 +264,7 @@ template<> struct fmt::formatter : formatter */ template<> struct fmt::formatter : formatter { - auto format(cvt::Result r, format_context &ctx) const + auto format(cvt::Result r, format_context &ctx) const -> format_context::iterator { string_view ret = "Invalid"; switch (r) { diff --git a/test/test_vectorization.cpp b/test/test_vectorization.cpp index 202c74d..d669a07 100644 --- a/test/test_vectorization.cpp +++ b/test/test_vectorization.cpp @@ -3,6 +3,15 @@ #include +TEST(AutoVectorTest, OneHotEnum) +{ + ASSERT_EQ(cvt::numEnumValues(), 4uz); + auto e = cvt::Alliance::Ally; + auto oneHot = cvt::enumToOneHot(e); + std::vector expected = { 0.f, 1.f, 0.f, 0.f }; + ASSERT_EQ(oneHot, expected); +} + TEST(AutoVectorTest, NeutralUnit) { cvt::NeutralUnit unit;