From f79dedc5a0bb61161a00a7c5cc392f2d6a62396a Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Sun, 28 Nov 2021 15:20:00 +0900 Subject: [PATCH 01/11] feat(doctest): Remove library 'googletest' --- .gitmodules | 5 +---- Libraries/googletest | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 160000 Libraries/googletest diff --git a/.gitmodules b/.gitmodules index d0a12a343c..d3370a7c3e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [submodule "Libraries/Clara"] path = Libraries/Clara url = https://github.com/catchorg/Clara -[submodule "Libraries/googletest"] - path = Libraries/googletest - url = https://github.com/google/googletest [submodule "Libraries/googlebenchmark"] path = Libraries/googlebenchmark url = https://github.com/google/benchmark @@ -15,4 +12,4 @@ url = https://github.com/syoyo/tinyobjloader [submodule "Libraries/doctest"] path = Libraries/doctest - url = https://github.com/onqtam/doctest + url = https://github.com/onqtam/doctest \ No newline at end of file diff --git a/Libraries/googletest b/Libraries/googletest deleted file mode 160000 index 703bd9caab..0000000000 --- a/Libraries/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 703bd9caab50b139428cea1aaff9974ebee5742e From 432bcda9acd8795956ec3c36f6e1dde0f14f9016 Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Sun, 28 Nov 2021 15:21:21 +0900 Subject: [PATCH 02/11] build: Remove commands related to 'googletest' --- CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 058dc75be0..6e7305a5a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,15 +123,10 @@ set(RESOURCES_OBJS ${RESOURCES_DIR}/dragon.obj) # Project modules -set(BUILD_GTEST ON CACHE BOOL "" FORCE) set(BUILD_GMOCK ON CACHE BOOL "" FORCE) -find_package(GTest CONFIG) if(FALSE) # GTest_FOUND # link_libraries(GTest::gmock GTest::gtest) else() - set(gtest_force_shared_crt ON CACHE BOOL "") - set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE) - add_subdirectory(Libraries/googletest EXCLUDE_FROM_ALL) add_subdirectory(Libraries/googlebenchmark EXCLUDE_FROM_ALL) endif() add_subdirectory(Libraries/cnpy) From d71ccd7e264e093d94a8a09468257e86a6f2c68d Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Sat, 4 Dec 2021 17:05:15 +0900 Subject: [PATCH 03/11] feat(doctest): Remove command and file related to 'googletest' --- Tests/UnitTests/CMakeLists.txt | 10 +--------- Tests/UnitTests/UnitTests.cpp | 22 ---------------------- 2 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 Tests/UnitTests/UnitTests.cpp diff --git a/Tests/UnitTests/CMakeLists.txt b/Tests/UnitTests/CMakeLists.txt index 094a6b322d..fd3726682a 100644 --- a/Tests/UnitTests/CMakeLists.txt +++ b/Tests/UnitTests/CMakeLists.txt @@ -1,12 +1,6 @@ # Target name set(target UnitTests) -# Includes -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${LIBRARY_DIR}/googletest/googlemock/include - ${LIBRARY_DIR}/googletest/googletest/include) - # Sources file(GLOB sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) @@ -41,6 +35,4 @@ target_compile_definitions(${target} target_link_libraries(${target} PRIVATE ${DEFAULT_LINKER_OPTIONS} - CubbyFlow - gmock - gtest) \ No newline at end of file + CubbyFlow) \ No newline at end of file diff --git a/Tests/UnitTests/UnitTests.cpp b/Tests/UnitTests/UnitTests.cpp deleted file mode 100644 index f6adca0aa6..0000000000 --- a/Tests/UnitTests/UnitTests.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include - -#include - -int main(int argc, char* argv[]) -{ - ::testing::InitGoogleMock(&argc, argv); - ::testing::InitGoogleTest(&argc, argv); - - std::ofstream logFile("UnitTests.log"); - if (logFile) - { - CubbyFlow::Logging::SetAllStream(&logFile); - } - - int ret = RUN_ALL_TESTS(); - - return ret; -} \ No newline at end of file From 0e5b1b5bd7deb8bd5c627eea35db741f3b75aa2e Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Sat, 4 Dec 2021 17:06:59 +0900 Subject: [PATCH 04/11] feat(doctest): Add files to support library 'doctest' --- Tests/UnitTests/doctest_proxy.hpp | 2 ++ Tests/UnitTests/main.cpp | 32 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 Tests/UnitTests/doctest_proxy.hpp create mode 100644 Tests/UnitTests/main.cpp diff --git a/Tests/UnitTests/doctest_proxy.hpp b/Tests/UnitTests/doctest_proxy.hpp new file mode 100644 index 0000000000..2bc78aca7f --- /dev/null +++ b/Tests/UnitTests/doctest_proxy.hpp @@ -0,0 +1,2 @@ +#include +#include \ No newline at end of file diff --git a/Tests/UnitTests/main.cpp b/Tests/UnitTests/main.cpp new file mode 100644 index 0000000000..94159afd64 --- /dev/null +++ b/Tests/UnitTests/main.cpp @@ -0,0 +1,32 @@ +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#define DOCTEST_CONFIG_IMPLEMENT +#include + +#include + +#include + +int main() +{ + doctest::Context context; + + std::ofstream logFile("unit_tests.log"); + if (logFile) + { + CubbyFlow::Logging::SetAllStream(&logFile); + } + + // Run queries, or run tests unless --no-run is specified + const int res = context.run(); + + return res; +} \ No newline at end of file From 3b687c45edd59087e39a93b4d55775cde0ed347c Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Sat, 4 Dec 2021 17:24:51 +0900 Subject: [PATCH 05/11] feat(doctest): Replace library 'googletest' with 'doctest' --- Tests/UnitTests/AnimationTests.cpp | 34 +++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Tests/UnitTests/AnimationTests.cpp b/Tests/UnitTests/AnimationTests.cpp index e3c80212e7..259876d59f 100644 --- a/Tests/UnitTests/AnimationTests.cpp +++ b/Tests/UnitTests/AnimationTests.cpp @@ -1,26 +1,36 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include using namespace CubbyFlow; -TEST(Frame, Constructors) +TEST_CASE("[Frame] - Constructors") { Frame frame; - EXPECT_EQ(0, frame.index); - EXPECT_DOUBLE_EQ(1.0 / 60.0, frame.timeIntervalInSeconds); + CHECK_EQ(0, frame.index); + CHECK_EQ(doctest::Approx(1.0 / 60.0), frame.timeIntervalInSeconds); } -TEST(Frame, TimeInSeconds) +TEST_CASE("[Frame] - TimeInSeconds") { Frame frame; frame.index = 180; - EXPECT_DOUBLE_EQ(3.0, frame.TimeInSeconds()); + CHECK_EQ(doctest::Approx(3.0), frame.TimeInSeconds()); } -TEST(Frame, Advance) +TEST_CASE("[Frame] - Advance") { Frame frame; @@ -31,15 +41,15 @@ TEST(Frame, Advance) frame.Advance(); } - EXPECT_EQ(54, frame.index); + CHECK_EQ(54, frame.index); frame.Advance(23); - EXPECT_EQ(77, frame.index); + CHECK_EQ(77, frame.index); - EXPECT_EQ(78, (++frame).index); + CHECK_EQ(78, (++frame).index); - EXPECT_EQ(78, (frame++).index); + CHECK_EQ(78, (frame++).index); - EXPECT_EQ(79, frame.index); + CHECK_EQ(79, frame.index); } \ No newline at end of file From 2fdd2e0f75e5785308455cfaf2bdf5a17e6429e1 Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Mon, 20 Dec 2021 21:54:40 +0900 Subject: [PATCH 06/11] feat(doctest): Replace library 'googletest' with 'doctest' --- Tests/UnitTests/APICSolver2Tests.cpp | 14 ++++++++++++-- Tests/UnitTests/APICSolver3Tests.cpp | 13 +++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Tests/UnitTests/APICSolver2Tests.cpp b/Tests/UnitTests/APICSolver2Tests.cpp index a30269089f..71c2ecdfc9 100644 --- a/Tests/UnitTests/APICSolver2Tests.cpp +++ b/Tests/UnitTests/APICSolver2Tests.cpp @@ -1,10 +1,20 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include using namespace CubbyFlow; -TEST(APICSolver2, UpdateEmpty) +TEST_CASE("[APICSolver2] - UpdateEmpty") { APICSolver2 solver; diff --git a/Tests/UnitTests/APICSolver3Tests.cpp b/Tests/UnitTests/APICSolver3Tests.cpp index 0e533d047d..fbea2519b7 100644 --- a/Tests/UnitTests/APICSolver3Tests.cpp +++ b/Tests/UnitTests/APICSolver3Tests.cpp @@ -1,10 +1,19 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. +#include "doctest_proxy.hpp" #include using namespace CubbyFlow; -TEST(APICSolver3, UpdateEmpty) +TEST_CASE("[APICSolver3] - UpdateEmpty") { APICSolver3 solver; From 733ab5412cd6094148744a75a6a02aa4b8ecaca8 Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Mon, 20 Dec 2021 22:38:39 +0900 Subject: [PATCH 07/11] feat(doctest): Replace library 'googletest' with 'doctest' --- Tests/UnitTests/Array1Tests.cpp | 86 ++++++++++-------- Tests/UnitTests/Array2Tests.cpp | 128 ++++++++++++++------------- Tests/UnitTests/Array3Tests.cpp | 152 +++++++++++++++++--------------- 3 files changed, 198 insertions(+), 168 deletions(-) diff --git a/Tests/UnitTests/Array1Tests.cpp b/Tests/UnitTests/Array1Tests.cpp index 5eb771c86e..bc6ad21101 100644 --- a/Tests/UnitTests/Array1Tests.cpp +++ b/Tests/UnitTests/Array1Tests.cpp @@ -1,142 +1,152 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include #include using namespace CubbyFlow; -TEST(Array1, Constructors) +TEST_CASE("[Array1] - Constructors") { Array1 arr1; - EXPECT_EQ(0u, arr1.Length()); + CHECK_EQ(0u, arr1.Length()); Array1 arr2(9, 1.5f); - EXPECT_EQ(9u, arr2.Length()); + CHECK_EQ(9u, arr2.Length()); for (size_t i = 0; i < 9; ++i) { - EXPECT_FLOAT_EQ(1.5f, arr2[i]); + CHECK_EQ(doctest::Approx(1.5), arr2[i]); } Array1 arr3({ 1.f, 2.f, 3.f, 4.f }); - EXPECT_EQ(4u, arr3.Length()); + CHECK_EQ(4u, arr3.Length()); for (size_t i = 0; i < 4; ++i) { - EXPECT_FLOAT_EQ(static_cast(i) + 1.f, arr3[i]); + CHECK_EQ(doctest::Approx(static_cast(i) + 1.0), arr3[i]); } Array1 arr4({ 1.f, 2.f, 3.f, 4.f }); Array1 arr5(arr4); - EXPECT_EQ(4u, arr5.Length()); + CHECK_EQ(4u, arr5.Length()); for (size_t i = 0; i < 4; ++i) { - EXPECT_FLOAT_EQ(static_cast(i) + 1.f, arr5[i]); + CHECK_EQ(doctest::Approx(static_cast(i) + 1.0), arr5[i]); } } -TEST(Array1, SetMethods) +TEST_CASE("[Array1] - SetMethods") { Array1 arr1(12, -1.f); arr1.Fill(3.5f); for (float a : arr1) { - EXPECT_EQ(3.5f, a); + CHECK_EQ(3.5f, a); } Array1 arr2; arr1.CopyFrom(arr2); - EXPECT_EQ(arr1.Length(), arr2.Length()); + CHECK_EQ(arr1.Length(), arr2.Length()); for (size_t i = 0; i < arr2.Length(); ++i) { - EXPECT_EQ(arr1[i], arr2[i]); + CHECK_EQ(arr1[i], arr2[i]); } arr2 = { 2.f, 5.f, 9.f, -1.f }; - EXPECT_EQ(4u, arr2.Length()); - EXPECT_EQ(2.f, arr2[0]); - EXPECT_EQ(5.f, arr2[1]); - EXPECT_EQ(9.f, arr2[2]); - EXPECT_EQ(-1.f, arr2[3]); + CHECK_EQ(4u, arr2.Length()); + CHECK_EQ(2.f, arr2[0]); + CHECK_EQ(5.f, arr2[1]); + CHECK_EQ(9.f, arr2[2]); + CHECK_EQ(-1.f, arr2[3]); } -TEST(Array1, Clear) +TEST_CASE("[Array1] - Clear") { Array1 arr1 = { 2.f, 5.f, 9.f, -1.f }; arr1.Clear(); - EXPECT_EQ(0u, arr1.Length()); + CHECK_EQ(0u, arr1.Length()); } -TEST(Array1, ResizeMethod) +TEST_CASE("[Array1] - ResizeMethod") { Array1 arr; arr.Resize(9); - EXPECT_EQ(9u, arr.Length()); + CHECK_EQ(9u, arr.Length()); for (size_t i = 0; i < 9; ++i) { - EXPECT_FLOAT_EQ(0.f, arr[i]); + CHECK_EQ(doctest::Approx(0.0), arr[i]); } arr.Resize(12, 4.f); - EXPECT_EQ(12u, arr.Length()); + CHECK_EQ(12u, arr.Length()); for (size_t i = 0; i < 8; ++i) { if (i < 9) { - EXPECT_FLOAT_EQ(0.f, arr[i]); + CHECK_EQ(doctest::Approx(0.0), arr[i]); } else { - EXPECT_FLOAT_EQ(4.f, arr[i]); + CHECK_EQ(doctest::Approx(4.0), arr[i]); } } } -TEST(Array1, Iterators) +TEST_CASE("[Array1] - Iterators") { Array1 arr1 = { 6.f, 4.f, 1.f, -5.f }; size_t i = 0; for (float& elem : arr1) { - EXPECT_FLOAT_EQ(arr1[i], elem); + CHECK_EQ(doctest::Approx(static_cast(arr1[i])), elem); ++i; } i = 0; for (const float& elem : arr1) { - EXPECT_FLOAT_EQ(arr1[i], elem); + CHECK_EQ(doctest::Approx(static_cast(arr1[i])), elem); ++i; } } -TEST(Array1, ForEach) +TEST_CASE("[Array1] - ForEach") { Array1 arr1 = { 6.f, 4.f, 1.f, -5.f }; size_t i = 0; std::for_each(arr1.begin(), arr1.end(), [&](float val) { - EXPECT_FLOAT_EQ(arr1[i], val); + CHECK_EQ(doctest::Approx(static_cast(arr1[i])), val); ++i; }); } -TEST(Array1, ForEachIndex) +TEST_CASE("[Array1] - ForEachIndex") { - Array1 arr1 = { 6.f, 4.f, 1.f, -5.f }; + const Array1 arr1 = { 6.f, 4.f, 1.f, -5.f }; size_t cnt = 0; ForEachIndex(arr1.Length(), [&](size_t i) { - EXPECT_EQ(cnt, i); + CHECK_EQ(cnt, i); ++cnt; }); } -TEST(Array1, ParallelForEachIndex) +TEST_CASE("[Array1] - ParallelForEachIndex") { Array1 arr1(200); ForEachIndex(arr1.Length(), - [&](size_t i) { arr1[i] = static_cast(200.f - i); }); + [&](size_t i) { arr1[i] = 200.f - static_cast(i); }); ParallelForEachIndex(arr1.Length(), [&](size_t i) { - float ans = static_cast(200.f - i); - EXPECT_EQ(ans, arr1[i]); + const auto ans = 200.f - static_cast(i); + CHECK_EQ(ans, arr1[i]); }); } \ No newline at end of file diff --git a/Tests/UnitTests/Array2Tests.cpp b/Tests/UnitTests/Array2Tests.cpp index df9c0a8699..e8e409854c 100644 --- a/Tests/UnitTests/Array2Tests.cpp +++ b/Tests/UnitTests/Array2Tests.cpp @@ -1,160 +1,170 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include #include using namespace CubbyFlow; -TEST(Array2, Constructors) +TEST_CASE("[Array2] - Constructors") { Array2 arr1; - EXPECT_EQ(0u, arr1.Width()); - EXPECT_EQ(0u, arr1.Height()); + CHECK_EQ(0u, arr1.Width()); + CHECK_EQ(0u, arr1.Height()); Array2 arr2(Vector2UZ(3, 7)); - EXPECT_EQ(3u, arr2.Width()); - EXPECT_EQ(7u, arr2.Height()); + CHECK_EQ(3u, arr2.Width()); + CHECK_EQ(7u, arr2.Height()); for (size_t i = 0; i < 21; ++i) { - EXPECT_FLOAT_EQ(0.f, arr2[i]); + CHECK_EQ(doctest::Approx(0.0), arr2[i]); } Array2 arr3(Vector2UZ(1, 9), 1.5f); - EXPECT_EQ(1u, arr3.Width()); - EXPECT_EQ(9u, arr3.Height()); + CHECK_EQ(1u, arr3.Width()); + CHECK_EQ(9u, arr3.Height()); for (size_t i = 0; i < 9; ++i) { - EXPECT_FLOAT_EQ(1.5f, arr3[i]); + CHECK_EQ(doctest::Approx(1.5), arr3[i]); } Array2 arr4(5, 2); - EXPECT_EQ(5u, arr4.Width()); - EXPECT_EQ(2u, arr4.Height()); + CHECK_EQ(5u, arr4.Width()); + CHECK_EQ(2u, arr4.Height()); for (size_t i = 0; i < 10; ++i) { - EXPECT_FLOAT_EQ(0.f, arr4[i]); + CHECK_EQ(doctest::Approx(0.0), arr4[i]); } Array2 arr5(3, 4, 7.f); - EXPECT_EQ(3u, arr5.Width()); - EXPECT_EQ(4u, arr5.Height()); + CHECK_EQ(3u, arr5.Width()); + CHECK_EQ(4u, arr5.Height()); for (size_t i = 0; i < 12; ++i) { - EXPECT_FLOAT_EQ(7.f, arr5[i]); + CHECK_EQ(doctest::Approx(7.0), arr5[i]); } Array2 arr6({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); - EXPECT_EQ(4u, arr6.Width()); - EXPECT_EQ(3u, arr6.Height()); + CHECK_EQ(4u, arr6.Width()); + CHECK_EQ(3u, arr6.Height()); for (size_t i = 0; i < 12; ++i) { - EXPECT_FLOAT_EQ(static_cast(i) + 1.f, arr6[i]); + CHECK_EQ(doctest::Approx(static_cast(i) + 1.0), arr6[i]); } Array2 arr7({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); Array2 arr8(arr7); - EXPECT_EQ(4u, arr8.Width()); - EXPECT_EQ(3u, arr8.Height()); + CHECK_EQ(4u, arr8.Width()); + CHECK_EQ(3u, arr8.Height()); for (size_t i = 0; i < 12; ++i) { - EXPECT_FLOAT_EQ(static_cast(i) + 1.f, arr8[i]); + CHECK_EQ(doctest::Approx(static_cast(i) + 1.0), arr8[i]); } } -TEST(Array2, Clear) +TEST_CASE("[Array2] - Clear") { Array2 arr({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); arr.Clear(); - EXPECT_EQ(0u, arr.Width()); - EXPECT_EQ(0u, arr.Height()); + CHECK_EQ(0u, arr.Width()); + CHECK_EQ(0u, arr.Height()); } -TEST(Array2, ResizeMethod) +TEST_CASE("[Array2] - ResizeMethod") { Array2 arr1; arr1.Resize(Vector2UZ(2, 9)); - EXPECT_EQ(2u, arr1.Width()); - EXPECT_EQ(9u, arr1.Height()); + CHECK_EQ(2u, arr1.Width()); + CHECK_EQ(9u, arr1.Height()); for (size_t i = 0; i < 18; ++i) { - EXPECT_FLOAT_EQ(0.f, arr1[i]); + CHECK_EQ(doctest::Approx(0.0), arr1[i]); } arr1.Resize(Vector2UZ(8, 13), 4.f); - EXPECT_EQ(8u, arr1.Width()); - EXPECT_EQ(13u, arr1.Height()); + CHECK_EQ(8u, arr1.Width()); + CHECK_EQ(13u, arr1.Height()); for (size_t i = 0; i < 8; ++i) { for (size_t j = 0; j < 13; ++j) { if (i < 2 && j < 9) { - EXPECT_FLOAT_EQ(0.f, arr1(i, j)); + CHECK_EQ(doctest::Approx(0.0), arr1(i, j)); } else { - EXPECT_FLOAT_EQ(4.f, arr1(i, j)); + CHECK_EQ(doctest::Approx(4.0), arr1(i, j)); } } } Array2 arr2; arr2.Resize(7, 6); - EXPECT_EQ(7u, arr2.Width()); - EXPECT_EQ(6u, arr2.Height()); + CHECK_EQ(7u, arr2.Width()); + CHECK_EQ(6u, arr2.Height()); for (size_t i = 0; i < 42; ++i) { - EXPECT_FLOAT_EQ(0.f, arr2[i]); + CHECK_EQ(doctest::Approx(0.0), arr2[i]); } arr2.Resize(1, 9, 3.f); - EXPECT_EQ(1u, arr2.Width()); - EXPECT_EQ(9u, arr2.Height()); + CHECK_EQ(1u, arr2.Width()); + CHECK_EQ(9u, arr2.Height()); for (size_t i = 0; i < 1; ++i) { for (size_t j = 0; j < 9; ++j) { if (j < 6) { - EXPECT_FLOAT_EQ(0.f, arr2(i, j)); + CHECK_EQ(doctest::Approx(0.0), arr2(i, j)); } else { - EXPECT_FLOAT_EQ(3.f, arr2(i, j)); + CHECK_EQ(doctest::Approx(3.0), arr2(i, j)); } } } } -TEST(Array2, Iterators) +TEST_CASE("[Array2] - Iterators") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); - float cnt = 1.f; + double cnt = 1.0; for (float& elem : arr1) { - EXPECT_FLOAT_EQ(cnt, elem); - cnt += 1.f; + CHECK_EQ(doctest::Approx(cnt), elem); + cnt += 1.0; } - cnt = 1.f; + cnt = 1.0; for (const float& elem : arr1) { - EXPECT_FLOAT_EQ(cnt, elem); - cnt += 1.f; + CHECK_EQ(doctest::Approx(cnt), elem); + cnt += 1.0; } } -TEST(Array2, ForEach) +TEST_CASE("[Array2] - ForEach") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -162,47 +172,47 @@ TEST(Array2, ForEach) size_t i = 0; std::for_each(arr1.begin(), arr1.end(), [&](float val) { - EXPECT_FLOAT_EQ(arr1[i], val); + CHECK_EQ(doctest::Approx(static_cast(arr1[i])), val); ++i; }); } -TEST(Array2, ForEachIndex) +TEST_CASE("[Array2] - ForEachIndex") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); ForEachIndex(arr1.Size(), [&](size_t i, size_t j) { - size_t idx = i + (4 * j) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), arr1(i, j)); + const size_t idx = i + (4 * j) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), arr1(i, j)); }); } -TEST(Array2, ParallelForEachIndex) +TEST_CASE("[Array2] - ParallelForEachIndex") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); ParallelForEachIndex(arr1.Size(), [&](size_t i, size_t j) { - size_t idx = i + (4 * j) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), arr1(i, j)); + const size_t idx = i + (4 * j) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), arr1(i, j)); }); } -TEST(Array2, View) +TEST_CASE("[Array2] - View") { Array2 arr({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); ArrayView2 arr2 = arr.View(); - EXPECT_EQ(4u, arr2.Width()); - EXPECT_EQ(3u, arr2.Height()); + CHECK_EQ(4u, arr2.Width()); + CHECK_EQ(3u, arr2.Height()); for (size_t i = 0; i < 12; ++i) { - EXPECT_FLOAT_EQ(static_cast(i) + 1.f, arr2[i]); + CHECK_EQ(doctest::Approx(static_cast(i) + 1.0), arr2[i]); } } diff --git a/Tests/UnitTests/Array3Tests.cpp b/Tests/UnitTests/Array3Tests.cpp index 4978c5e831..7c891e09e8 100644 --- a/Tests/UnitTests/Array3Tests.cpp +++ b/Tests/UnitTests/Array3Tests.cpp @@ -1,51 +1,61 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include #include using namespace CubbyFlow; -TEST(Array3, Constructors) +TEST_CASE("[Array3] - Constructors") { Array3 arr1; - EXPECT_EQ(0u, arr1.Width()); - EXPECT_EQ(0u, arr1.Height()); - EXPECT_EQ(0u, arr1.Depth()); + CHECK_EQ(0u, arr1.Width()); + CHECK_EQ(0u, arr1.Height()); + CHECK_EQ(0u, arr1.Depth()); Array3 arr2(Vector3UZ(3, 7, 4)); - EXPECT_EQ(3u, arr2.Width()); - EXPECT_EQ(7u, arr2.Height()); - EXPECT_EQ(4u, arr2.Depth()); + CHECK_EQ(3u, arr2.Width()); + CHECK_EQ(7u, arr2.Height()); + CHECK_EQ(4u, arr2.Depth()); for (size_t i = 0; i < 84; ++i) { - EXPECT_FLOAT_EQ(0.f, arr2[i]); + CHECK_EQ(doctest::Approx(0.0), arr2[i]); } Array3 arr3(Vector3UZ(1, 9, 5), 1.5f); - EXPECT_EQ(1u, arr3.Width()); - EXPECT_EQ(9u, arr3.Height()); - EXPECT_EQ(5u, arr3.Depth()); + CHECK_EQ(1u, arr3.Width()); + CHECK_EQ(9u, arr3.Height()); + CHECK_EQ(5u, arr3.Depth()); for (size_t i = 0; i < 45; ++i) { - EXPECT_FLOAT_EQ(1.5f, arr3[i]); + CHECK_EQ(doctest::Approx(1.5), arr3[i]); } Array3 arr4(5, 2, 8); - EXPECT_EQ(5u, arr4.Width()); - EXPECT_EQ(2u, arr4.Height()); - EXPECT_EQ(8u, arr4.Depth()); + CHECK_EQ(5u, arr4.Width()); + CHECK_EQ(2u, arr4.Height()); + CHECK_EQ(8u, arr4.Depth()); for (size_t i = 0; i < 80; ++i) { - EXPECT_FLOAT_EQ(0.f, arr4[i]); + CHECK_EQ(doctest::Approx(0.0), arr4[i]); } Array3 arr5(3, 4, 2, 7.f); - EXPECT_EQ(3u, arr5.Width()); - EXPECT_EQ(4u, arr5.Height()); - EXPECT_EQ(2u, arr5.Depth()); + CHECK_EQ(3u, arr5.Width()); + CHECK_EQ(4u, arr5.Height()); + CHECK_EQ(2u, arr5.Depth()); for (size_t i = 0; i < 24; ++i) { - EXPECT_FLOAT_EQ(7.f, arr5[i]); + CHECK_EQ(doctest::Approx(7.0), arr5[i]); } Array3 arr6({ { { 1.f, 2.f, 3.f, 4.f }, @@ -55,12 +65,12 @@ TEST(Array3, Constructors) { 17.f, 18.f, 19.f, 20.f }, { 21.f, 22.f, 23.f, 24.f } } }); - EXPECT_EQ(4u, arr6.Width()); - EXPECT_EQ(3u, arr6.Height()); - EXPECT_EQ(2u, arr6.Depth()); + CHECK_EQ(4u, arr6.Width()); + CHECK_EQ(3u, arr6.Height()); + CHECK_EQ(2u, arr6.Depth()); for (size_t i = 0; i < 24; ++i) { - EXPECT_FLOAT_EQ(static_cast(i) + 1.f, arr6[i]); + CHECK_EQ(doctest::Approx(static_cast(i) + 1.0), arr6[i]); } Array3 arr7({ { { 1.f, 2.f, 3.f, 4.f }, @@ -71,16 +81,16 @@ TEST(Array3, Constructors) { 21.f, 22.f, 23.f, 24.f } } }); Array3 arr8(arr7); - EXPECT_EQ(4u, arr8.Width()); - EXPECT_EQ(3u, arr8.Height()); - EXPECT_EQ(2u, arr8.Depth()); + CHECK_EQ(4u, arr8.Width()); + CHECK_EQ(3u, arr8.Height()); + CHECK_EQ(2u, arr8.Depth()); for (size_t i = 0; i < 24; ++i) { - EXPECT_FLOAT_EQ(static_cast(i) + 1.f, arr8[i]); + CHECK_EQ(doctest::Approx(static_cast(i) + 1.0), arr8[i]); } } -TEST(Array3, Clear) +TEST_CASE("[Array3] - Clear") { Array3 arr({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -90,27 +100,27 @@ TEST(Array3, Clear) { 21.f, 22.f, 23.f, 24.f } } }); arr.Clear(); - EXPECT_EQ(0u, arr.Width()); - EXPECT_EQ(0u, arr.Height()); - EXPECT_EQ(0u, arr.Depth()); + CHECK_EQ(0u, arr.Width()); + CHECK_EQ(0u, arr.Height()); + CHECK_EQ(0u, arr.Depth()); } -TEST(Array3, ResizeMethod) +TEST_CASE("[Array3] - ResizeMethod") { Array3 arr1; arr1.Resize(Vector3UZ(2, 9, 5)); - EXPECT_EQ(2u, arr1.Width()); - EXPECT_EQ(9u, arr1.Height()); - EXPECT_EQ(5u, arr1.Depth()); + CHECK_EQ(2u, arr1.Width()); + CHECK_EQ(9u, arr1.Height()); + CHECK_EQ(5u, arr1.Depth()); for (size_t i = 0; i < 90; ++i) { - EXPECT_FLOAT_EQ(0.f, arr1[i]); + CHECK_EQ(doctest::Approx(0.0), arr1[i]); } arr1.Resize(Vector3UZ(8, 13, 7), 4.f); - EXPECT_EQ(8u, arr1.Width()); - EXPECT_EQ(13u, arr1.Height()); - EXPECT_EQ(7u, arr1.Depth()); + CHECK_EQ(8u, arr1.Width()); + CHECK_EQ(13u, arr1.Height()); + CHECK_EQ(7u, arr1.Depth()); for (size_t k = 0; k < 7; ++k) { for (size_t j = 0; j < 13; ++j) @@ -119,11 +129,11 @@ TEST(Array3, ResizeMethod) { if (i < 2 && j < 9 && k < 5) { - EXPECT_FLOAT_EQ(0.f, arr1(i, j, k)); + CHECK_EQ(doctest::Approx(0.0), arr1(i, j, k)); } else { - EXPECT_FLOAT_EQ(4.f, arr1(i, j, k)); + CHECK_EQ(doctest::Approx(4.0), arr1(i, j, k)); } } } @@ -131,18 +141,18 @@ TEST(Array3, ResizeMethod) Array3 arr2; arr2.Resize(7, 6, 3); - EXPECT_EQ(7u, arr2.Width()); - EXPECT_EQ(6u, arr2.Height()); - EXPECT_EQ(3u, arr2.Depth()); + CHECK_EQ(7u, arr2.Width()); + CHECK_EQ(6u, arr2.Height()); + CHECK_EQ(3u, arr2.Depth()); for (size_t i = 0; i < 126; ++i) { - EXPECT_FLOAT_EQ(0.f, arr2[i]); + CHECK_EQ(doctest::Approx(0.0), arr2[i]); } arr2.Resize(1, 9, 4, 3.f); - EXPECT_EQ(1u, arr2.Width()); - EXPECT_EQ(9u, arr2.Height()); - EXPECT_EQ(4u, arr2.Depth()); + CHECK_EQ(1u, arr2.Width()); + CHECK_EQ(9u, arr2.Height()); + CHECK_EQ(4u, arr2.Depth()); for (size_t k = 0; k < 4; ++k) { for (size_t j = 0; j < 9; ++j) @@ -151,18 +161,18 @@ TEST(Array3, ResizeMethod) { if (j < 6 && k < 3) { - EXPECT_FLOAT_EQ(0.f, arr2(i, j, k)); + CHECK_EQ(doctest::Approx(0.0), arr2(i, j, k)); } else { - EXPECT_FLOAT_EQ(3.f, arr2(i, j, k)); + CHECK_EQ(doctest::Approx(3.0), arr2(i, j, k)); } } } } } -TEST(Array3, Iterators) +TEST_CASE("[Array3] - Iterators") { Array3 arr1({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -171,22 +181,22 @@ TEST(Array3, Iterators) { 17.f, 18.f, 19.f, 20.f }, { 21.f, 22.f, 23.f, 24.f } } }); - float cnt = 1.f; + double cnt = 1.0; for (float& elem : arr1) { - EXPECT_FLOAT_EQ(cnt, elem); - cnt += 1.f; + CHECK_EQ(doctest::Approx(cnt), elem); + cnt += 1.0; } - cnt = 1.f; + cnt = 1.0; for (const float& elem : arr1) { - EXPECT_FLOAT_EQ(cnt, elem); - cnt += 1.f; + CHECK_EQ(doctest::Approx(cnt), elem); + cnt += 1.0; } } -TEST(Array3, ForEach) +TEST_CASE("[Array3] - ForEach") { Array3 arr1({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -197,12 +207,12 @@ TEST(Array3, ForEach) size_t i = 0; std::for_each(arr1.begin(), arr1.end(), [&](float val) { - EXPECT_FLOAT_EQ(arr1[i], val); + CHECK_EQ(doctest::Approx(static_cast(arr1[i])), val); ++i; }); } -TEST(Array3, ForEachIndex) +TEST_CASE("[Array3] - ForEachIndex") { Array3 arr1({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -212,12 +222,12 @@ TEST(Array3, ForEachIndex) { 21.f, 22.f, 23.f, 24.f } } }); ForEachIndex(arr1.Size(), [&](size_t i, size_t j, size_t k) { - size_t idx = i + (4 * (j + 3 * k)) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), arr1(i, j, k)); + const size_t idx = i + (4 * (j + 3 * k)) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), arr1(i, j, k)); }); } -TEST(Array3, ParallelForEachIndex) +TEST_CASE("[Array3] - ParallelForEachIndex") { Array3 arr1({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -227,12 +237,12 @@ TEST(Array3, ParallelForEachIndex) { 21.f, 22.f, 23.f, 24.f } } }); ParallelForEachIndex(arr1.Size(), [&](size_t i, size_t j, size_t k) { - size_t idx = i + (4 * (j + 3 * k)) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), arr1(i, j, k)); + const size_t idx = i + (4 * (j + 3 * k)) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), arr1(i, j, k)); }); } -TEST(Array3, View) +TEST_CASE("[Array3] - View") { Array3 arr({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -242,11 +252,11 @@ TEST(Array3, View) { 21.f, 22.f, 23.f, 24.f } } }); ArrayView3 arr2 = arr.View(); - EXPECT_EQ(4u, arr2.Width()); - EXPECT_EQ(3u, arr2.Height()); + CHECK_EQ(4u, arr2.Width()); + CHECK_EQ(3u, arr2.Height()); for (size_t i = 0; i < 12; ++i) { - EXPECT_FLOAT_EQ(static_cast(i) + 1.f, arr2[i]); + CHECK_EQ(doctest::Approx(static_cast(i) + 1.0), arr2[i]); } } From 8c8b34a9600571fec6eaa221eb7ab334e9e882ee Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Mon, 20 Dec 2021 22:50:22 +0900 Subject: [PATCH 08/11] feat(doctest): Replace library 'googletest' with 'doctest' --- Tests/UnitTests/ArraySamplersTests.cpp | 107 ++++++++++++++----------- Tests/UnitTests/ArrayUtilsTests.cpp | 46 ++++++----- 2 files changed, 88 insertions(+), 65 deletions(-) diff --git a/Tests/UnitTests/ArraySamplersTests.cpp b/Tests/UnitTests/ArraySamplersTests.cpp index afb7b7a142..abb27f14f3 100644 --- a/Tests/UnitTests/ArraySamplersTests.cpp +++ b/Tests/UnitTests/ArraySamplersTests.cpp @@ -1,11 +1,21 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include #include using namespace CubbyFlow; -TEST(NearestArraySampler1, Sample) +TEST_CASE("[NearestArraySampler1] - Sample") { { Array1 grid({ 1.0, 2.0, 3.0, 4.0 }); @@ -14,13 +24,13 @@ TEST(NearestArraySampler1, Sample) gridOrigin); double s0 = sampler(0.45); - EXPECT_LT(std::fabs(s0 - 1.0), 1e-9); + CHECK_LT(std::fabs(s0 - 1.0), 1e-9); double s1 = sampler(1.57); - EXPECT_LT(std::fabs(s1 - 3.0), 1e-9); + CHECK_LT(std::fabs(s1 - 3.0), 1e-9); double s2 = sampler(3.51); - EXPECT_LT(std::fabs(s2 - 4.0), 1e-9); + CHECK_LT(std::fabs(s2 - 4.0), 1e-9); } { @@ -30,14 +40,14 @@ TEST(NearestArraySampler1, Sample) gridOrigin); double s0 = sampler(0.45); - EXPECT_LT(std::fabs(s0 - 4.0), 1e-9); + CHECK_LT(std::fabs(s0 - 4.0), 1e-9); double s1 = sampler(-0.05); - EXPECT_LT(std::fabs(s1 - 3.0), 1e-9); + CHECK_LT(std::fabs(s1 - 3.0), 1e-9); } } -TEST(LinearArraySampler1, Sample) +TEST_CASE("[LinearArraySampler1] - Sample") { { Array1 grid({ 1.0, 2.0, 3.0, 4.0 }); @@ -46,13 +56,13 @@ TEST(LinearArraySampler1, Sample) gridOrigin); double s0 = sampler(0.5); - EXPECT_LT(std::fabs(s0 - 1.5), 1e-9); + CHECK_LT(std::fabs(s0 - 1.5), 1e-9); double s1 = sampler(1.8); - EXPECT_LT(std::fabs(s1 - 2.8), 1e-9); + CHECK_LT(std::fabs(s1 - 2.8), 1e-9); double s2 = sampler(3.5); - EXPECT_NEAR(4.0, s2, 1e-9); + CHECK_EQ(doctest::Approx(4.0), s2); } { @@ -62,26 +72,27 @@ TEST(LinearArraySampler1, Sample) gridOrigin); double s0 = sampler(0.2); - EXPECT_LT(std::fabs(s0 - 3.4), 1e-9); + CHECK_LT(std::fabs(s0 - 3.4), 1e-9); double s1 = sampler(-0.7); - EXPECT_LT(std::fabs(s1 - 1.6), 1e-9); + CHECK_LT(std::fabs(s1 - 1.6), 1e-9); } } -TEST(MonotonicCatmullRomArraySampler1, Sample) +TEST_CASE("[MonotonicCatmullRomArraySampler1] - Sample") { Array1 grid({ 1.0, 2.0, 3.0, 4.0 }); - double gridSpacing = 1.0, gridOrigin = 0.0; - MonotonicCatmullRomArraySampler1 sampler(grid.View(), gridSpacing, - gridOrigin); - - double s0 = sampler(1.25); - EXPECT_LT(2.0, s0); - EXPECT_GT(3.0, s0); + constexpr double gridSpacing = 1.0; + constexpr double gridOrigin = 0.0; + const MonotonicCatmullRomArraySampler1 sampler( + grid.View(), gridSpacing, gridOrigin); + + const double s0 = sampler(1.25); + CHECK_LT(2.0, s0); + CHECK_GT(3.0, s0); } -TEST(NearestArraySampler2, Sample) +TEST_CASE("[NearestArraySampler2] - Sample") { { Array2 grid({ { 1.0, 2.0, 3.0, 4.0 }, @@ -94,13 +105,13 @@ TEST(NearestArraySampler2, Sample) gridOrigin); double s0 = sampler(Vector2D(0.45, 0.45)); - EXPECT_LT(std::fabs(s0 - 1.0), 1e-9); + CHECK_LT(std::fabs(s0 - 1.0), 1e-9); double s1 = sampler(Vector2D(1.57, 4.01)); - EXPECT_LT(std::fabs(s1 - 7.0), 1e-9); + CHECK_LT(std::fabs(s1 - 7.0), 1e-9); double s2 = sampler(Vector2D(3.50, 1.21)); - EXPECT_LT(std::fabs(s2 - 5.0), 1e-9); + CHECK_LT(std::fabs(s2 - 5.0), 1e-9); } { @@ -114,14 +125,14 @@ TEST(NearestArraySampler2, Sample) gridOrigin); double s0 = sampler(Vector2D(0.45, 0.4)); - EXPECT_LT(std::fabs(s0 - 8.0), 1e-9); + CHECK_LT(std::fabs(s0 - 8.0), 1e-9); double s1 = sampler(Vector2D(-0.05, 0.37)); - EXPECT_LT(std::fabs(s1 - 6.0), 1e-9); + CHECK_LT(std::fabs(s1 - 6.0), 1e-9); } } -TEST(LinearArraySampler2, Sample) +TEST_CASE("[LinearArraySampler2] - Sample") { { Array2 grid({ { 1.0, 2.0, 3.0, 4.0 }, @@ -134,10 +145,10 @@ TEST(LinearArraySampler2, Sample) gridOrigin); double s0 = sampler(Vector2D(0.5, 0.5)); - EXPECT_LT(std::fabs(s0 - 2.0), 1e-9); + CHECK_LT(std::fabs(s0 - 2.0), 1e-9); double s1 = sampler(Vector2D(1.5, 4.0)); - EXPECT_LT(std::fabs(s1 - 6.5), 1e-9); + CHECK_LT(std::fabs(s1 - 6.5), 1e-9); } { @@ -151,30 +162,31 @@ TEST(LinearArraySampler2, Sample) gridOrigin); double s0 = sampler(Vector2D(0.5, 0.5)); - EXPECT_LT(std::fabs(s0 - 8.0), 1e-9); + CHECK_LT(std::fabs(s0 - 8.0), 1e-9); double s1 = sampler(Vector2D(-0.5, 0.375)); - EXPECT_LT(std::fabs(s1 - 5.5), 1e-9); + CHECK_LT(std::fabs(s1 - 5.5), 1e-9); } } -TEST(MonotonicCatmullRomArraySampler2, Sample) +TEST_CASE("[MonotonicCatmullRomArraySampler2] - Sample") { Array2 grid({ { 1.0, 2.0, 3.0, 4.0 }, { 2.0, 3.0, 4.0, 5.0 }, { 3.0, 4.0, 5.0, 6.0 }, { 4.0, 5.0, 6.0, 7.0 }, { 5.0, 6.0, 7.0, 8.0 } }); - Vector2D gridSpacing(1.0, 1.0), gridOrigin; - MonotonicCatmullRomArraySampler2 sampler(grid.View(), gridSpacing, - gridOrigin); - - double s0 = sampler(Vector2D(1.5, 2.8)); - EXPECT_LT(4.0, s0); - EXPECT_GT(6.0, s0); + constexpr Vector2D gridSpacing(1.0, 1.0); + constexpr Vector2D gridOrigin; + const MonotonicCatmullRomArraySampler2 sampler( + grid.View(), gridSpacing, gridOrigin); + + const double s0 = sampler(Vector2D(1.5, 2.8)); + CHECK_LT(4.0, s0); + CHECK_GT(6.0, s0); } -TEST(MonotonicCatmullRomArraySampler3, Sample) +TEST_CASE("[MonotonicCatmullRomArraySampler3] - Sample") { Array3 grid(4, 4, 4); for (size_t k = 0; k < 4; ++k) @@ -188,11 +200,12 @@ TEST(MonotonicCatmullRomArraySampler3, Sample) } } - Vector3D gridSpacing(1.0, 1.0, 1.0), gridOrigin; - MonotonicCatmullRomArraySampler3 sampler(grid.View(), gridSpacing, - gridOrigin); + constexpr Vector3D gridSpacing(1.0, 1.0, 1.0); + constexpr Vector3D gridOrigin; + const MonotonicCatmullRomArraySampler3 sampler( + grid.View(), gridSpacing, gridOrigin); - double s0 = sampler(Vector3D(1.5, 1.8, 1.2)); - EXPECT_LT(3.0, s0); - EXPECT_GT(6.0, s0); + const double s0 = sampler(Vector3D(1.5, 1.8, 1.2)); + CHECK_LT(3.0, s0); + CHECK_GT(6.0, s0); } \ No newline at end of file diff --git a/Tests/UnitTests/ArrayUtilsTests.cpp b/Tests/UnitTests/ArrayUtilsTests.cpp index 02f52c241a..0f676cacf6 100644 --- a/Tests/UnitTests/ArrayUtilsTests.cpp +++ b/Tests/UnitTests/ArrayUtilsTests.cpp @@ -1,11 +1,21 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include #include using namespace CubbyFlow; -TEST(ArrayUtils, Fill) +TEST_CASE("[ArrayUtils] - Fill") { Array1 array0(5); @@ -13,18 +23,18 @@ TEST(ArrayUtils, Fill) for (size_t i = 0; i < 5; ++i) { - EXPECT_EQ(3.4, array0[i]); + CHECK_EQ(3.4, array0[i]); } Fill(array0.View(), 2, 4, 4.2); for (size_t i = 2; i < 4; ++i) { - EXPECT_EQ(4.2, array0[i]); + CHECK_EQ(4.2, array0[i]); } } -TEST(ArrayUtils, Copy1) +TEST_CASE("[ArrayUtils] - Copy1") { Array1 array0({ 1.0, 2.0, 3.0, 4.0, 5.0 }); Array1 array1(5); @@ -33,18 +43,18 @@ TEST(ArrayUtils, Copy1) for (size_t i = 1; i < 3; ++i) { - EXPECT_EQ(array0[i], array1[i]); + CHECK_EQ(array0[i], array1[i]); } Copy(array0.View(), 0, 5, array1.View()); for (size_t i = 0; i < 5; ++i) { - EXPECT_EQ(array0[i], array1[i]); + CHECK_EQ(array0[i], array1[i]); } } -TEST(ArrayUtils, Copy2) +TEST_CASE("[ArrayUtils] - Copy2") { Array2 array0({ { 1.0, 2.0 }, { 3.0, 4.0 }, { 5.0, 6.0 } }); Array2 array1(2, 3); @@ -55,7 +65,7 @@ TEST(ArrayUtils, Copy2) { for (size_t i = 0; i < 1; ++i) { - EXPECT_EQ(array0(i, j), array1(i, j)); + CHECK_EQ(array0(i, j), array1(i, j)); } } @@ -65,12 +75,12 @@ TEST(ArrayUtils, Copy2) { for (size_t i = 0; i < 2; ++i) { - EXPECT_EQ(array0(i, j), array1(i, j)); + CHECK_EQ(array0(i, j), array1(i, j)); } } } -TEST(ArrayUtils, Copy3) +TEST_CASE("[ArrayUtils] - Copy3") { Array3 array0({ { { 1.0, 2.0 }, { 3.0, 4.0 }, { 5.0, 6.0 } }, { { 7.0, 8.0 }, { 9.0, 10.0 }, { 11.0, 12.0 } } }); @@ -84,7 +94,7 @@ TEST(ArrayUtils, Copy3) { for (size_t i = 0; i < 1; ++i) { - EXPECT_EQ(array0(i, j, k), array1(i, j, k)); + CHECK_EQ(array0(i, j, k), array1(i, j, k)); } } } @@ -97,13 +107,13 @@ TEST(ArrayUtils, Copy3) { for (size_t i = 0; i < 2; ++i) { - EXPECT_EQ(array0(i, j, k), array1(i, j, k)); + CHECK_EQ(array0(i, j, k), array1(i, j, k)); } } } } -TEST(ArrayUtils, ExtrapolateToRegion2) +TEST_CASE("[ArrayUtils] - ExtrapolateToRegion2") { Array2 data(10, 12, 0.0); Array2 valid(10, 12, static_cast(0)); @@ -112,7 +122,7 @@ TEST(ArrayUtils, ExtrapolateToRegion2) { for (size_t i = 2; i < 6; ++i) { - data(i, j) = static_cast(i + j * 10.0); + data(i, j) = static_cast(i) + static_cast(j) * 10.0; valid(i, j) = 1; } } @@ -137,12 +147,12 @@ TEST(ArrayUtils, ExtrapolateToRegion2) { for (size_t i = 0; i < 10; ++i) { - EXPECT_DOUBLE_EQ(dataAnswer(i, j), data(i, j)); + CHECK_EQ(doctest::Approx(dataAnswer(i, j)), data(i, j)); } } } -TEST(ArrayUtils, ExtrapolateToRegion3) +TEST_CASE("[ArrayUtils] - ExtrapolateToRegion3") { // TODO: Need better testing Array3 data(3, 4, 5, 0.0); @@ -168,7 +178,7 @@ TEST(ArrayUtils, ExtrapolateToRegion3) { for (size_t i = 0; i < 3; ++i) { - EXPECT_DOUBLE_EQ(42.0, data(i, j, k)); + CHECK_EQ(doctest::Approx(42.0), data(i, j, k)); } } } From 1b23dee0f625fa3a876b59501603e0c8794b73ed Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Mon, 20 Dec 2021 23:12:05 +0900 Subject: [PATCH 09/11] feat(doctest): Replace library 'googletest' with 'doctest' --- Tests/UnitTests/ArrayView1Tests.cpp | 70 +++++++++++++----------- Tests/UnitTests/ArrayView2Tests.cpp | 82 ++++++++++++++++------------- Tests/UnitTests/ArrayView3Tests.cpp | 82 ++++++++++++++++------------- 3 files changed, 132 insertions(+), 102 deletions(-) diff --git a/Tests/UnitTests/ArrayView1Tests.cpp b/Tests/UnitTests/ArrayView1Tests.cpp index 1f6182ed18..dd8d6fb29a 100644 --- a/Tests/UnitTests/ArrayView1Tests.cpp +++ b/Tests/UnitTests/ArrayView1Tests.cpp @@ -1,11 +1,21 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include #include using namespace CubbyFlow; -TEST(ArrayView1, Constructors) +TEST_CASE("[ArrayView1] - Constructors") { double data[5]; for (int i = 0; i < 5; ++i) @@ -15,11 +25,11 @@ TEST(ArrayView1, Constructors) ArrayView1 acc(data, 5); - EXPECT_EQ(5u, acc.Length()); - EXPECT_EQ(data, acc.data()); + CHECK_EQ(5u, acc.Length()); + CHECK_EQ(data, acc.data()); } -TEST(ArrayView1, Iterators) +TEST_CASE("[ArrayView1] - Iterators") { Array1 arr1 = { 6.f, 4.f, 1.f, -5.f }; auto acc = arr1.View(); @@ -27,45 +37,45 @@ TEST(ArrayView1, Iterators) size_t i = 0; for (float& elem : acc) { - EXPECT_FLOAT_EQ(acc[i], elem); + CHECK_EQ(doctest::Approx(static_cast(acc[i])), elem); ++i; } i = 0; for (const float& elem : acc) { - EXPECT_FLOAT_EQ(acc[i], elem); + CHECK_EQ(acc[i], elem); ++i; } } -TEST(ArrayView1, ForEachIndex) +TEST_CASE("[ArrayView1] - ForEachIndex") { Array1 arr1 = { 6.f, 4.f, 1.f, -5.f }; - auto acc = arr1.View(); + const auto acc = arr1.View(); size_t cnt = 0; ForEachIndex(acc.Size(), [&](size_t i) { - EXPECT_EQ(cnt, i); + CHECK_EQ(cnt, i); ++cnt; }); } -TEST(ArrayView1, ParallelForEachIndex) +TEST_CASE("[ArrayView1] - ParallelForEachIndex") { Array1 arr1(200); - auto acc = arr1.View(); + const auto acc = arr1.View(); ForEachIndex(acc.Size(), - [&](size_t i) { arr1[i] = static_cast(200.f - i); }); + [&](size_t i) { arr1[i] = 200.f - static_cast(i); }); ParallelForEachIndex(acc.Size(), [&](size_t i) { - float ans = static_cast(200.f - i); - EXPECT_EQ(ans, arr1[i]); + const float ans = 200.f - static_cast(i); + CHECK_EQ(ans, arr1[i]); }); } -TEST(ConstArrayView1, Constructors) +TEST_CASE("[ConstArrayView1] - Constructors") { double data[5]; for (int i = 0; i < 5; ++i) @@ -74,14 +84,14 @@ TEST(ConstArrayView1, Constructors) } // Construct with ArrayView1 - ArrayView1 acc(data, 5); - ConstArrayView1 cacc(acc); + const ArrayView1 acc(data, 5); + const ConstArrayView1 cacc(acc); - EXPECT_EQ(5u, cacc.Length()); - EXPECT_EQ(data, cacc.data()); + CHECK_EQ(5u, cacc.Length()); + CHECK_EQ(data, cacc.data()); } -TEST(ConstArrayView1, Iterators) +TEST_CASE("[ConstArrayView1] - Iterators") { Array1 arr1 = { 6.f, 4.f, 1.f, -5.f }; auto acc = arr1.View(); @@ -89,33 +99,33 @@ TEST(ConstArrayView1, Iterators) size_t i = 0; for (const float& elem : acc) { - EXPECT_FLOAT_EQ(acc[i], elem); + CHECK_EQ(doctest::Approx(static_cast(acc[i])), elem); ++i; } } -TEST(ConstArrayView1, ForEachIndex) +TEST_CASE("[ConstArrayView1] - ForEachIndex") { Array1 arr1 = { 6.f, 4.f, 1.f, -5.f }; - auto acc = arr1.View(); + const auto acc = arr1.View(); size_t cnt = 0; ForEachIndex(acc.Size(), [&](size_t i) { - EXPECT_EQ(cnt, i); + CHECK_EQ(cnt, i); ++cnt; }); } -TEST(ConstArrayView1, ParallelForEachIndex) +TEST_CASE("[ConstArrayView1] - ParallelForEachIndex") { Array1 arr1(200); - auto acc = arr1.View(); + const auto acc = arr1.View(); ForEachIndex(acc.Size(), - [&](size_t i) { arr1[i] = static_cast(200.f - i); }); + [&](size_t i) { arr1[i] = 200.f - static_cast(i); }); ParallelForEachIndex(acc.Size(), [&](size_t i) { - float ans = static_cast(200.f - i); - EXPECT_EQ(ans, arr1[i]); + const float ans = 200.f - static_cast(i); + CHECK_EQ(ans, arr1[i]); }); } \ No newline at end of file diff --git a/Tests/UnitTests/ArrayView2Tests.cpp b/Tests/UnitTests/ArrayView2Tests.cpp index 2d1f101de7..7b0f0b76a2 100644 --- a/Tests/UnitTests/ArrayView2Tests.cpp +++ b/Tests/UnitTests/ArrayView2Tests.cpp @@ -1,11 +1,21 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include #include using namespace CubbyFlow; -TEST(ArrayView2, Constructors) +TEST_CASE("[ArrayView2] - Constructors") { double data[20]; for (int i = 0; i < 20; ++i) @@ -15,58 +25,58 @@ TEST(ArrayView2, Constructors) ArrayView2 acc(data, Vector2UZ(5, 4)); - EXPECT_EQ(5u, acc.Size().x); - EXPECT_EQ(4u, acc.Size().y); - EXPECT_EQ(data, acc.data()); + CHECK_EQ(5u, acc.Size().x); + CHECK_EQ(4u, acc.Size().y); + CHECK_EQ(data, acc.data()); } -TEST(ArrayView2, Iterators) +TEST_CASE("[ArrayView2] - Iterators") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); auto acc = arr1.View(); - float cnt = 1.f; + double cnt = 1.0; for (float& elem : acc) { - EXPECT_FLOAT_EQ(cnt, elem); - cnt += 1.f; + CHECK_EQ(doctest::Approx(cnt), elem); + cnt += 1.0; } - cnt = 1.f; + cnt = 1.0; for (const float& elem : acc) { - EXPECT_FLOAT_EQ(cnt, elem); - cnt += 1.f; + CHECK_EQ(doctest::Approx(cnt), elem); + cnt += 1.0; } } -TEST(ArrayView2, ForEachIndex) +TEST_CASE("[ArrayView2] - ForEachIndex") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); ForEachIndex(arr1.Size(), [&](size_t i, size_t j) { - size_t idx = i + (4 * j) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), arr1(i, j)); + const size_t idx = i + (4 * j) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), arr1(i, j)); }); } -TEST(ArrayView2, ParallelForEachIndex) +TEST_CASE("[ArrayView2] - ParallelForEachIndex") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); ParallelForEachIndex(arr1.Size(), [&](size_t i, size_t j) { - size_t idx = i + (4 * j) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), arr1(i, j)); + const size_t idx = i + (4 * j) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), arr1(i, j)); }); } -TEST(ConstArrayView2, Constructors) +TEST_CASE("[ConstArrayView2] - Constructors") { double data[20]; for (int i = 0; i < 20; ++i) @@ -75,30 +85,30 @@ TEST(ConstArrayView2, Constructors) } // Construct with ArrayView2 - ArrayView2 acc(data, Vector2UZ(5, 4)); - ConstArrayView2 cacc(acc); + const ArrayView2 acc(data, Vector2UZ(5, 4)); + const ConstArrayView2 cacc(acc); - EXPECT_EQ(5u, cacc.Size().x); - EXPECT_EQ(4u, cacc.Size().y); - EXPECT_EQ(data, cacc.data()); + CHECK_EQ(5u, cacc.Size().x); + CHECK_EQ(4u, cacc.Size().y); + CHECK_EQ(data, cacc.data()); } -TEST(ConstArrayView2, Iterators) +TEST_CASE("[ConstArrayView2] - Iterators") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, { 9.f, 10.f, 11.f, 12.f } }); auto acc = arr1.View(); - float cnt = 1.f; + double cnt = 1.0; for (const float& elem : acc) { - EXPECT_FLOAT_EQ(cnt, elem); - cnt += 1.f; + CHECK_EQ(doctest::Approx(cnt), elem); + cnt += 1.0; } } -TEST(ConstArrayView2, ForEach) +TEST_CASE("[ConstArrayView2] - ForEach") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -107,12 +117,12 @@ TEST(ConstArrayView2, ForEach) size_t i = 0; std::for_each(acc.begin(), acc.end(), [&](float val) { - EXPECT_FLOAT_EQ(acc[i], val); + CHECK_EQ(doctest::Approx(static_cast(acc[i])), val); ++i; }); } -TEST(ConstArrayView2, ForEachIndex) +TEST_CASE("[ConstArrayView2] - ForEachIndex") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -120,12 +130,12 @@ TEST(ConstArrayView2, ForEachIndex) auto acc = arr1.View(); ForEachIndex(acc.Size(), [&](size_t i, size_t j) { - size_t idx = i + (4 * j) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), acc(i, j)); + const size_t idx = i + (4 * j) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), acc(i, j)); }); } -TEST(ConstArrayView2, ParallelForEachIndex) +TEST_CASE("[ConstArrayView2] - ParallelForEachIndex") { Array2 arr1({ { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -133,7 +143,7 @@ TEST(ConstArrayView2, ParallelForEachIndex) auto acc = arr1.View(); ParallelForEachIndex(acc.Size(), [&](size_t i, size_t j) { - size_t idx = i + (4 * j) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), acc(i, j)); + const size_t idx = i + (4 * j) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), acc(i, j)); }); } \ No newline at end of file diff --git a/Tests/UnitTests/ArrayView3Tests.cpp b/Tests/UnitTests/ArrayView3Tests.cpp index 1fa5b8e518..d13888d88c 100644 --- a/Tests/UnitTests/ArrayView3Tests.cpp +++ b/Tests/UnitTests/ArrayView3Tests.cpp @@ -1,11 +1,21 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include #include using namespace CubbyFlow; -TEST(ArrayView3, Constructors) +TEST_CASE("[ArrayView3] - Constructors") { double data[60]; for (int i = 0; i < 60; ++i) @@ -15,13 +25,13 @@ TEST(ArrayView3, Constructors) ArrayView3 acc(data, Vector3UZ(5, 4, 3)); - EXPECT_EQ(5u, acc.Size().x); - EXPECT_EQ(4u, acc.Size().y); - EXPECT_EQ(3u, acc.Size().z); - EXPECT_EQ(data, acc.data()); + CHECK_EQ(5u, acc.Size().x); + CHECK_EQ(4u, acc.Size().y); + CHECK_EQ(3u, acc.Size().z); + CHECK_EQ(data, acc.data()); } -TEST(ArrayView3, Iterators) +TEST_CASE("[ArrayView3] - Iterators") { Array3 arr1({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -31,22 +41,22 @@ TEST(ArrayView3, Iterators) { 21.f, 22.f, 23.f, 24.f } } }); auto acc = arr1.View(); - float cnt = 1.f; + double cnt = 1.0; for (float& elem : acc) { - EXPECT_FLOAT_EQ(cnt, elem); - cnt += 1.f; + CHECK_EQ(doctest::Approx(cnt), elem); + cnt += 1.0; } - cnt = 1.f; + cnt = 1.0; for (const float& elem : acc) { - EXPECT_FLOAT_EQ(cnt, elem); - cnt += 1.f; + CHECK_EQ(doctest::Approx(cnt), elem); + cnt += 1.0; } } -TEST(ArrayView3, ForEachIndex) +TEST_CASE("[ArrayView3] - ForEachIndex") { Array3 arr1({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -57,12 +67,12 @@ TEST(ArrayView3, ForEachIndex) auto acc = arr1.View(); ForEachIndex(acc.Size(), [&](size_t i, size_t j, size_t k) { - size_t idx = i + (4 * (j + 3 * k)) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), acc(i, j, k)); + const size_t idx = i + (4 * (j + 3 * k)) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), acc(i, j, k)); }); } -TEST(ArrayView3, ParallelForEachIndex) +TEST_CASE("[ArrayView3] - ParallelForEachIndex") { Array3 arr1({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -73,12 +83,12 @@ TEST(ArrayView3, ParallelForEachIndex) auto acc = arr1.View(); ParallelForEachIndex(acc.Size(), [&](size_t i, size_t j, size_t k) { - size_t idx = i + (4 * (j + 3 * k)) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), acc(i, j, k)); + const size_t idx = i + (4 * (j + 3 * k)) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), acc(i, j, k)); }); } -TEST(ConstArrayView3, Constructors) +TEST_CASE("[ConstArrayView3] - Constructors") { double data[60]; for (int i = 0; i < 60; ++i) @@ -87,16 +97,16 @@ TEST(ConstArrayView3, Constructors) } // Construct with ArrayView3 - ArrayView3 acc(data, Vector3UZ(5, 4, 3)); - ConstArrayView3 cacc(acc); + const ArrayView3 acc(data, Vector3UZ(5, 4, 3)); + const ConstArrayView3 cacc(acc); - EXPECT_EQ(5u, cacc.Size().x); - EXPECT_EQ(4u, cacc.Size().y); - EXPECT_EQ(3u, cacc.Size().z); - EXPECT_EQ(data, cacc.data()); + CHECK_EQ(5u, cacc.Size().x); + CHECK_EQ(4u, cacc.Size().y); + CHECK_EQ(3u, cacc.Size().z); + CHECK_EQ(data, cacc.data()); } -TEST(ConstArrayView3, Iterators) +TEST_CASE("[ConstArrayView3] - Iterators") { Array3 arr1({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -106,15 +116,15 @@ TEST(ConstArrayView3, Iterators) { 21.f, 22.f, 23.f, 24.f } } }); auto acc = arr1.View(); - float cnt = 1.f; + double cnt = 1.0; for (const float& elem : acc) { - EXPECT_FLOAT_EQ(cnt, elem); - cnt += 1.f; + CHECK_EQ(doctest::Approx(cnt), elem); + cnt += 1.0; } } -TEST(ConstArrayView3, ForEachIndex) +TEST_CASE("[ConstArrayView3] - ForEachIndex") { Array3 arr1({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -125,12 +135,12 @@ TEST(ConstArrayView3, ForEachIndex) auto acc = arr1.View(); ForEachIndex(acc.Size(), [&](size_t i, size_t j, size_t k) { - size_t idx = i + (4 * (j + 3 * k)) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), acc(i, j, k)); + const size_t idx = i + (4 * (j + 3 * k)) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), acc(i, j, k)); }); } -TEST(ConstArrayView3, ParallelForEachIndex) +TEST_CASE("[ConstArrayView3] - ParallelForEachIndex") { Array3 arr1({ { { 1.f, 2.f, 3.f, 4.f }, { 5.f, 6.f, 7.f, 8.f }, @@ -141,7 +151,7 @@ TEST(ConstArrayView3, ParallelForEachIndex) auto acc = arr1.View(); ParallelForEachIndex(acc.Size(), [&](size_t i, size_t j, size_t k) { - size_t idx = i + (4 * (j + 3 * k)) + 1; - EXPECT_FLOAT_EQ(static_cast(idx), acc(i, j, k)); + const size_t idx = i + (4 * (j + 3 * k)) + 1; + CHECK_EQ(doctest::Approx(static_cast(idx)), acc(i, j, k)); }); } \ No newline at end of file From 30a6a5cd0e323eaf60946eacdf5fcdd13d1c36d1 Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Thu, 23 Dec 2021 00:03:29 +0900 Subject: [PATCH 10/11] feat(doctest): Replace library 'googletest' with 'doctest' --- Tests/UnitTests/BLASTests.cpp | 82 ++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/Tests/UnitTests/BLASTests.cpp b/Tests/UnitTests/BLASTests.cpp index 8485095d17..4a2764f0c9 100644 --- a/Tests/UnitTests/BLASTests.cpp +++ b/Tests/UnitTests/BLASTests.cpp @@ -1,26 +1,36 @@ -#include "gtest/gtest.h" +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + +#include "doctest_proxy.hpp" #include #include using namespace CubbyFlow; -TEST(BLAS, Set) +TEST_CASE("[BLAS] - Set") { Vector3D vec; BLAS::Set(3.14, &vec); - EXPECT_DOUBLE_EQ(3.14, vec.x); - EXPECT_DOUBLE_EQ(3.14, vec.y); - EXPECT_DOUBLE_EQ(3.14, vec.z); + CHECK_EQ(doctest::Approx(3.14), vec.x); + CHECK_EQ(doctest::Approx(3.14), vec.y); + CHECK_EQ(doctest::Approx(3.14), vec.z); Vector3D vec2(5.1, 3.7, 8.2); BLAS::Set(vec2, &vec); - EXPECT_DOUBLE_EQ(5.1, vec.x); - EXPECT_DOUBLE_EQ(3.7, vec.y); - EXPECT_DOUBLE_EQ(8.2, vec.z); + CHECK_EQ(doctest::Approx(5.1), vec.x); + CHECK_EQ(doctest::Approx(3.7), vec.y); + CHECK_EQ(doctest::Approx(8.2), vec.z); Matrix3x3D mat; @@ -29,70 +39,70 @@ TEST(BLAS, Set) for (int i = 0; i < 9; ++i) { double elem = mat[i]; - EXPECT_DOUBLE_EQ(0.414, elem); + CHECK_EQ(doctest::Approx(0.414), elem); } Matrix3x3D mat2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); BLAS::Set(mat2, &mat); for (int i = 0; i < 9; ++i) { - EXPECT_DOUBLE_EQ(static_cast(i + 1), mat[i]); + CHECK_EQ(doctest::Approx(static_cast(i + 1)), mat[i]); } } -TEST(BLAS, Dot) +TEST_CASE("[BLAS] - Dot") { - Vector3D vec(1.0, 2.0, 3.0), vec2(4.0, 5.0, 6.0); - double result = BLAS::Dot(vec, vec2); - EXPECT_DOUBLE_EQ(32.0, result); + constexpr Vector3D vec(1.0, 2.0, 3.0), vec2(4.0, 5.0, 6.0); + const double result = BLAS::Dot(vec, vec2); + CHECK_EQ(doctest::Approx(32.0), result); } -TEST(BLAS, AXPlusY) +TEST_CASE("[BLAS] - AXPlusY") { Vector3D result; BLAS::AXPlusY(2.5, Vector3D(1, 2, 3), Vector3D(4, 5, 6), &result); - EXPECT_DOUBLE_EQ(6.5, result.x); - EXPECT_DOUBLE_EQ(10.0, result.y); - EXPECT_DOUBLE_EQ(13.5, result.z); + CHECK_EQ(doctest::Approx(6.5), result.x); + CHECK_EQ(doctest::Approx(10.0), result.y); + CHECK_EQ(doctest::Approx(13.5), result.z); } -TEST(BLAS, MVM) +TEST_CASE("[BLAS] - MVM") { - Matrix3x3D mat(1, 2, 3, 4, 5, 6, 7, 8, 9); + constexpr Matrix3x3D mat(1, 2, 3, 4, 5, 6, 7, 8, 9); Vector3D result; BLAS::MVM(mat, Vector3D(1, 2, 3), &result); - EXPECT_DOUBLE_EQ(14.0, result.x); - EXPECT_DOUBLE_EQ(32.0, result.y); - EXPECT_DOUBLE_EQ(50.0, result.z); + CHECK_EQ(doctest::Approx(14.0), result.x); + CHECK_EQ(doctest::Approx(32.0), result.y); + CHECK_EQ(doctest::Approx(50.0), result.z); } -TEST(BLAS, Residual) +TEST_CASE("[BLAS] - Residual") { - Matrix3x3D mat(1, 2, 3, 4, 5, 6, 7, 8, 9); + constexpr Matrix3x3D mat(1, 2, 3, 4, 5, 6, 7, 8, 9); Vector3D result; BLAS::Residual(mat, Vector3D(1, 2, 3), Vector3D(4, 5, 6), &result); - EXPECT_DOUBLE_EQ(-10.0, result.x); - EXPECT_DOUBLE_EQ(-27.0, result.y); - EXPECT_DOUBLE_EQ(-44.0, result.z); + CHECK_EQ(doctest::Approx(-10.0), result.x); + CHECK_EQ(doctest::Approx(-27.0), result.y); + CHECK_EQ(doctest::Approx(-44.0), result.z); } -TEST(BLAS, L2Norm) +TEST_CASE("[BLAS] - L2Norm") { - Vector3D vec(-1.0, 2.0, -3.0); - double result = BLAS::L2Norm(vec); - EXPECT_DOUBLE_EQ(std::sqrt(14.0), result); + constexpr Vector3D vec(-1.0, 2.0, -3.0); + const double result = BLAS::L2Norm(vec); + CHECK_EQ(doctest::Approx(std::sqrt(14.0)), result); } -TEST(BLAS, LInfNorm) +TEST_CASE("[BLAS] - LInfNorm") { - Vector3D vec(-1.0, 2.0, -3.0); - double result = BLAS::LInfNorm(vec); - EXPECT_DOUBLE_EQ(3.0, result); + constexpr Vector3D vec(-1.0, 2.0, -3.0); + const double result = BLAS::LInfNorm(vec); + CHECK_EQ(doctest::Approx(3.0), result); } \ No newline at end of file From 886f9478028c79942798ae2aec290fcfc2246d43 Mon Sep 17 00:00:00 2001 From: Chris Ohk Date: Thu, 23 Dec 2021 09:11:16 +0900 Subject: [PATCH 11/11] feat(doctest): Replace library 'googletest' with 'doctest' --- Tests/UnitTests/BoundingBox2Tests.cpp | 176 +++++++++++---------- Tests/UnitTests/BoundingBox3Tests.cpp | 216 ++++++++++++++------------ Tests/UnitTests/UnitTestsUtils.hpp | 14 +- 3 files changed, 216 insertions(+), 190 deletions(-) diff --git a/Tests/UnitTests/BoundingBox2Tests.cpp b/Tests/UnitTests/BoundingBox2Tests.cpp index 8ed6959995..80e5cce985 100644 --- a/Tests/UnitTests/BoundingBox2Tests.cpp +++ b/Tests/UnitTests/BoundingBox2Tests.cpp @@ -1,64 +1,76 @@ +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + #include "UnitTestsUtils.hpp" -#include "gtest/gtest.h" +#include "doctest_proxy.hpp" #include using namespace CubbyFlow; -TEST(BoundingBox2, Constructors) +TEST_CASE("[BoundingBox2] - Constructors") { { BoundingBox2D box; - EXPECT_DOUBLE_EQ(std::numeric_limits::max(), box.lowerCorner.x); - EXPECT_DOUBLE_EQ(std::numeric_limits::max(), box.lowerCorner.y); + CHECK_EQ(doctest::Approx(std::numeric_limits::max()), + box.lowerCorner.x); + CHECK_EQ(doctest::Approx(std::numeric_limits::max()), + box.lowerCorner.y); - EXPECT_DOUBLE_EQ(-std::numeric_limits::max(), - box.upperCorner.x); - EXPECT_DOUBLE_EQ(-std::numeric_limits::max(), - box.upperCorner.y); + CHECK_EQ(doctest::Approx(-std::numeric_limits::max()), + box.upperCorner.x); + CHECK_EQ(doctest::Approx(-std::numeric_limits::max()), + box.upperCorner.y); } { BoundingBox2D box(Vector2D(-2.0, 3.0), Vector2D(4.0, -2.0)); - EXPECT_DOUBLE_EQ(-2.0, box.lowerCorner.x); - EXPECT_DOUBLE_EQ(-2.0, box.lowerCorner.y); + CHECK_EQ(doctest::Approx(-2.0), box.lowerCorner.x); + CHECK_EQ(doctest::Approx(-2.0), box.lowerCorner.y); - EXPECT_DOUBLE_EQ(4.0, box.upperCorner.x); - EXPECT_DOUBLE_EQ(3.0, box.upperCorner.y); + CHECK_EQ(doctest::Approx(4.0), box.upperCorner.x); + CHECK_EQ(doctest::Approx(3.0), box.upperCorner.y); } { BoundingBox2D box(Vector2D(-2.0, 3.0), Vector2D(4.0, -2.0)); BoundingBox2D box2(box); - EXPECT_DOUBLE_EQ(-2.0, box2.lowerCorner.x); - EXPECT_DOUBLE_EQ(-2.0, box2.lowerCorner.y); + CHECK_EQ(doctest::Approx(-2.0), box2.lowerCorner.x); + CHECK_EQ(doctest::Approx(-2.0), box2.lowerCorner.y); - EXPECT_DOUBLE_EQ(4.0, box2.upperCorner.x); - EXPECT_DOUBLE_EQ(3.0, box2.upperCorner.y); + CHECK_EQ(doctest::Approx(4.0), box2.upperCorner.x); + CHECK_EQ(doctest::Approx(3.0), box2.upperCorner.y); } } -TEST(BoundingBox2, BasicGetters) +TEST_CASE("[BoundingBox2] - BasicGetters") { BoundingBox2D box(Vector2D(-2.0, 3.0), Vector2D(4.0, -2.0)); - EXPECT_DOUBLE_EQ(6.0, box.Width()); - EXPECT_DOUBLE_EQ(5.0, box.Height()); - EXPECT_DOUBLE_EQ(6.0, box.Length(0)); - EXPECT_DOUBLE_EQ(5.0, box.Length(1)); + CHECK_EQ(doctest::Approx(6.0), box.Width()); + CHECK_EQ(doctest::Approx(5.0), box.Height()); + CHECK_EQ(doctest::Approx(6.0), box.Length(0)); + CHECK_EQ(doctest::Approx(5.0), box.Length(1)); } -TEST(BoundingBox2, Overlaps) +TEST_CASE("[BoundingBox2] - Overlaps") { // x-axis is not overlapping { BoundingBox2D box1(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); BoundingBox2D box2(Vector2D(5.0, 1.0), Vector2D(8.0, 2.0)); - EXPECT_FALSE(box1.Overlaps(box2)); + CHECK_FALSE(box1.Overlaps(box2)); } // y-axis is not overlapping @@ -66,7 +78,7 @@ TEST(BoundingBox2, Overlaps) BoundingBox2D box1(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); BoundingBox2D box2(Vector2D(3.0, 4.0), Vector2D(8.0, 6.0)); - EXPECT_FALSE(box1.Overlaps(box2)); + CHECK_FALSE(box1.Overlaps(box2)); } // overlapping @@ -74,18 +86,18 @@ TEST(BoundingBox2, Overlaps) BoundingBox2D box1(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); BoundingBox2D box2(Vector2D(3.0, 1.0), Vector2D(8.0, 2.0)); - EXPECT_TRUE(box1.Overlaps(box2)); + CHECK(box1.Overlaps(box2)); } } -TEST(BoundingBox2, Contains) +TEST_CASE("[BoundingBox2] - Contains") { // Not containing (x-axis is out) { BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); Vector2D point(-3.0, 0.0); - EXPECT_FALSE(box.Contains(point)); + CHECK_FALSE(box.Contains(point)); } // Not containing (y-axis is out) @@ -93,7 +105,7 @@ TEST(BoundingBox2, Contains) BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); Vector2D point(2.0, 3.5); - EXPECT_FALSE(box.Contains(point)); + CHECK_FALSE(box.Contains(point)); } // Containing @@ -101,80 +113,80 @@ TEST(BoundingBox2, Contains) BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); Vector2D point(2.0, 0.0); - EXPECT_TRUE(box.Contains(point)); + CHECK(box.Contains(point)); } } -TEST(BoundingBox2, Intersects) +TEST_CASE("[BoundingBox2] - Intersects") { BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); Ray2D ray1(Vector2D(-3, 0), Vector2D(2, 1).Normalized()); - EXPECT_TRUE(box.Intersects(ray1)); + CHECK(box.Intersects(ray1)); Ray2D ray2(Vector2D(3, -1), Vector2D(-1, 2).Normalized()); - EXPECT_TRUE(box.Intersects(ray2)); + CHECK(box.Intersects(ray2)); Ray2D ray3(Vector2D(1, -5), Vector2D(2, 1).Normalized()); - EXPECT_FALSE(box.Intersects(ray3)); + CHECK_FALSE(box.Intersects(ray3)); } -TEST(BoundingBox2, ClosestIntersection) +TEST_CASE("[BoundingBox2] - ClosestIntersection") { BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(1.0, 0.0)); Ray2D ray1(Vector2D(-4, -3), Vector2D(1, 1).Normalized()); BoundingBoxRayIntersectionD intersection1 = box.ClosestIntersection(ray1); - EXPECT_TRUE(intersection1.isIntersecting); - EXPECT_DOUBLE_EQ(Vector2D(2, 2).Length(), intersection1.near); - EXPECT_DOUBLE_EQ(Vector2D(3, 3).Length(), intersection1.far); + CHECK(intersection1.isIntersecting); + CHECK_EQ(doctest::Approx(Vector2D(2, 2).Length()), intersection1.near); + CHECK_EQ(doctest::Approx(Vector2D(3, 3).Length()), intersection1.far); Ray2D ray2(Vector2D(0, -1), Vector2D(-2, 1).Normalized()); BoundingBoxRayIntersectionD intersection2 = box.ClosestIntersection(ray2); - EXPECT_TRUE(intersection2.isIntersecting); - EXPECT_DOUBLE_EQ(Vector2D(2, 1).Length(), intersection2.near); + CHECK(intersection2.isIntersecting); + CHECK_EQ(doctest::Approx(Vector2D(2, 1).Length()), intersection2.near); } -TEST(BoundingBox2, MidPoint) +TEST_CASE("[BoundingBox2] - MidPoint") { - BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); - Vector2D midPoint = box.MidPoint(); + const BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); + const Vector2D midPoint = box.MidPoint(); - EXPECT_DOUBLE_EQ(1.0, midPoint.x); - EXPECT_DOUBLE_EQ(0.5, midPoint.y); + CHECK_EQ(doctest::Approx(1.0), midPoint.x); + CHECK_EQ(doctest::Approx(0.5), midPoint.y); } -TEST(BoundingBox2, DiagonalLength) +TEST_CASE("[BoundingBox2] - DiagonalLength") { - BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); - double diagLen = box.DiagonalLength(); + const BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); + const double diagLen = box.DiagonalLength(); - EXPECT_DOUBLE_EQ(std::sqrt(6.0 * 6.0 + 5.0 * 5.0), diagLen); + CHECK_EQ(doctest::Approx(std::sqrt(6.0 * 6.0 + 5.0 * 5.0)), diagLen); } -TEST(BoundingBox2, DiagonalLengthSquared) +TEST_CASE("[BoundingBox2] - DiagonalLengthSquared") { - BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); - double diagLenSqr = box.DiagonalLengthSquared(); + const BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); + const double diagLenSqr = box.DiagonalLengthSquared(); - EXPECT_DOUBLE_EQ(6.0 * 6.0 + 5.0 * 5.0, diagLenSqr); + CHECK_EQ(doctest::Approx(6.0 * 6.0 + 5.0 * 5.0), diagLenSqr); } -TEST(BoundingBox2, Reset) +TEST_CASE("[BoundingBox2] - Reset") { BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); box.Reset(); - static const double maxDouble = std::numeric_limits::max(); + static constexpr double maxDouble = std::numeric_limits::max(); - EXPECT_DOUBLE_EQ(maxDouble, box.lowerCorner.x); - EXPECT_DOUBLE_EQ(maxDouble, box.lowerCorner.y); + CHECK_EQ(doctest::Approx(maxDouble), box.lowerCorner.x); + CHECK_EQ(doctest::Approx(maxDouble), box.lowerCorner.y); - EXPECT_DOUBLE_EQ(-maxDouble, box.upperCorner.x); - EXPECT_DOUBLE_EQ(-maxDouble, box.upperCorner.y); + CHECK_EQ(doctest::Approx(-maxDouble), box.upperCorner.x); + CHECK_EQ(doctest::Approx(-maxDouble), box.upperCorner.y); } -TEST(BoundingBox2, Merge) +TEST_CASE("[BoundingBox2] - Merge") { // Merge with point { @@ -183,11 +195,11 @@ TEST(BoundingBox2, Merge) box.Merge(point); - EXPECT_DOUBLE_EQ(-2.0, box.lowerCorner.x); - EXPECT_DOUBLE_EQ(-2.0, box.lowerCorner.y); + CHECK_EQ(doctest::Approx(-2.0), box.lowerCorner.x); + CHECK_EQ(doctest::Approx(-2.0), box.lowerCorner.y); - EXPECT_DOUBLE_EQ(5.0, box.upperCorner.x); - EXPECT_DOUBLE_EQ(3.0, box.upperCorner.y); + CHECK_EQ(doctest::Approx(5.0), box.upperCorner.x); + CHECK_EQ(doctest::Approx(3.0), box.upperCorner.y); } // Merge with other box @@ -197,46 +209,46 @@ TEST(BoundingBox2, Merge) box1.Merge(box2); - EXPECT_DOUBLE_EQ(-2.0, box1.lowerCorner.x); - EXPECT_DOUBLE_EQ(-2.0, box1.lowerCorner.y); + CHECK_EQ(doctest::Approx(-2.0), box1.lowerCorner.x); + CHECK_EQ(doctest::Approx(-2.0), box1.lowerCorner.y); - EXPECT_DOUBLE_EQ(8.0, box1.upperCorner.x); - EXPECT_DOUBLE_EQ(3.0, box1.upperCorner.y); + CHECK_EQ(doctest::Approx(8.0), box1.upperCorner.x); + CHECK_EQ(doctest::Approx(3.0), box1.upperCorner.y); } } -TEST(BoundingBox2, Expand) +TEST_CASE("[BoundingBox2] - Expand") { BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); box.Expand(3.0); - EXPECT_DOUBLE_EQ(-5.0, box.lowerCorner.x); - EXPECT_DOUBLE_EQ(-5.0, box.lowerCorner.y); + CHECK_EQ(doctest::Approx(-5.0), box.lowerCorner.x); + CHECK_EQ(doctest::Approx(-5.0), box.lowerCorner.y); - EXPECT_DOUBLE_EQ(7.0, box.upperCorner.x); - EXPECT_DOUBLE_EQ(6.0, box.upperCorner.y); + CHECK_EQ(doctest::Approx(7.0), box.upperCorner.x); + CHECK_EQ(doctest::Approx(6.0), box.upperCorner.y); } -TEST(BoundingBox2, Corner) +TEST_CASE("[BoundingBox2] - Corner") { BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); - EXPECT_VECTOR2_EQ(Vector2D(-2.0, -2.0), box.Corner(0)); - EXPECT_VECTOR2_EQ(Vector2D(4.0, -2.0), box.Corner(1)); - EXPECT_VECTOR2_EQ(Vector2D(-2.0, 3.0), box.Corner(2)); - EXPECT_VECTOR2_EQ(Vector2D(4.0, 3.0), box.Corner(3)); + CHECK_VECTOR2_EQ(Vector2D(-2.0, -2.0), box.Corner(0)) + CHECK_VECTOR2_EQ(Vector2D(4.0, -2.0), box.Corner(1)) + CHECK_VECTOR2_EQ(Vector2D(-2.0, 3.0), box.Corner(2)) + CHECK_VECTOR2_EQ(Vector2D(4.0, 3.0), box.Corner(3)) } -TEST(BoundingBox2, IsEmpty) +TEST_CASE("[BoundingBox2] - IsEmpty") { BoundingBox2D box(Vector2D(-2.0, -2.0), Vector2D(4.0, 3.0)); - EXPECT_FALSE(box.IsEmpty()); + CHECK_FALSE(box.IsEmpty()); box.lowerCorner = Vector2D(5.0, 1.0); - EXPECT_TRUE(box.IsEmpty()); + CHECK(box.IsEmpty()); box.lowerCorner = Vector2D(2.0, 4.0); - EXPECT_TRUE(box.IsEmpty()); + CHECK(box.IsEmpty()); box.lowerCorner = Vector2D(4.0, 1.0); - EXPECT_TRUE(box.IsEmpty()); + CHECK(box.IsEmpty()); } \ No newline at end of file diff --git a/Tests/UnitTests/BoundingBox3Tests.cpp b/Tests/UnitTests/BoundingBox3Tests.cpp index 0696fff7f2..a0652f9dc7 100644 --- a/Tests/UnitTests/BoundingBox3Tests.cpp +++ b/Tests/UnitTests/BoundingBox3Tests.cpp @@ -1,73 +1,86 @@ +// This code is based on Jet framework. +// Copyright (c) 2018 Doyub Kim +// CubbyFlow is voxel-based fluid simulation engine for computer games. +// Copyright (c) 2020 CubbyFlow Team +// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo +// AI Part: Dongheon Cho, Minseo Kim +// We are making my contributions/submissions to this project solely in our +// personal capacity and are not conveying any rights to any intellectual +// property of any third parties. + #include "UnitTestsUtils.hpp" -#include "gtest/gtest.h" +#include "doctest_proxy.hpp" #include using namespace CubbyFlow; -TEST(BoundingBox3, Constructors) +TEST_CASE("[BoundingBox3] - Constructors") { { BoundingBox3D box; - EXPECT_DOUBLE_EQ(std::numeric_limits::max(), box.lowerCorner.x); - EXPECT_DOUBLE_EQ(std::numeric_limits::max(), box.lowerCorner.y); - EXPECT_DOUBLE_EQ(std::numeric_limits::max(), box.lowerCorner.z); - - EXPECT_DOUBLE_EQ(-std::numeric_limits::max(), - box.upperCorner.x); - EXPECT_DOUBLE_EQ(-std::numeric_limits::max(), - box.upperCorner.y); - EXPECT_DOUBLE_EQ(-std::numeric_limits::max(), - box.upperCorner.z); + CHECK_EQ(doctest::Approx(std::numeric_limits::max()), + box.lowerCorner.x); + CHECK_EQ(doctest::Approx(std::numeric_limits::max()), + box.lowerCorner.y); + CHECK_EQ(doctest::Approx(std::numeric_limits::max()), + box.lowerCorner.z); + + CHECK_EQ(doctest::Approx(-std::numeric_limits::max()), + box.upperCorner.x); + CHECK_EQ(doctest::Approx(-std::numeric_limits::max()), + box.upperCorner.y); + CHECK_EQ(doctest::Approx(-std::numeric_limits::max()), + box.upperCorner.z); } { BoundingBox3D box(Vector3D(-2.0, 3.0, 5.0), Vector3D(4.0, -2.0, 1.0)); - EXPECT_DOUBLE_EQ(-2.0, box.lowerCorner.x); - EXPECT_DOUBLE_EQ(-2.0, box.lowerCorner.y); - EXPECT_DOUBLE_EQ(1.0, box.lowerCorner.z); + CHECK_EQ(doctest::Approx(-2.0), box.lowerCorner.x); + CHECK_EQ(doctest::Approx(-2.0), box.lowerCorner.y); + CHECK_EQ(doctest::Approx(1.0), box.lowerCorner.z); - EXPECT_DOUBLE_EQ(4.0, box.upperCorner.x); - EXPECT_DOUBLE_EQ(3.0, box.upperCorner.y); - EXPECT_DOUBLE_EQ(5.0, box.upperCorner.z); + CHECK_EQ(doctest::Approx(4.0), box.upperCorner.x); + CHECK_EQ(doctest::Approx(3.0), box.upperCorner.y); + CHECK_EQ(doctest::Approx(5.0), box.upperCorner.z); } { BoundingBox3D box(Vector3D(-2.0, 3.0, 5.0), Vector3D(4.0, -2.0, 1.0)); BoundingBox3D box2(box); - EXPECT_DOUBLE_EQ(-2.0, box2.lowerCorner.x); - EXPECT_DOUBLE_EQ(-2.0, box2.lowerCorner.y); - EXPECT_DOUBLE_EQ(1.0, box2.lowerCorner.z); + CHECK_EQ(doctest::Approx(-2.0), box2.lowerCorner.x); + CHECK_EQ(doctest::Approx(-2.0), box2.lowerCorner.y); + CHECK_EQ(doctest::Approx(1.0), box2.lowerCorner.z); - EXPECT_DOUBLE_EQ(4.0, box2.upperCorner.x); - EXPECT_DOUBLE_EQ(3.0, box2.upperCorner.y); - EXPECT_DOUBLE_EQ(5.0, box2.upperCorner.z); + CHECK_EQ(doctest::Approx(4.0), box2.upperCorner.x); + CHECK_EQ(doctest::Approx(3.0), box2.upperCorner.y); + CHECK_EQ(doctest::Approx(5.0), box2.upperCorner.z); } } -TEST(BoundingBox3, BasicGetters) +TEST_CASE("[BoundingBox3] - BasicGetters") { BoundingBox3D box(Vector3D(-2.0, 3.0, 5.0), Vector3D(4.0, -2.0, 1.0)); - EXPECT_DOUBLE_EQ(6.0, box.Width()); - EXPECT_DOUBLE_EQ(5.0, box.Height()); - EXPECT_DOUBLE_EQ(4.0, box.Depth()); - EXPECT_DOUBLE_EQ(6.0, box.Length(0)); - EXPECT_DOUBLE_EQ(5.0, box.Length(1)); - EXPECT_DOUBLE_EQ(4.0, box.Length(2)); + CHECK_EQ(doctest::Approx(6.0), box.Width()); + CHECK_EQ(doctest::Approx(5.0), box.Height()); + CHECK_EQ(doctest::Approx(4.0), box.Depth()); + CHECK_EQ(doctest::Approx(6.0), box.Length(0)); + CHECK_EQ(doctest::Approx(5.0), box.Length(1)); + CHECK_EQ(doctest::Approx(4.0), box.Length(2)); } -TEST(BoundingBox3, Overlaps) +TEST_CASE("[BoundingBox3] - Overlaps") { // x-axis is not overlapping { BoundingBox3D box1(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); BoundingBox3D box2(Vector3D(5.0, 1.0, 3.0), Vector3D(8.0, 2.0, 4.0)); - EXPECT_FALSE(box1.Overlaps(box2)); + CHECK_FALSE(box1.Overlaps(box2)); } // y-axis is not overlapping @@ -75,7 +88,7 @@ TEST(BoundingBox3, Overlaps) BoundingBox3D box1(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); BoundingBox3D box2(Vector3D(3.0, 4.0, 3.0), Vector3D(8.0, 6.0, 4.0)); - EXPECT_FALSE(box1.Overlaps(box2)); + CHECK_FALSE(box1.Overlaps(box2)); } // z-axis is not overlapping @@ -83,7 +96,7 @@ TEST(BoundingBox3, Overlaps) BoundingBox3D box1(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); BoundingBox3D box2(Vector3D(3.0, 1.0, 6.0), Vector3D(8.0, 2.0, 9.0)); - EXPECT_FALSE(box1.Overlaps(box2)); + CHECK_FALSE(box1.Overlaps(box2)); } // overlapping @@ -91,18 +104,18 @@ TEST(BoundingBox3, Overlaps) BoundingBox3D box1(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); BoundingBox3D box2(Vector3D(3.0, 1.0, 3.0), Vector3D(8.0, 2.0, 7.0)); - EXPECT_TRUE(box1.Overlaps(box2)); + CHECK(box1.Overlaps(box2)); } } -TEST(BoundingBox3, Contains) +TEST_CASE("[BoundingBox3] - Contains") { // Not containing (x-axis is out) { BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); Vector3D point(-3.0, 0.0, 4.0); - EXPECT_FALSE(box.Contains(point)); + CHECK_FALSE(box.Contains(point)); } // Not containing (y-axis is out) @@ -110,7 +123,7 @@ TEST(BoundingBox3, Contains) BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); Vector3D point(2.0, 3.5, 4.0); - EXPECT_FALSE(box.Contains(point)); + CHECK_FALSE(box.Contains(point)); } // Not containing (z-axis is out) @@ -118,7 +131,7 @@ TEST(BoundingBox3, Contains) BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); Vector3D point(2.0, 0.0, 0.0); - EXPECT_FALSE(box.Contains(point)); + CHECK_FALSE(box.Contains(point)); } // Containing @@ -126,83 +139,84 @@ TEST(BoundingBox3, Contains) BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); Vector3D point(2.0, 0.0, 4.0); - EXPECT_TRUE(box.Contains(point)); + CHECK(box.Contains(point)); } } -TEST(BoundingBox3, Intersects) +TEST_CASE("[BoundingBox3] - Intersects") { BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); Ray3D ray1(Vector3D(-3, 0, 2), Vector3D(2, 1, 1).Normalized()); - EXPECT_TRUE(box.Intersects(ray1)); + CHECK(box.Intersects(ray1)); Ray3D ray2(Vector3D(3, -1, 3), Vector3D(-1, 2, -3).Normalized()); - EXPECT_TRUE(box.Intersects(ray2)); + CHECK(box.Intersects(ray2)); Ray3D ray3(Vector3D(1, -5, 1), Vector3D(2, 1, 2).Normalized()); - EXPECT_FALSE(box.Intersects(ray3)); + CHECK_FALSE(box.Intersects(ray3)); } -TEST(BoundingBox3, ClosestIntersection) +TEST_CASE("[BoundingBox3] - ClosestIntersection") { BoundingBox3D box(Vector3D(-2.0, -2.0, -1.0), Vector3D(1.0, 0.0, 1.0)); Ray3D ray1(Vector3D(-4, -3, 0), Vector3D(1, 1, 0).Normalized()); BoundingBoxRayIntersectionD intersection1 = box.ClosestIntersection(ray1); - EXPECT_TRUE(intersection1.isIntersecting); - EXPECT_DOUBLE_EQ(Vector3D(2, 2, 0).Length(), intersection1.near); - EXPECT_DOUBLE_EQ(Vector3D(3, 3, 0).Length(), intersection1.far); + CHECK(intersection1.isIntersecting); + CHECK_EQ(doctest::Approx(Vector3D(2, 2, 0).Length()), intersection1.near); + CHECK_EQ(doctest::Approx(Vector3D(3, 3, 0).Length()), intersection1.far); Ray3D ray2(Vector3D(0, -1, 0), Vector3D(-2, 1, 1).Normalized()); BoundingBoxRayIntersectionD intersection2 = box.ClosestIntersection(ray2); - EXPECT_TRUE(intersection2.isIntersecting); - EXPECT_DOUBLE_EQ(Vector3D(2, 1, 1).Length(), intersection2.near); + CHECK(intersection2.isIntersecting); + CHECK_EQ(doctest::Approx(Vector3D(2, 1, 1).Length()), intersection2.near); } -TEST(BoundingBox3, MidPoint) +TEST_CASE("[BoundingBox3] - MidPoint") { BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); Vector3D midPoint = box.MidPoint(); - EXPECT_DOUBLE_EQ(1.0, midPoint.x); - EXPECT_DOUBLE_EQ(0.5, midPoint.y); - EXPECT_DOUBLE_EQ(3.0, midPoint.z); + CHECK_EQ(doctest::Approx(1.0), midPoint.x); + CHECK_EQ(doctest::Approx(0.5), midPoint.y); + CHECK_EQ(doctest::Approx(3.0), midPoint.z); } -TEST(BoundingBox3, DiagonalLength) +TEST_CASE("[BoundingBox3] - DiagonalLength") { BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); double diagLen = box.DiagonalLength(); - EXPECT_DOUBLE_EQ(std::sqrt(6.0 * 6.0 + 5.0 * 5.0 + 4.0 * 4.0), diagLen); + CHECK_EQ(doctest::Approx(std::sqrt(6.0 * 6.0 + 5.0 * 5.0 + 4.0 * 4.0)), + diagLen); } -TEST(BoundingBox3, DiagonalLengthSquared) +TEST_CASE("[BoundingBox3] - DiagonalLengthSquared") { BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); double diagLenSqr = box.DiagonalLengthSquared(); - EXPECT_DOUBLE_EQ(6.0 * 6.0 + 5.0 * 5.0 + 4.0 * 4.0, diagLenSqr); + CHECK_EQ(doctest::Approx(6.0 * 6.0 + 5.0 * 5.0 + 4.0 * 4.0), diagLenSqr); } -TEST(BoundingBox3, Reset) +TEST_CASE("[BoundingBox3] - Reset") { BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); box.Reset(); static const double maxDouble = std::numeric_limits::max(); - EXPECT_DOUBLE_EQ(maxDouble, box.lowerCorner.x); - EXPECT_DOUBLE_EQ(maxDouble, box.lowerCorner.y); - EXPECT_DOUBLE_EQ(maxDouble, box.lowerCorner.z); + CHECK_EQ(doctest::Approx(maxDouble), box.lowerCorner.x); + CHECK_EQ(doctest::Approx(maxDouble), box.lowerCorner.y); + CHECK_EQ(doctest::Approx(maxDouble), box.lowerCorner.z); - EXPECT_DOUBLE_EQ(-maxDouble, box.upperCorner.x); - EXPECT_DOUBLE_EQ(-maxDouble, box.upperCorner.y); - EXPECT_DOUBLE_EQ(-maxDouble, box.upperCorner.z); + CHECK_EQ(doctest::Approx(-maxDouble), box.upperCorner.x); + CHECK_EQ(doctest::Approx(-maxDouble), box.upperCorner.y); + CHECK_EQ(doctest::Approx(-maxDouble), box.upperCorner.z); } -TEST(BoundingBox3, Merge) +TEST_CASE("[BoundingBox3] - Merge") { // Merge with point { @@ -211,13 +225,13 @@ TEST(BoundingBox3, Merge) box.Merge(point); - EXPECT_DOUBLE_EQ(-2.0, box.lowerCorner.x); - EXPECT_DOUBLE_EQ(-2.0, box.lowerCorner.y); - EXPECT_DOUBLE_EQ(-1.0, box.lowerCorner.z); + CHECK_EQ(doctest::Approx(-2.0), box.lowerCorner.x); + CHECK_EQ(doctest::Approx(-2.0), box.lowerCorner.y); + CHECK_EQ(doctest::Approx(-1.0), box.lowerCorner.z); - EXPECT_DOUBLE_EQ(5.0, box.upperCorner.x); - EXPECT_DOUBLE_EQ(3.0, box.upperCorner.y); - EXPECT_DOUBLE_EQ(5.0, box.upperCorner.z); + CHECK_EQ(doctest::Approx(5.0), box.upperCorner.x); + CHECK_EQ(doctest::Approx(3.0), box.upperCorner.y); + CHECK_EQ(doctest::Approx(5.0), box.upperCorner.z); } // Merge with other box @@ -227,58 +241,58 @@ TEST(BoundingBox3, Merge) box1.Merge(box2); - EXPECT_DOUBLE_EQ(-2.0, box1.lowerCorner.x); - EXPECT_DOUBLE_EQ(-2.0, box1.lowerCorner.y); - EXPECT_DOUBLE_EQ(1.0, box1.lowerCorner.z); + CHECK_EQ(doctest::Approx(-2.0), box1.lowerCorner.x); + CHECK_EQ(doctest::Approx(-2.0), box1.lowerCorner.y); + CHECK_EQ(doctest::Approx(1.0), box1.lowerCorner.z); - EXPECT_DOUBLE_EQ(8.0, box1.upperCorner.x); - EXPECT_DOUBLE_EQ(3.0, box1.upperCorner.y); - EXPECT_DOUBLE_EQ(7.0, box1.upperCorner.z); + CHECK_EQ(doctest::Approx(8.0), box1.upperCorner.x); + CHECK_EQ(doctest::Approx(3.0), box1.upperCorner.y); + CHECK_EQ(doctest::Approx(7.0), box1.upperCorner.z); } } -TEST(BoundingBox3, Expand) +TEST_CASE("[BoundingBox3] - Expand") { BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); box.Expand(3.0); - EXPECT_DOUBLE_EQ(-5.0, box.lowerCorner.x); - EXPECT_DOUBLE_EQ(-5.0, box.lowerCorner.y); - EXPECT_DOUBLE_EQ(-2.0, box.lowerCorner.z); + CHECK_EQ(doctest::Approx(-5.0), box.lowerCorner.x); + CHECK_EQ(doctest::Approx(-5.0), box.lowerCorner.y); + CHECK_EQ(doctest::Approx(-2.0), box.lowerCorner.z); - EXPECT_DOUBLE_EQ(7.0, box.upperCorner.x); - EXPECT_DOUBLE_EQ(6.0, box.upperCorner.y); - EXPECT_DOUBLE_EQ(8.0, box.upperCorner.z); + CHECK_EQ(doctest::Approx(7.0), box.upperCorner.x); + CHECK_EQ(doctest::Approx(6.0), box.upperCorner.y); + CHECK_EQ(doctest::Approx(8.0), box.upperCorner.z); } -TEST(BoundingBox3, Corner) +TEST_CASE("[BoundingBox3] - Corner") { BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); - EXPECT_VECTOR3_EQ(Vector3D(-2.0, -2.0, 1.0), box.Corner(0)); - EXPECT_VECTOR3_EQ(Vector3D(4.0, -2.0, 1.0), box.Corner(1)); - EXPECT_VECTOR3_EQ(Vector3D(-2.0, 3.0, 1.0), box.Corner(2)); - EXPECT_VECTOR3_EQ(Vector3D(4.0, 3.0, 1.0), box.Corner(3)); - EXPECT_VECTOR3_EQ(Vector3D(-2.0, -2.0, 5.0), box.Corner(4)); - EXPECT_VECTOR3_EQ(Vector3D(4.0, -2.0, 5.0), box.Corner(5)); - EXPECT_VECTOR3_EQ(Vector3D(-2.0, 3.0, 5.0), box.Corner(6)); - EXPECT_VECTOR3_EQ(Vector3D(4.0, 3.0, 5.0), box.Corner(7)); + CHECK_VECTOR3_EQ(Vector3D(-2.0, -2.0, 1.0), box.Corner(0)) + CHECK_VECTOR3_EQ(Vector3D(4.0, -2.0, 1.0), box.Corner(1)) + CHECK_VECTOR3_EQ(Vector3D(-2.0, 3.0, 1.0), box.Corner(2)) + CHECK_VECTOR3_EQ(Vector3D(4.0, 3.0, 1.0), box.Corner(3)) + CHECK_VECTOR3_EQ(Vector3D(-2.0, -2.0, 5.0), box.Corner(4)) + CHECK_VECTOR3_EQ(Vector3D(4.0, -2.0, 5.0), box.Corner(5)) + CHECK_VECTOR3_EQ(Vector3D(-2.0, 3.0, 5.0), box.Corner(6)) + CHECK_VECTOR3_EQ(Vector3D(4.0, 3.0, 5.0), box.Corner(7)) } -TEST(BoundingBox3, IsEmpty) +TEST_CASE("[BoundingBox3] - IsEmpty") { BoundingBox3D box(Vector3D(-2.0, -2.0, 1.0), Vector3D(4.0, 3.0, 5.0)); - EXPECT_FALSE(box.IsEmpty()); + CHECK_FALSE(box.IsEmpty()); box.lowerCorner = Vector3D(5.0, 1.0, 3.0); - EXPECT_TRUE(box.IsEmpty()); + CHECK(box.IsEmpty()); box.lowerCorner = Vector3D(2.0, 4.0, 3.0); - EXPECT_TRUE(box.IsEmpty()); + CHECK(box.IsEmpty()); box.lowerCorner = Vector3D(2.0, 1.0, 6.0); - EXPECT_TRUE(box.IsEmpty()); + CHECK(box.IsEmpty()); box.lowerCorner = Vector3D(4.0, 1.0, 3.0); - EXPECT_TRUE(box.IsEmpty()); + CHECK(box.IsEmpty()); } \ No newline at end of file diff --git a/Tests/UnitTests/UnitTestsUtils.hpp b/Tests/UnitTests/UnitTestsUtils.hpp index ed1ce2e5d1..5f1c3a45b5 100644 --- a/Tests/UnitTests/UnitTestsUtils.hpp +++ b/Tests/UnitTests/UnitTestsUtils.hpp @@ -3,18 +3,18 @@ #include -#define EXPECT_VECTOR2_EQ(expected, actual) \ - EXPECT_DOUBLE_EQ((expected).x, (actual).x); \ - EXPECT_DOUBLE_EQ((expected).y, (actual).y); +#define CHECK_VECTOR2_EQ(expected, actual) \ + CHECK_EQ(doctest::Approx((expected).x), (actual).x); \ + CHECK_EQ(doctest::Approx((expected).y), (actual).y); #define EXPECT_VECTOR2_NEAR(expected, actual, eps) \ EXPECT_NEAR((expected).x, (actual).x, eps); \ EXPECT_NEAR((expected).y, (actual).y, eps); -#define EXPECT_VECTOR3_EQ(expected, actual) \ - EXPECT_DOUBLE_EQ((expected).x, (actual).x); \ - EXPECT_DOUBLE_EQ((expected).y, (actual).y); \ - EXPECT_DOUBLE_EQ((expected).z, (actual).z); +#define CHECK_VECTOR3_EQ(expected, actual) \ + CHECK_EQ(doctest::Approx((expected).x), (actual).x); \ + CHECK_EQ(doctest::Approx((expected).y), (actual).y); \ + CHECK_EQ(doctest::Approx((expected).z), (actual).z); #define EXPECT_VECTOR3_NEAR(expected, actual, eps) \ EXPECT_NEAR((expected).x, (actual).x, eps); \