diff --git a/.appveyor.yml b/.appveyor.yml index e96c2d10b..571caf8c1 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -35,7 +35,7 @@ install: - CALL conda.bat activate xtensor - if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2017" set CMAKE_ARGS="-DDISABLE_VS2017=ON" - if "%APPVEYOR_BUILD_WORKER_IMAGE%" == "Visual Studio 2015" set CMAKE_ARGS="" - - cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DDOWNLOAD_GTEST=ON -DXTENSOR_USE_XSIMD=ON -DCMAKE_BUILD_TYPE=RELEASE %CMAKE_ARGS% . + - cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=%MINICONDA%\\LIBRARY -DBUILD_TESTS=ON -DXTENSOR_USE_XSIMD=ON -DCMAKE_BUILD_TYPE=RELEASE %CMAKE_ARGS% . - nmake test_xtensor_lib - cd test diff --git a/.azure-pipelines/azure-pipelines-win.yml b/.azure-pipelines/azure-pipelines-win.yml index fe364d0bb..f353f97cf 100644 --- a/.azure-pipelines/azure-pipelines-win.yml +++ b/.azure-pipelines/azure-pipelines-win.yml @@ -36,6 +36,7 @@ jobs: - script: | conda install cmake==3.14.0 ^ ninja ^ + doctest ^ nlohmann_json ^ xtl==0.7.0 ^ xsimd==7.4.8 ^ @@ -61,7 +62,7 @@ jobs: -DCMAKE_BUILD_TYPE=Release ^ -DCMAKE_C_COMPILER=clang-cl ^ -DCMAKE_CXX_COMPILER=clang-cl ^ - -DDOWNLOAD_GTEST=ON ^ + -DBUILD_TESTS=ON ^ -DXTENSOR_USE_XSIMD=ON ^ $(Build.SourcesDirectory) displayName: "Configure xtensor" diff --git a/.azure-pipelines/unix-build.yml b/.azure-pipelines/unix-build.yml index 2a1d0454c..a3b438e22 100644 --- a/.azure-pipelines/unix-build.yml +++ b/.azure-pipelines/unix-build.yml @@ -26,6 +26,7 @@ steps: source activate xtensor mkdir build cd build + CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DBUILD_TESTS=ON"; if [[ $(bound_checks) == 1 ]]; then CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DXTENSOR_ENABLE_ASSERT=ON"; fi @@ -53,7 +54,7 @@ steps: CMAKE_EXTA_ARGS="$CMAKE_EXTRA_ARGS -DBUILD_BENCHMARK=ON"; fi - cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX $CMAKE_EXTRA_ARGS -DDOWNLOAD_GTEST=ON $(Build.SourcesDirectory) + cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX $CMAKE_EXTRA_ARGS $(Build.SourcesDirectory) displayName: Configure xtensor workingDirectory: $(Build.BinariesDirectory) diff --git a/CMakeLists.txt b/CMakeLists.txt index cde49f4f7..bf2f75bf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,9 +207,6 @@ OPTION(CPP20 "enables C++20 (experimental)" OFF) OPTION(XTENSOR_DISABLE_EXCEPTIONS "Disable C++ exceptions" OFF) OPTION(DISABLE_MSVC_ITERATOR_CHECK "Disable the MVSC iterator check" ON) -if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) - set(BUILD_TESTS ON) -endif() if(XTENSOR_ENABLE_ASSERT OR XTENSOR_CHECK_DIMENSION) add_definitions(-DXTENSOR_ENABLE_ASSERT) diff --git a/environment-dev.yml b/environment-dev.yml index e7f868bf0..2c3eb456a 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -6,3 +6,4 @@ dependencies: - xtl=0.7.0 - xsimd=7.4.9 - nlohmann_json + - doctest \ No newline at end of file diff --git a/include/xtensor/xlayout.hpp b/include/xtensor/xlayout.hpp index ccace0fa0..3468dcf57 100644 --- a/include/xtensor/xlayout.hpp +++ b/include/xtensor/xlayout.hpp @@ -10,6 +10,8 @@ #ifndef XTENSOR_LAYOUT_HPP #define XTENSOR_LAYOUT_HPP +#include + // Do not include anything else here. // xlayout.hpp is included in xtensor_forward.hpp // and we don't want to bring other headers to it. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2e58db64f..6e5cc7b9a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,6 +9,9 @@ cmake_minimum_required(VERSION 3.1) +find_package(doctest REQUIRED) +find_package(Threads) + if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) project(xtensor-test) @@ -118,46 +121,6 @@ else() message(FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}") endif() -if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) - if(DOWNLOAD_GTEST) - # Download and unpack googletest at configure time - configure_file(downloadGTest.cmake.in googletest-download/CMakeLists.txt) - else() - # Copy local source of googletest at configure time - configure_file(copyGTest.cmake.in googletest-download/CMakeLists.txt) - endif() - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) - if(result) - message(FATAL_ERROR "CMake step for googletest failed: ${result}") - endif() - execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) - if(result) - message(FATAL_ERROR "Build step for googletest failed: ${result}") - endif() - - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - - # Add googletest directly to our build. This defines - # the gtest and gtest_main targets. - add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src - ${CMAKE_CURRENT_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL) - - set(GTEST_INCLUDE_DIRS "${gtest_SOURCE_DIR}/include") - add_library(GTest::GTest INTERFACE IMPORTED) - target_link_libraries(GTest::GTest INTERFACE gtest) - add_library(GTest::Main INTERFACE IMPORTED) - target_link_libraries(GTest::Main INTERFACE gtest_main) -else() - find_package(GTest REQUIRED) -endif() - -find_package(Threads) - -include_directories(${GTEST_INCLUDE_DIRS} SYSTEM) # For unit test and coverity scan. # The Coverity scanner takes time and it could cause build timeout(10mins) in Travis CI. @@ -284,7 +247,7 @@ add_custom_target( foreach(filename IN LISTS COMMON_BASE XTENSOR_TESTS) string(REPLACE ".cpp" "" targetname ${filename}) - add_executable(${targetname} ${filename} ${TEST_HEADERS} ${XTENSOR_HEADERS}) + add_executable(${targetname} main.cpp ${filename} ${TEST_HEADERS} ${XTENSOR_HEADERS}) if(XTENSOR_USE_XSIMD) target_compile_definitions(${targetname} PRIVATE @@ -300,11 +263,8 @@ foreach(filename IN LISTS COMMON_BASE XTENSOR_TESTS) if(XTENSOR_USE_OPENMP) target_compile_definitions(${targetname} PRIVATE XTENSOR_USE_OPENMP) endif() - if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) - add_dependencies(${targetname} gtest_main) - endif() target_include_directories(${targetname} PRIVATE ${XTENSOR_INCLUDE_DIR}) - target_link_libraries(${targetname} PRIVATE xtensor GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(${targetname} PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT}) add_custom_target( x${targetname} COMMAND ${targetname} @@ -312,7 +272,7 @@ foreach(filename IN LISTS COMMON_BASE XTENSOR_TESTS) add_test(NAME ${targetname} COMMAND ${targetname}) endforeach() -add_executable(test_xtensor_lib ${COMMON_BASE} ${XTENSOR_TESTS} ${TEST_HEADERS} ${XTENSOR_HEADERS}) +add_executable(test_xtensor_lib main.cpp ${COMMON_BASE} ${XTENSOR_TESTS} ${TEST_HEADERS} ${XTENSOR_HEADERS}) if(XTENSOR_USE_XSIMD) target_compile_definitions(test_xtensor_lib PRIVATE @@ -329,12 +289,8 @@ if(XTENSOR_USE_OPENMP) target_compile_definitions(test_xtensor_lib PRIVATE XTENSOR_USE_OPENMP) endif() -if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) - add_dependencies(test_xtensor_lib gtest_main) -endif() - target_include_directories(test_xtensor_lib PRIVATE ${XTENSOR_INCLUDE_DIR}) -target_link_libraries(test_xtensor_lib PRIVATE xtensor GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(test_xtensor_lib PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT}) add_custom_target(xtest COMMAND test_xtensor_lib DEPENDS test_xtensor_lib) add_test(NAME xtest COMMAND test_xtensor_lib) @@ -345,9 +301,5 @@ add_test(NAME xtest COMMAND test_xtensor_lib) add_library(test_xtensor_core_lib ${COMMON_BASE} ${TEST_HEADERS} ${XTENSOR_HEADERS}) target_include_directories(test_xtensor_core_lib PRIVATE ${XTENSOR_INCLUDE_DIR}) -if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) - add_dependencies(test_xtensor_core_lib gtest_main) -endif() - -target_link_libraries(test_xtensor_core_lib PRIVATE xtensor GTest::GTest GTest::Main ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(test_xtensor_core_lib PRIVATE xtensor doctest::doctest ${CMAKE_THREAD_LIBS_INIT}) add_custom_target(coverity COMMAND coverity_scan DEPENDS test_xtensor_core_lib) diff --git a/test/copyGTest.cmake.in b/test/copyGTest.cmake.in deleted file mode 100644 index 6db02b3dc..000000000 --- a/test/copyGTest.cmake.in +++ /dev/null @@ -1,24 +0,0 @@ -############################################################################ -# Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht # -# Copyright (c) QuantStack # -# # -# Distributed under the terms of the BSD 3-Clause License. # -# # -# The full license is in the file LICENSE, distributed with this software. # -############################################################################ - -cmake_minimum_required(VERSION 2.8.2) - -project(googletest-download NONE) - -include(ExternalProject) -ExternalProject_Add(googletest - URL "${GTEST_SRC_DIR}" - SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" -) - diff --git a/test/downloadGTest.cmake.in b/test/downloadGTest.cmake.in deleted file mode 100644 index 9743d0c38..000000000 --- a/test/downloadGTest.cmake.in +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################ -# Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht # -# Copyright (c) QuantStack # -# # -# Distributed under the terms of the BSD 3-Clause License. # -# # -# The full license is in the file LICENSE, distributed with this software. # -############################################################################ - -cmake_minimum_required(VERSION 2.8.2) - -project(googletest-download NONE) - -include(ExternalProject) -ExternalProject_Add(googletest - GIT_REPOSITORY https://github.com/JohanMabille/googletest.git - GIT_TAG warnings - SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" -) - diff --git a/test/main.cpp b/test/main.cpp index 078b4619a..a2d9121e7 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,16 +1,5 @@ -/*************************************************************************** -* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht * -* Copyright (c) QuantStack * -* * -* Distributed under the terms of the BSD 3-Clause License. * -* * -* The full license is in the file LICENSE, distributed with this software. * -****************************************************************************/ - -#include "gtest/gtest.h" - -int main(int argc, char* argv[]) -{ - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#if defined(XTENSOR_DISABLE_EXCEPTIONS) + #define DOCTEST_CONFIG_NO_EXCEPTIONS +#endif +#include "doctest/doctest.h" diff --git a/test/test_common.hpp b/test/test_common.hpp index 3156f0cdc..9424b6c7d 100644 --- a/test/test_common.hpp +++ b/test/test_common.hpp @@ -14,6 +14,18 @@ #include "xtensor/xmanipulation.hpp" #include "test_common_macros.hpp" +// the tests used to be implemented with gtest +// testing::Types<...> and testing::Test +// where introduced to keep compatible +// with the gtest test where we can +namespace testing +{ + template + using Types = std::tuple; + + struct Test{}; +} + namespace xt { template @@ -173,14 +185,14 @@ namespace xt void test_resize(V& vec) { { - SCOPED_TRACE("row_major resize"); + INFO("row_major resize"); row_major_result rm; vec.resize(rm.m_shape, layout_type::row_major); compare_shape(vec, rm); } { - SCOPED_TRACE("different types resize"); + INFO("different types resize"); row_major_result rm; auto v_copy_a = vec; auto v_copy_b = vec; @@ -193,21 +205,21 @@ namespace xt } { - SCOPED_TRACE("column_major resize"); + INFO("column_major resize"); column_major_result cm; vec.resize(cm.m_shape, layout_type::column_major); compare_shape(vec, cm); } { - SCOPED_TRACE("central_major resize"); + INFO("central_major resize"); central_major_result cem; vec.resize(cem.m_shape, cem.m_strides); compare_shape(vec, cem); } { - SCOPED_TRACE("unit_shape resize"); + INFO("unit_shape resize"); unit_shape_result usr; vec.resize(usr.m_shape, layout_type::row_major); compare_shape(vec, usr, false); @@ -219,7 +231,7 @@ namespace xt void test_reshape(V& vec) { { - SCOPED_TRACE("row_major reshape"); + INFO("row_major reshape"); row_major_result rm; auto shape = rm.m_shape; std::size_t sz = compute_size(shape); @@ -252,7 +264,7 @@ namespace xt void test_throwing_reshape(V& vec) { { - SCOPED_TRACE("throwing reshape"); + INFO("throwing reshape"); vec = xt::arange(6); XT_EXPECT_THROW(vec.reshape({2}), std::runtime_error); } @@ -263,8 +275,9 @@ namespace xt { using shape_type = typename V::shape_type; using strides_type = typename V::strides_type; + { - SCOPED_TRACE("transpose"); + INFO("transpose"); shape_type shape_new = vec.shape(); auto vt = transpose(vec); std::reverse(shape_new.begin(), shape_new.end()); @@ -272,7 +285,7 @@ namespace xt } { - SCOPED_TRACE("transpose with data"); + INFO("transpose with data"); row_major_result rm; vec.resize(rm.shape(), layout_type::row_major); @@ -304,7 +317,7 @@ namespace xt } { - SCOPED_TRACE("transpose with permutation"); + INFO("transpose with permutation"); row_major_result rm; vec.resize(rm.shape(), layout_type::row_major); @@ -340,7 +353,7 @@ namespace xt } { - SCOPED_TRACE("transpose permutation throws"); + INFO("transpose permutation throws"); row_major_result rm; vec.reshape(rm.shape(), layout_type::row_major); @@ -401,7 +414,7 @@ namespace xt void test_access(V& vec) { { - SCOPED_TRACE("row_major access"); + INFO("row_major access"); row_major_result rm; vec.resize(rm.m_shape, layout_type::row_major); assign_array(vec, rm.m_assigner); @@ -412,7 +425,7 @@ namespace xt } { - SCOPED_TRACE("column_major access"); + INFO("column_major access"); column_major_result cm; vec.resize(cm.m_shape, layout_type::column_major); assign_array(vec, cm.m_assigner); @@ -423,7 +436,7 @@ namespace xt } { - SCOPED_TRACE("central_major access"); + INFO("central_major access"); central_major_result cem; vec.resize(cem.m_shape, cem.m_strides); assign_array(vec, cem.m_assigner); @@ -434,7 +447,7 @@ namespace xt } { - SCOPED_TRACE("unit_shape access"); + INFO("unit_shape access"); unit_shape_result usr; vec.resize(usr.m_shape, layout_type::row_major); assign_array(vec, usr.m_assigner); @@ -449,7 +462,7 @@ namespace xt void test_unchecked(V& vec) { { - SCOPED_TRACE("row_major access"); + INFO("row_major access"); row_major_result rm; vec.resize(rm.m_shape, layout_type::row_major); assign_array(vec, rm.m_assigner); @@ -458,7 +471,7 @@ namespace xt } { - SCOPED_TRACE("column_major access"); + INFO("column_major access"); column_major_result cm; vec.resize(cm.m_shape, layout_type::column_major); assign_array(vec, cm.m_assigner); @@ -467,7 +480,7 @@ namespace xt } { - SCOPED_TRACE("central_major access"); + INFO("central_major access"); central_major_result cem; vec.resize(cem.m_shape, cem.m_strides); assign_array(vec, cem.m_assigner); @@ -476,7 +489,7 @@ namespace xt } { - SCOPED_TRACE("unit_shape access"); + INFO("unit_shape access"); unit_shape_result usr; vec.resize(usr.m_shape, layout_type::row_major); assign_array(vec, usr.m_assigner); @@ -489,7 +502,7 @@ namespace xt void test_at(V& vec) { { - SCOPED_TRACE("row_major access"); + INFO("row_major access"); row_major_result rm; vec.resize(rm.m_shape, layout_type::row_major); safe_assign_array(vec, rm.m_assigner); @@ -498,7 +511,7 @@ namespace xt } { - SCOPED_TRACE("column_major access"); + INFO("column_major access"); column_major_result cm; vec.resize(cm.m_shape, layout_type::column_major); safe_assign_array(vec, cm.m_assigner); @@ -507,7 +520,7 @@ namespace xt } { - SCOPED_TRACE("central_major access"); + INFO("central_major access"); central_major_result cem; vec.resize(cem.m_shape, cem.m_strides); safe_assign_array(vec, cem.m_assigner); @@ -516,7 +529,7 @@ namespace xt } { - SCOPED_TRACE("unit_shape access"); + INFO("unit_shape access"); unit_shape_result usr; vec.resize(usr.m_shape, layout_type::row_major); safe_assign_array(vec, usr.m_assigner); @@ -529,7 +542,7 @@ namespace xt void test_element(V& vec) { { - SCOPED_TRACE("row_major access"); + INFO("row_major access"); row_major_result rm; vec.resize(rm.m_shape, layout_type::row_major); assign_array(vec, rm.m_assigner); @@ -544,7 +557,7 @@ namespace xt } { - SCOPED_TRACE("column_major access"); + INFO("column_major access"); column_major_result cm; vec.resize(cm.m_shape, layout_type::column_major); assign_array(vec, cm.m_assigner); @@ -559,7 +572,7 @@ namespace xt } { - SCOPED_TRACE("central_major access"); + INFO("central_major access"); central_major_result cem; vec.resize(cem.m_shape, cem.m_strides); assign_array(vec, cem.m_assigner); @@ -574,7 +587,7 @@ namespace xt } { - SCOPED_TRACE("unit_shape access"); + INFO("unit_shape access"); unit_shape_result usr; vec.resize(usr.m_shape, layout_type::row_major); assign_array(vec, usr.m_assigner); @@ -614,7 +627,7 @@ namespace xt xindex index1 = {1, 1}; xindex index2 = {2, 2, 2, 1, 3}; { - SCOPED_TRACE("row_major access"); + INFO("row_major access"); row_major_result rm; vec.resize(rm.m_shape, layout_type::row_major); indexed_assign_array(vec, rm.m_assigner); @@ -626,7 +639,7 @@ namespace xt } { - SCOPED_TRACE("column_major access"); + INFO("column_major access"); column_major_result cm; vec.resize(cm.m_shape, layout_type::column_major); indexed_assign_array(vec, cm.m_assigner); @@ -638,7 +651,7 @@ namespace xt } { - SCOPED_TRACE("central_major access"); + INFO("central_major access"); central_major_result cem; vec.resize(cem.m_shape, cem.m_strides); indexed_assign_array(vec, cem.m_assigner); @@ -650,7 +663,7 @@ namespace xt } { - SCOPED_TRACE("unit_shape access"); + INFO("unit_shape access"); unit_shape_result usr; vec.resize(usr.m_shape, layout_type::row_major); indexed_assign_array(vec, usr.m_assigner); @@ -673,7 +686,7 @@ namespace xt vec.resize(s); { - SCOPED_TRACE("same shape"); + INFO("same shape"); shape_type s1 = s; bool res = vec.broadcast_shape(s1); EXPECT_EQ(s1, s); @@ -681,7 +694,7 @@ namespace xt } { - SCOPED_TRACE("different shape"); + INFO("different shape"); shape_type s2 = {3, 5, 1, 2}; shape_type s2r = {3, 5, 4, 2}; bool res = vec.broadcast_shape(s2); @@ -690,7 +703,7 @@ namespace xt } { - SCOPED_TRACE("incompatible shapes"); + INFO("incompatible shapes"); shape_type s4 = {2, 1, 3, 2}; XT_EXPECT_THROW(vec.broadcast_shape(s4), broadcast_error); } @@ -705,7 +718,7 @@ namespace xt vec.resize(s); { - SCOPED_TRACE("different dimensions"); + INFO("different dimensions"); shape_type s3 = {5, 3, 1, 4, 2}; shape_type s3r = s3; bool res = vec.broadcast_shape(s3); @@ -718,7 +731,7 @@ namespace xt void test_iterator(VRM& vecrm, VCM& veccm) { { - SCOPED_TRACE("row_major storage iterator"); + INFO("row_major storage iterator"); row_major_result rm; vecrm.resize(rm.m_shape, layout_type::row_major); std::copy(rm.storage().cbegin(), rm.storage().cend(), vecrm.template begin()); @@ -727,7 +740,7 @@ namespace xt } { - SCOPED_TRACE("column_major storage iterator"); + INFO("column_major storage iterator"); column_major_result cm; veccm.resize(cm.m_shape, layout_type::column_major); std::copy(cm.storage().cbegin(), cm.storage().cend(), veccm.template begin()); @@ -758,8 +771,8 @@ namespace xt size_t nb_iter = vec.size() / 2; using shape_type = std::vector; - // broadcast_iterator { + INFO("broadcast_iterator"); auto iter = vec.template begin(); auto iter_end = vec.template end(); for (size_t i = 0; i < nb_iter; ++i) @@ -774,8 +787,8 @@ namespace xt EXPECT_EQ(iter, iter_end); } - // shaped_xiterator { + INFO("shaped_xiterator"); shape_type shape(rm.m_shape.size() + 1); std::copy(rm.m_shape.begin(), rm.m_shape.end(), shape.begin() + 1); shape[0] = 2; @@ -793,8 +806,8 @@ namespace xt EXPECT_EQ(iter, iter_end); } - // column broadcast_iterator { + INFO("column broadcast_iterator"); auto iter = vec.template begin(); auto iter_end = vec.template end(); for (size_t i = 0; i < nb_iter; ++i) @@ -809,8 +822,8 @@ namespace xt EXPECT_EQ(iter, iter_end); } - // column shaped_xiterator { + INFO("column shaped_xiterator"); shape_type shape(rm.m_shape.size() + 1); std::copy(rm.m_shape.begin(), rm.m_shape.end(), shape.begin() + 1); shape[0] = 2; @@ -837,8 +850,8 @@ namespace xt indexed_assign_array(vec, rm.m_assigner); size_t nb_iter = vec.size() / 2; - // broadcast_iterator { + INFO("broadcast_iterator"); auto iter = vec.template rbegin(); auto iter_end = vec.template rend(); for (size_t i = 0; i < nb_iter; ++i) @@ -853,8 +866,8 @@ namespace xt EXPECT_EQ(iter, iter_end); } - // shaped_xiterator { + INFO("shaped_xiterator"); using shape_type = std::vector; shape_type shape(rm.m_shape.size() + 1); std::copy(rm.m_shape.begin(), rm.m_shape.end(), shape.begin() + 1); diff --git a/test/test_common_macros.hpp b/test/test_common_macros.hpp index 95e2826ed..1ecaf92df 100644 --- a/test/test_common_macros.hpp +++ b/test/test_common_macros.hpp @@ -1,26 +1,57 @@ #ifndef TEST_COMMON_MACROS_HPP #define TEST_COMMON_MACROS_HPP -#include "gtest/gtest.h" +#if defined(XTENSOR_DISABLE_EXCEPTIONS) + #define DOCTEST_CONFIG_NO_EXCEPTIONS +#endif + +#include "doctest/doctest.h" #include "xtensor/xtensor_config.hpp" #if defined(XTENSOR_DISABLE_EXCEPTIONS) -#define XT_EXPECT_THROW(x, y) EXPECT_DEATH_IF_SUPPORTED(x, ""); -#define XT_ASSERT_THROW(x, y) ASSERT_DEATH_IF_SUPPORTED(x, ""); -#define XT_EXPECT_ANY_THROW(x) EXPECT_DEATH_IF_SUPPORTED(x, ""); -#define XT_ASSERT_ANY_THROW(x) ASSERT_DEATH_IF_SUPPORTED(x, ""); +#define XT_EXPECT_THROW(x, y) #warning "XT_EXPECT_THROW IS DISABLED WHEN EXCEPTIONS ARE DISABLED" ; +#define XT_ASSERT_THROW(x, y) #warning "XT_ASSERT_THROW IS DISABLED WHEN EXCEPTIONS ARE DISABLED" ; +#define XT_EXPECT_ANY_THROW(x) #warning "XT_EXPECT_ANY_THROW IS DISABLED WHEN EXCEPTIONS ARE DISABLED" ; +#define XT_ASSERT_ANY_THROW(x) #warning "XT_ASSERT_ANY_THROW IS DISABLED WHEN EXCEPTIONS ARE DISABLED" ; #define XT_EXPECT_NO_THROW(x) x; #define XT_ASSERT_NO_THROW(x) x; #else -#define XT_EXPECT_THROW(x, y) EXPECT_THROW(x, y); -#define XT_ASSERT_THROW(x, y) EXPECT_THROW(x, y); -#define XT_EXPECT_ANY_THROW(x) EXPECT_ANY_THROW(x); -#define XT_ASSERT_ANY_THROW(x) ASSERT_ANY_THROW(x); -#define XT_EXPECT_NO_THROW(x) EXPECT_NO_THROW(x); -#define XT_ASSERT_NO_THROW(x) ASSERT_NO_THROW(x); +#define XT_EXPECT_THROW(x, y) CHECK_THROWS_AS(x, y); +#define XT_ASSERT_THROW(x, y) REQUIRE_THROWS_AS(x, y); +#define XT_EXPECT_ANY_THROW(x) CHECK_THROWS_AS(x, std::exception); +#define XT_ASSERT_ANY_THROW(x) REQUIRE_THROWS_AS(x, std::exception); +#define XT_EXPECT_NO_THROW(x) x; +#define XT_ASSERT_NO_THROW(x) x; #endif #endif + +#define EXPECT_NO_THROW(x) XT_EXPECT_NO_THROW(x) +#define EXPECT_THROW(x, y) XT_EXPECT_THROW(x,y) + +#define TEST(A,B) TEST_CASE(#A"."#B ) +#define EXPECT_EQ(A,B) CHECK_EQ(A,B) +#define EXPECT_NE(A,B) CHECK_NE(A,B) +#define EXPECT_LE(A,B) CHECK_LE(A,B) +#define EXPECT_GE(A,B) CHECK_GE(A,B) +#define EXPECT_LT(A,B) CHECK_LT(A,B) +#define EXPECT_GT(A,B) CHECK_GT(A,B) +#define EXPECT_TRUE(A) CHECK_EQ(A, true) +#define EXPECT_FALSE(A) CHECK_FALSE(A) + +#define ASSERT_EQ(A,B) REQUIRE_EQ(A,B) +#define ASSERT_NE(A,B) REQUIRE_NE(A,B) +#define ASSERT_LE(A,B) REQUIRE_LE(A,B) +#define ASSERT_GE(A,B) REQUIRE_GE(A,B) +#define ASSERT_LT(A,B) REQUIRE_LT(A,B) +#define ASSERT_GT(A,B) REQUIRE_GT(A,B) +#define ASSERT_TRUE(A) REQUIRE_EQ(A, true) +#define ASSERT_FALSE(A) REQUIRE_FALSE(A) + +#define EXPECT_DOUBLE_EQ(x,y) CHECK(x == doctest::Approx(y)); + +#define TEST_F(FIXTURE_CLASS, NAME)\ + TEST_CASE_FIXTURE(FIXTURE_CLASS, #NAME) diff --git a/test/test_extended_broadcast_view.cpp b/test/test_extended_broadcast_view.cpp index a0c74701d..e7e9f2cd9 100644 --- a/test/test_extended_broadcast_view.cpp +++ b/test/test_extended_broadcast_view.cpp @@ -12,7 +12,7 @@ #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xfixed.hpp" #include "xtensor/xnoalias.hpp" diff --git a/test/test_extended_xhistogram.cpp b/test/test_extended_xhistogram.cpp index bc540be73..5defe0686 100644 --- a/test/test_extended_xhistogram.cpp +++ b/test/test_extended_xhistogram.cpp @@ -12,7 +12,7 @@ #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" #include "xtensor/xhistogram.hpp" diff --git a/test/test_extended_xmath_interp.cpp b/test/test_extended_xmath_interp.cpp index a683a9d8e..f942922a4 100644 --- a/test/test_extended_xmath_interp.cpp +++ b/test/test_extended_xmath_interp.cpp @@ -12,7 +12,7 @@ #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" #include "xtensor/xmath.hpp" diff --git a/test/test_extended_xmath_reducers.cpp b/test/test_extended_xmath_reducers.cpp index eaa602240..6b285fdd7 100644 --- a/test/test_extended_xmath_reducers.cpp +++ b/test/test_extended_xmath_reducers.cpp @@ -12,7 +12,7 @@ #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" #include "xtensor/xmath.hpp" diff --git a/test/test_extended_xsort.cpp b/test/test_extended_xsort.cpp index 559e70c68..57b6346a4 100644 --- a/test/test_extended_xsort.cpp +++ b/test/test_extended_xsort.cpp @@ -10,7 +10,7 @@ // Warning: This file should not be modified directly! Instead, modify the `*.cppy` file. -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include #include diff --git a/test/test_sfinae.cpp b/test/test_sfinae.cpp index 2f95909f4..3376e2ee2 100644 --- a/test/test_sfinae.cpp +++ b/test/test_sfinae.cpp @@ -10,7 +10,7 @@ #include #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xtensor.hpp" #include "xtensor/xarray.hpp" // #include "xtensor/xfixed.hpp" diff --git a/test/test_xaccumulator.cpp b/test/test_xaccumulator.cpp index 6a4b34c38..ca19e0363 100644 --- a/test/test_xaccumulator.cpp +++ b/test/test_xaccumulator.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xaccumulator.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" diff --git a/test/test_xadapt.cpp b/test/test_xadapt.cpp index 25a4121cf..3f352c9ba 100644 --- a/test/test_xadapt.cpp +++ b/test/test_xadapt.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xadapt.hpp" #include "xtensor/xstrides.hpp" diff --git a/test/test_xadaptor_semantic.cpp b/test/test_xadaptor_semantic.cpp index e18b8fe9f..d0cde16ce 100644 --- a/test/test_xadaptor_semantic.cpp +++ b/test/test_xadaptor_semantic.cpp @@ -7,9 +7,11 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common.hpp" #include "test_xsemantic.hpp" +TEST_SUITE_BEGIN("adaptor_semantic"); + namespace xt { using vector_type = std::vector; @@ -35,17 +37,16 @@ namespace xt using get_test_adaptor_t = typename get_test_adaptor::type; template - class adaptor_semantic : public ::testing::Test + class adaptor_semantic { public: using container_type = C; using adaptor_type = get_test_adaptor_t; }; - using testing_types = ::testing::Types; - TYPED_TEST_SUITE(adaptor_semantic, testing_types); + #define ADAPTOR_SEMANTIC_TYPES xarray_dynamic, xtensor_dynamic - TYPED_TEST(adaptor_semantic, xsimd_info) + TEST_CASE_TEMPLATE("xsimd_info", TypeParam, ADAPTOR_SEMANTIC_TYPES) { #if defined(XTENSOR_USE_XSIMD) std::cout << "Built with XSIMD" << std::endl; @@ -63,36 +64,36 @@ namespace xt #endif } - TYPED_TEST(adaptor_semantic, a_plus_b) + TEST_CASE_TEMPLATE("a_plus_b", TypeParam, ADAPTOR_SEMANTIC_TYPES) { operation_tester, TypeParam> tester; - using adaptor_type = typename TestFixture::adaptor_type; + using adaptor_type = typename adaptor_semantic::adaptor_type; + SUBCASE("row_major + row_major") { - SCOPED_TRACE("row_major + row_major"); vector_type v; adaptor_type b(v); b = tester.a + tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major + column_major") { - SCOPED_TRACE("row_major + column_major"); vector_type v; adaptor_type b(v); b = tester.a + tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major + central_major") { - SCOPED_TRACE("row_major + central_major"); vector_type v; adaptor_type b(v); b = tester.a + tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major + unit_major") { - SCOPED_TRACE("row_major + unit_major"); vector_type v; adaptor_type b(v); b = tester.a + tester.ua; @@ -100,37 +101,37 @@ namespace xt } } - TYPED_TEST(adaptor_semantic, a_minus_b) + TEST_CASE_TEMPLATE("a_minus_b", TypeParam, ADAPTOR_SEMANTIC_TYPES) { operation_tester, TypeParam> tester; - using adaptor_type = typename TestFixture::adaptor_type; + using adaptor_type = typename adaptor_semantic::adaptor_type; + SUBCASE("row_major - row_major") { - SCOPED_TRACE("row_major - row_major"); vector_type v; adaptor_type b(v); b = tester.a - tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major - column_major") { - SCOPED_TRACE("row_major - column_major"); vector_type v; adaptor_type b(v); b = tester.a - tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major - central_major") { - SCOPED_TRACE("row_major - central_major"); vector_type v; adaptor_type b(v); b = tester.a - tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major - unit_major") { - SCOPED_TRACE("row_major - unit_major"); vector_type v; adaptor_type b(v); b = tester.a - tester.ua; @@ -138,37 +139,37 @@ namespace xt } } - TYPED_TEST(adaptor_semantic, a_times_b) + TEST_CASE_TEMPLATE("a_times_b", TypeParam, ADAPTOR_SEMANTIC_TYPES) { operation_tester, TypeParam> tester; - using adaptor_type = typename TestFixture::adaptor_type; + using adaptor_type = typename adaptor_semantic::adaptor_type; + SUBCASE("row_major * row_major") { - SCOPED_TRACE("row_major * row_major"); vector_type v; adaptor_type b(v); b = tester.a * tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major * column_major") { - SCOPED_TRACE("row_major * column_major"); vector_type v; adaptor_type b(v); b = tester.a * tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major * central_major") { - SCOPED_TRACE("row_major * central_major"); vector_type v; adaptor_type b(v); b = tester.a * tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major * unit_major") { - SCOPED_TRACE("row_major * unit_major"); vector_type v; adaptor_type b(v); b = tester.a * tester.ua; @@ -176,37 +177,37 @@ namespace xt } } - TYPED_TEST(adaptor_semantic, a_divide_by_b) + TEST_CASE_TEMPLATE("a_divide_by_b", TypeParam, ADAPTOR_SEMANTIC_TYPES) { operation_tester, TypeParam> tester; - using adaptor_type = typename TestFixture::adaptor_type; + using adaptor_type = typename adaptor_semantic::adaptor_type; + SUBCASE("row_major / row_major") { - SCOPED_TRACE("row_major / row_major"); vector_type v; adaptor_type b(v); b = tester.a / tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major / column_major") { - SCOPED_TRACE("row_major / column_major"); vector_type v; adaptor_type b(v); b = tester.a / tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major / central_major") { - SCOPED_TRACE("row_major / central_major"); vector_type v; adaptor_type b(v); b = tester.a / tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major / unit_major") { - SCOPED_TRACE("row_major / unit_major"); vector_type v; adaptor_type b(v); b = tester.a / tester.ua; @@ -214,13 +215,13 @@ namespace xt } } - TYPED_TEST(adaptor_semantic, a_plus_equal_b) + TEST_CASE_TEMPLATE("a_plus_equal_b", TypeParam, ADAPTOR_SEMANTIC_TYPES) { operation_tester, TypeParam> tester; - using adaptor_type = typename TestFixture::adaptor_type; + using adaptor_type = typename adaptor_semantic::adaptor_type; + SUBCASE("row_major += row_major") { - SCOPED_TRACE("row_major += row_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -228,8 +229,8 @@ namespace xt EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major += column_major") { - SCOPED_TRACE("row_major += column_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -237,8 +238,8 @@ namespace xt EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major += central_major") { - SCOPED_TRACE("row_major += central_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -246,8 +247,8 @@ namespace xt EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major += unit_major") { - SCOPED_TRACE("row_major += unit_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -256,13 +257,13 @@ namespace xt } } - TYPED_TEST(adaptor_semantic, a_minus_equal_b) + TEST_CASE_TEMPLATE("a_minus_equal_b", TypeParam, ADAPTOR_SEMANTIC_TYPES) { operation_tester, TypeParam> tester; - using adaptor_type = typename TestFixture::adaptor_type; + using adaptor_type = typename adaptor_semantic::adaptor_type; + SUBCASE("row_major -= row_major") { - SCOPED_TRACE("row_major -= row_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -270,8 +271,8 @@ namespace xt EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major -= column_major") { - SCOPED_TRACE("row_major -= column_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -279,8 +280,8 @@ namespace xt EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major -= central_major") { - SCOPED_TRACE("row_major -= central_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -288,8 +289,8 @@ namespace xt EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major -= unit_major") { - SCOPED_TRACE("row_major -= unit_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -298,13 +299,13 @@ namespace xt } } - TYPED_TEST(adaptor_semantic, a_times_equal_b) + TEST_CASE_TEMPLATE("a_times_equal_b", TypeParam, ADAPTOR_SEMANTIC_TYPES) { operation_tester, TypeParam> tester; - using adaptor_type = typename TestFixture::adaptor_type; + using adaptor_type = typename adaptor_semantic::adaptor_type; + SUBCASE("row_major *= row_major") { - SCOPED_TRACE("row_major *= row_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -312,8 +313,8 @@ namespace xt EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major *= column_major") { - SCOPED_TRACE("row_major *= column_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -321,8 +322,8 @@ namespace xt EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major *= central_major") { - SCOPED_TRACE("row_major *= central_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -330,8 +331,8 @@ namespace xt EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major *= unit_major") { - SCOPED_TRACE("row_major *= unit_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -340,13 +341,13 @@ namespace xt } } - TYPED_TEST(adaptor_semantic, a_divide_by_equal_b) + TEST_CASE_TEMPLATE("a_divide_by_equal_b", TypeParam, ADAPTOR_SEMANTIC_TYPES) { operation_tester, TypeParam> tester; - using adaptor_type = typename TestFixture::adaptor_type; + using adaptor_type = typename adaptor_semantic::adaptor_type; + SUBCASE("row_major /= row_major") { - SCOPED_TRACE("row_major /= row_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -354,8 +355,8 @@ namespace xt EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major /= column_major") { - SCOPED_TRACE("row_major /= column_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -363,8 +364,8 @@ namespace xt EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major /= central_major") { - SCOPED_TRACE("row_major /= central_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -372,8 +373,8 @@ namespace xt EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major /= unit_major") { - SCOPED_TRACE("row_major /= unit_major"); vector_type v; adaptor_type b(v); b = tester.a; @@ -381,4 +382,6 @@ namespace xt EXPECT_EQ(tester.res_ru, b); } } + #undef ADAPTOR_SEMANTIC_TYPES } +TEST_SUITE_END(); \ No newline at end of file diff --git a/test/test_xarray.cpp b/test/test_xarray.cpp index 5e51ad5d4..81724d940 100644 --- a/test/test_xarray.cpp +++ b/test/test_xarray.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" + #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" #include "xtensor/xmanipulation.hpp" @@ -21,22 +21,22 @@ namespace xt TEST(xarray, shaped_constructor) { + SUBCASE("row_major constructor") { - SCOPED_TRACE("row_major constructor"); row_major_result<> rm; xarray_dynamic ra(rm.m_shape, layout_type::row_major); compare_shape(ra, rm); } + SUBCASE("column_major constructor") { - SCOPED_TRACE("column_major constructor"); column_major_result<> cm; xarray ca(cm.m_shape); compare_shape(ca, cm); } + SUBCASE("from shape") { - SCOPED_TRACE("from shape"); std::array shp = {5, 4, 2}; std::vector shp_as_vec = {5, 4, 2}; auto ca = xarray::from_shape({3, 2, 1}); @@ -56,8 +56,8 @@ namespace xt TEST(xarray, valued_constructor) { + SUBCASE("row_major valued constructor") { - SCOPED_TRACE("row_major valued constructor"); row_major_result<> rm; int value = 2; xarray_dynamic ra(rm.m_shape, value, layout_type::row_major); @@ -66,8 +66,8 @@ namespace xt EXPECT_EQ(ra.storage(), vec); } + SUBCASE("column_major valued constructor") { - SCOPED_TRACE("column_major valued constructor"); column_major_result<> cm; int value = 2; xarray ca(cm.m_shape, value); @@ -100,15 +100,15 @@ namespace xt int value = 2; xarray_dynamic a(res.m_shape, res.m_strides, value); + SUBCASE("copy constructor") { - SCOPED_TRACE("copy constructor"); xarray_dynamic b(a); compare_shape(a, b); EXPECT_EQ(a.storage(), b.storage()); } + SUBCASE("assignment operator") { - SCOPED_TRACE("assignment operator"); row_major_result<> r; xarray_dynamic c(r.m_shape, 0); EXPECT_NE(a.storage(), c.storage()); @@ -124,16 +124,16 @@ namespace xt int value = 2; xarray_dynamic a(res.m_shape, res.m_strides, value); + SUBCASE("move constructor") { - SCOPED_TRACE("move constructor"); xarray_dynamic tmp(a); xarray_dynamic b(std::move(tmp)); compare_shape(a, b); EXPECT_EQ(a.storage(), b.storage()); } + SUBCASE("move assignment") { - SCOPED_TRACE("move assignment"); row_major_result<> r; xarray_dynamic c(r.m_shape, 0); EXPECT_NE(a.storage(), c.storage()); diff --git a/test/test_xarray_adaptor.cpp b/test/test_xarray_adaptor.cpp index 45a53c086..afdae118c 100644 --- a/test/test_xarray_adaptor.cpp +++ b/test/test_xarray_adaptor.cpp @@ -7,7 +7,6 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" #include "xtensor/xarray.hpp" #include "test_common.hpp" @@ -18,16 +17,16 @@ namespace xt TEST(xarray_adaptor, shaped_constructor) { + SUBCASE("row_major constructor") { - SCOPED_TRACE("row_major constructor"); row_major_result<> rm; vec_type v; adaptor_type a(v, rm.shape(), layout_type::row_major); compare_shape(a, rm); } + SUBCASE("column_major constructor") { - SCOPED_TRACE("column_major constructor"); column_major_result<> cm; vec_type v; adaptor_type a(v, cm.shape(), layout_type::column_major); @@ -50,15 +49,15 @@ namespace xt vec_type v(res.size(), value); adaptor_type a(v, res.shape(), res.strides()); + SUBCASE("copy constructor") { - SCOPED_TRACE("copy constructor"); adaptor_type b(a); compare_shape(a, b); EXPECT_EQ(a.storage(), b.storage()); } + SUBCASE("assignment operator") { - SCOPED_TRACE("assignment operator"); row_major_result<> r; vec_type v2(r.size(), 0); adaptor_type c(v2, r.shape()); @@ -76,16 +75,16 @@ namespace xt vec_type v(res.size(), value); adaptor_type a(v, res.shape(), res.strides()); + SUBCASE("move constructor") { - SCOPED_TRACE("move constructor"); adaptor_type tmp(a); adaptor_type b(std::move(tmp)); compare_shape(a, b); EXPECT_EQ(a.storage(), b.storage()); } + SUBCASE("move assignment") { - SCOPED_TRACE("move assignment"); row_major_result<> r; vec_type v2(r.size(), 0); adaptor_type c(v2, r.shape()); diff --git a/test/test_xassign.cpp b/test/test_xassign.cpp index 3f5618a66..76c19eafd 100644 --- a/test/test_xassign.cpp +++ b/test/test_xassign.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" diff --git a/test/test_xaxis_iterator.cpp b/test/test_xaxis_iterator.cpp index 3f3d9b509..61fb17819 100644 --- a/test/test_xaxis_iterator.cpp +++ b/test/test_xaxis_iterator.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xaxis_iterator.hpp" diff --git a/test/test_xaxis_slice_iterator.cpp b/test/test_xaxis_slice_iterator.cpp index cd54cbc86..2646b1964 100644 --- a/test/test_xaxis_slice_iterator.cpp +++ b/test/test_xaxis_slice_iterator.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xaxis_slice_iterator.hpp" diff --git a/test/test_xbroadcast.cpp b/test/test_xbroadcast.cpp index 1c3ab3468..ced09f742 100644 --- a/test/test_xbroadcast.cpp +++ b/test/test_xbroadcast.cpp @@ -7,8 +7,8 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" -#include "test_common_macros.hpp" + +#include "test_common.hpp" #include "xtensor/xbroadcast.hpp" #include "xtensor/xarray.hpp" diff --git a/test/test_xbuffer_adaptor.cpp b/test/test_xbuffer_adaptor.cpp index 733ab5ced..80f52bc74 100644 --- a/test/test_xbuffer_adaptor.cpp +++ b/test/test_xbuffer_adaptor.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_common_macros.hpp" #include "xtensor/xbuffer_adaptor.hpp" diff --git a/test/test_xbuilder.cpp b/test/test_xbuilder.cpp index 0aa86cf16..90d0d808d 100644 --- a/test/test_xbuilder.cpp +++ b/test/test_xbuilder.cpp @@ -11,8 +11,7 @@ #define VS_SKIP_CONCATENATE_FIXED 1 #endif -#include "gtest/gtest.h" -#include "test_common_macros.hpp" +#include "test_common.hpp" #include "xtensor/xbuilder.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" diff --git a/test/test_xchunked_array.cpp b/test/test_xchunked_array.cpp index 7da81fc69..8b0c7a4af 100644 --- a/test/test_xchunked_array.cpp +++ b/test/test_xchunked_array.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xbroadcast.hpp" #include "xtensor/xchunked_array.hpp" diff --git a/test/test_xchunked_view.cpp b/test/test_xchunked_view.cpp index 6a61f254b..c4d92dc9a 100644 --- a/test/test_xchunked_view.cpp +++ b/test/test_xchunked_view.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xchunked_array.hpp" #include "xtensor/xchunked_view.hpp" diff --git a/test/test_xcomplex.cpp b/test/test_xcomplex.cpp index 3f838b9b0..ea910c45c 100644 --- a/test/test_xcomplex.cpp +++ b/test/test_xcomplex.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include #include diff --git a/test/test_xcontainer_semantic.cpp b/test/test_xcontainer_semantic.cpp index c578fc7b6..1b1fc4a8d 100644 --- a/test/test_xcontainer_semantic.cpp +++ b/test/test_xcontainer_semantic.cpp @@ -6,9 +6,11 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_xsemantic.hpp" +TEST_SUITE_BEGIN("container_semantic"); + namespace xt { template @@ -19,671 +21,673 @@ namespace xt using storage_type = C; }; - using testing_types = ::testing::Types; - TYPED_TEST_SUITE(container_semantic, testing_types); + #define CONTAINER_SEMANTIC_TYPES xarray_dynamic, xtensor_dynamic - TYPED_TEST(container_semantic, a_plus_b) + TEST_CASE_TEMPLATE("a_plus_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major + row_major") { - SCOPED_TRACE("row_major + row_major"); TypeParam b = tester.a + tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major + column_major") { - SCOPED_TRACE("row_major + column_major"); TypeParam b = tester.a + tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major + central_major") { - SCOPED_TRACE("row_major + central_major"); TypeParam b = tester.a + tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major + unit_major") { - SCOPED_TRACE("row_major + unit_major"); TypeParam b = tester.a + tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_minus_b) + TEST_CASE_TEMPLATE("a_minus_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major - row_major") { - SCOPED_TRACE("row_major - row_major"); TypeParam b = tester.a - tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major - column_major") { - SCOPED_TRACE("row_major - column_major"); TypeParam b = tester.a - tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major - central_major") { - SCOPED_TRACE("row_major - central_major"); TypeParam b = tester.a - tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major - unit_major") { - SCOPED_TRACE("row_major - unit_major"); TypeParam b = tester.a - tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_times_b) + TEST_CASE_TEMPLATE("a_times_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major * row_major") { - SCOPED_TRACE("row_major * row_major"); TypeParam b = tester.a * tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major * column_major") { - SCOPED_TRACE("row_major * column_major"); TypeParam b = tester.a * tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major * central_major") { - SCOPED_TRACE("row_major * central_major"); TypeParam b = tester.a * tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major * unit_major") { - SCOPED_TRACE("row_major * unit_major"); TypeParam b = tester.a * tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_divide_by_b) + TEST_CASE_TEMPLATE("a_divide_by_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major / row_major") { - SCOPED_TRACE("row_major / row_major"); TypeParam b = tester.a / tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major / column_major") { - SCOPED_TRACE("row_major / column_major"); TypeParam b = tester.a / tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major / central_major") { - SCOPED_TRACE("row_major / central_major"); TypeParam b = tester.a / tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major / unit_major") { - SCOPED_TRACE("row_major / unit_major"); TypeParam b = tester.a / tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_bitwise_and_b) + TEST_CASE_TEMPLATE("a_bitwise_and_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major & row_major") { - SCOPED_TRACE("row_major & row_major"); TypeParam b = tester.a & tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major & column_major") { - SCOPED_TRACE("row_major & column_major"); TypeParam b = tester.a & tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major & central_major") { - SCOPED_TRACE("row_major & central_major"); TypeParam b = tester.a & tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major & unit_major") { - SCOPED_TRACE("row_major & unit_major"); TypeParam b = tester.a & tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_bitwise_or_b) + TEST_CASE_TEMPLATE("a_bitwise_or_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major | row_major") { - SCOPED_TRACE("row_major | row_major"); TypeParam b = tester.a | tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major | column_major") { - SCOPED_TRACE("row_major | column_major"); TypeParam b = tester.a | tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major | central_major") { - SCOPED_TRACE("row_major | central_major"); TypeParam b = tester.a | tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major | unit_major") { - SCOPED_TRACE("row_major | unit_major"); TypeParam b = tester.a | tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_bitwise_xor_b) + TEST_CASE_TEMPLATE("a_bitwise_xor_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major ^ row_major") { - SCOPED_TRACE("row_major ^ row_major"); TypeParam b = tester.a ^ tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major ^ column_major") { - SCOPED_TRACE("row_major ^ column_major"); TypeParam b = tester.a ^ tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major ^ central_major") { - SCOPED_TRACE("row_major ^ central_major"); TypeParam b = tester.a ^ tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major ^ unit_major") { - SCOPED_TRACE("row_major ^ unit_major"); TypeParam b = tester.a ^ tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_plus_equal_b) + TEST_CASE_TEMPLATE("a_plus_equal_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major += row_major") { - SCOPED_TRACE("row_major += row_major"); TypeParam b = tester.a; b += tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major += column_major") { - SCOPED_TRACE("row_major += column_major"); TypeParam b = tester.a; b += tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major += central_major") { - SCOPED_TRACE("row_major += central_major"); TypeParam b = tester.a; b += tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major += unit_major") { - SCOPED_TRACE("row_major += unit_major"); TypeParam b = tester.a; b += tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_minus_equal_b) + TEST_CASE_TEMPLATE("a_minus_equal_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major -= row_major") { - SCOPED_TRACE("row_major -= row_major"); TypeParam b = tester.a; b -= tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major -= column_major") { - SCOPED_TRACE("row_major -= column_major"); TypeParam b = tester.a; b -= tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major -= central_major") { - SCOPED_TRACE("row_major -= central_major"); TypeParam b = tester.a; b -= tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major -= unit_major") { - SCOPED_TRACE("row_major -= unit_major"); TypeParam b = tester.a; b -= tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_times_equal_b) + TEST_CASE_TEMPLATE("a_times_equal_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major *= row_major") { - SCOPED_TRACE("row_major *= row_major"); TypeParam b = tester.a; b *= tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major *= column_major") { - SCOPED_TRACE("row_major *= column_major"); TypeParam b = tester.a; b *= tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major *= central_major") { - SCOPED_TRACE("row_major *= central_major"); TypeParam b = tester.a; b *= tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major *= unit_major") { - SCOPED_TRACE("row_major *= unit_major"); TypeParam b = tester.a; b *= tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_divide_by_equal_b) + TEST_CASE_TEMPLATE("a_divide_by_equal_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major /= row_major") { - SCOPED_TRACE("row_major /= row_major"); TypeParam b = tester.a; b /= tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major /= column_major") { - SCOPED_TRACE("row_major /= column_major"); TypeParam b = tester.a; b /= tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major /= central_major") { - SCOPED_TRACE("row_major /= central_major"); TypeParam b = tester.a; b /= tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major /= unit_major") { - SCOPED_TRACE("row_major /= unit_major"); TypeParam b = tester.a; b /= tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_bitwise_and_equal_b) + TEST_CASE_TEMPLATE("a_bitwise_and_equal_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major &= row_major") { - SCOPED_TRACE("row_major &= row_major"); TypeParam b = tester.a; b &= tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major &= column_major") { - SCOPED_TRACE("row_major &= column_major"); TypeParam b = tester.a; b &= tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major &= central_major") { - SCOPED_TRACE("row_major &= central_major"); TypeParam b = tester.a; b &= tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major &= unit_major") { - SCOPED_TRACE("row_major &= unit_major"); TypeParam b = tester.a; b &= tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_bitwise_or_equal_b) + TEST_CASE_TEMPLATE("a_bitwise_or_equal_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major |= row_major") { - SCOPED_TRACE("row_major |= row_major"); TypeParam b = tester.a; b |= tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major |= column_major") { - SCOPED_TRACE("row_major |= column_major"); TypeParam b = tester.a; b |= tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major |= central_major") { - SCOPED_TRACE("row_major |= central_major"); TypeParam b = tester.a; b |= tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major |= unit_major") { - SCOPED_TRACE("row_major |= unit_major"); TypeParam b = tester.a; b |= tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, a_bitwise_xor_equal_b) + TEST_CASE_TEMPLATE("a_bitwise_xor_equal_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major ^= row_major") { - SCOPED_TRACE("row_major ^= row_major"); TypeParam b = tester.a; b ^= tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major ^= column_major") { - SCOPED_TRACE("row_major ^= column_major"); TypeParam b = tester.a; b ^= tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major ^= central_major") { - SCOPED_TRACE("row_major ^= central_major"); TypeParam b = tester.a; b ^= tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major ^= unit_major") { - SCOPED_TRACE("row_major ^= unit_major"); TypeParam b = tester.a; b ^= tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, assign_a_plus_b) + TEST_CASE_TEMPLATE("assign_a_plus_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major + row_major") { - SCOPED_TRACE("row_major + row_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a + tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major + column_major") { - SCOPED_TRACE("row_major + column_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a + tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major + central_major") { - SCOPED_TRACE("row_major + central_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a + tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major + unit_major") { - SCOPED_TRACE("row_major + unit_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a + tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, assign_a_minus_b) + TEST_CASE_TEMPLATE("assign_a_minus_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major - row_major") { - SCOPED_TRACE("row_major - row_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a - tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major - column_major") { - SCOPED_TRACE("row_major - column_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a - tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major - central_major") { - SCOPED_TRACE("row_major - central_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a - tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major - unit_major") { - SCOPED_TRACE("row_major - unit_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a - tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, assign_a_multiplies_b) + TEST_CASE_TEMPLATE("assign_a_multiplies_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major * row_major") { - SCOPED_TRACE("row_major * row_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a * tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major * column_major") { - SCOPED_TRACE("row_major * column_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a * tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major * central_major") { - SCOPED_TRACE("row_major * central_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a * tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major * unit_major") { - SCOPED_TRACE("row_major * unit_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a * tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, assign_a_divides_by_b) + TEST_CASE_TEMPLATE("assign_a_divides_by_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major / row_major") { - SCOPED_TRACE("row_major / row_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a / tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major / column_major") { - SCOPED_TRACE("row_major / column_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a / tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major / central_major") { - SCOPED_TRACE("row_major / central_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a / tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major / unit_major") { - SCOPED_TRACE("row_major / unit_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a / tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, assign_a_bitwise_and_b) + TEST_CASE_TEMPLATE("assign_a_bitwise_and_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major & row_major") { - SCOPED_TRACE("row_major & row_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a & tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major & column_major") { - SCOPED_TRACE("row_major & column_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a & tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major & central_major") { - SCOPED_TRACE("row_major & central_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a & tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major & unit_major") { - SCOPED_TRACE("row_major & unit_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a & tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, assign_a_bitwise_or_b) + TEST_CASE_TEMPLATE("assign_a_bitwise_or_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major | row_major") { - SCOPED_TRACE("row_major | row_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a | tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major | column_major") { - SCOPED_TRACE("row_major | column_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a | tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major | central_major") { - SCOPED_TRACE("row_major | central_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a | tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major | unit_major") { - SCOPED_TRACE("row_major | unit_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a | tester.ua; EXPECT_EQ(tester.res_ru, b); } } - TYPED_TEST(container_semantic, assign_a_bitwise_xor_b) + TEST_CASE_TEMPLATE("assign_a_bitwise_xor_b",TypeParam, xarray_dynamic, xtensor_dynamic) { operation_tester, TypeParam> tester; + SUBCASE("row_major ^ row_major") { - SCOPED_TRACE("row_major ^ row_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a ^ tester.ra; EXPECT_EQ(tester.res_rr, b); } + SUBCASE("row_major ^ column_major") { - SCOPED_TRACE("row_major ^ column_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a ^ tester.ca; EXPECT_EQ(tester.res_rc, b); } + SUBCASE("row_major ^ central_major") { - SCOPED_TRACE("row_major ^ central_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a ^ tester.cta; EXPECT_EQ(tester.res_rct, b); } + SUBCASE("row_major ^ unit_major") { - SCOPED_TRACE("row_major ^ unit_major"); TypeParam b(tester.ca.shape(), 0); b = tester.a ^ tester.ua; EXPECT_EQ(tester.res_ru, b); } } + + #undef CONTAINER_SEMANTIC_TYPES } +TEST_SUITE_END(); \ No newline at end of file diff --git a/test/test_xcsv.cpp b/test/test_xcsv.cpp index f356b25c1..50863fe05 100644 --- a/test/test_xcsv.cpp +++ b/test/test_xcsv.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include #include diff --git a/test/test_xdatesupport.cpp b/test/test_xdatesupport.cpp index b96461ff6..90b8a7b86 100644 --- a/test/test_xdatesupport.cpp +++ b/test/test_xdatesupport.cpp @@ -11,7 +11,7 @@ #warning "test_xdatesupport.cpp has been deactivated because it leads to internal compiler error" #else -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include diff --git a/test/test_xdynamic_view.cpp b/test/test_xdynamic_view.cpp index 80408200c..21df8c871 100644 --- a/test/test_xdynamic_view.cpp +++ b/test/test_xdynamic_view.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xbuilder.hpp" #include "xtensor/xio.hpp" diff --git a/test/test_xeval.cpp b/test/test_xeval.cpp index 559791415..a7e89349a 100644 --- a/test/test_xeval.cpp +++ b/test/test_xeval.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common.hpp" #include "xtensor/xtensor_config.hpp" #include "xtensor/xeval.hpp" @@ -302,4 +302,4 @@ namespace xt EXPECT_EQ(res_rvalue(2), 3); } } -} +} \ No newline at end of file diff --git a/test/test_xexception.cpp b/test/test_xexception.cpp index 45b7fc034..88b67cea4 100644 --- a/test/test_xexception.cpp +++ b/test/test_xexception.cpp @@ -13,7 +13,7 @@ #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xexception.hpp" #include "test_common_macros.hpp" @@ -33,7 +33,7 @@ namespace xt try { XTENSOR_ASSERT_MSG(false, "Intentional error"); - FAIL() << "No exception thrown."; + CHECK_MESSAGE(false, "no exception thrown"); } catch (std::runtime_error& e) { @@ -44,7 +44,7 @@ namespace xt try { XTENSOR_PRECONDITION(false, "Intentional error"); - FAIL() << "No exception thrown."; + CHECK_MESSAGE(false, "no exception thrown"); } catch (std::runtime_error& e) { diff --git a/test/test_xexpression.cpp b/test/test_xexpression.cpp index 8bb53684c..2cae05083 100644 --- a/test/test_xexpression.cpp +++ b/test/test_xexpression.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include #include "xtensor/xarray.hpp" diff --git a/test/test_xexpression_holder.cpp b/test/test_xexpression_holder.cpp index d7421d325..b1cdf9c9a 100644 --- a/test/test_xexpression_holder.cpp +++ b/test/test_xexpression_holder.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xexpression_holder.hpp" diff --git a/test/test_xexpression_traits.cpp b/test/test_xexpression_traits.cpp index 61cfb1437..fa0510192 100644 --- a/test/test_xexpression_traits.cpp +++ b/test/test_xexpression_traits.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" #include "xtensor/xfixed.hpp" diff --git a/test/test_xfixed.cpp b/test/test_xfixed.cpp index 665d28d58..20e6f337a 100644 --- a/test/test_xfixed.cpp +++ b/test/test_xfixed.cpp @@ -15,7 +15,6 @@ // an easy way to prevent compilation #ifndef VS_SKIP_XFIXED -#include "gtest/gtest.h" #include "test_common_macros.hpp" #include "xtensor/xadapt.hpp" #include "xtensor/xarray.hpp" diff --git a/test/test_xfunc_on_xexpression.cpp b/test/test_xfunc_on_xexpression.cpp index 77c35bb13..ba4a431b0 100644 --- a/test/test_xfunc_on_xexpression.cpp +++ b/test/test_xfunc_on_xexpression.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include diff --git a/test/test_xfunction.cpp b/test/test_xfunction.cpp index de9d5cf4b..c5ebdb9a7 100644 --- a/test/test_xfunction.cpp +++ b/test/test_xfunction.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xview.hpp" #include "test_common.hpp" @@ -76,24 +76,24 @@ namespace xt using shape_type = layout_result<>::shape_type; xfunction_features f; + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); shape_type sh = uninitialized_shape(3); bool trivial = (f.m_a + f.m_a).broadcast_shape(sh); EXPECT_EQ(sh, f.m_a.shape()); ASSERT_TRUE(trivial); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); shape_type sh = uninitialized_shape(3); bool trivial = (f.m_a + f.m_b).broadcast_shape(sh); EXPECT_EQ(sh, f.m_a.shape()); ASSERT_FALSE(trivial); } + SUBCASE("different dimensions") { - SCOPED_TRACE("different dimensions"); shape_type sh = uninitialized_shape(4); bool trivial = (f.m_a + f.m_c).broadcast_shape(sh); EXPECT_EQ(sh, f.m_c.shape()); @@ -170,22 +170,22 @@ namespace xt size_t j = f.m_a.shape()[1] - 1; size_t k = f.m_a.shape()[2] - 1; + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); int a = (f.m_a + f.m_a)(i, j, k); int b = f.m_a(i, j, k) + f.m_a(i, j, k); EXPECT_EQ(a, b); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); int a = (f.m_a + f.m_b)(i, j, k); int b = f.m_a(i, j, k) + f.m_b(i, 0, k); EXPECT_EQ(a, b); } + SUBCASE("different dimensions") { - SCOPED_TRACE("different dimensions"); int a = (f.m_a + f.m_c)(1, i, j, k); int b = f.m_a(i, j, k) + f.m_c(1, i, j, k); EXPECT_EQ(a, b); @@ -199,15 +199,15 @@ namespace xt size_t j = f.m_a.shape()[1] - 1; size_t k = f.m_a.shape()[2] - 1; + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); int a = (f.m_a + f.m_a)(i, j, k); int b = (f.m_a + f.m_a).unchecked(i, j, k); EXPECT_EQ(a, b); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); int a = (f.m_a + f.m_b)(i, j, k); int b = (f.m_a + f.m_b).unchecked(i, j, k); EXPECT_EQ(a, b); @@ -221,8 +221,8 @@ namespace xt size_t j = f.m_a.shape()[1] - 1; size_t k = f.m_a.shape()[2] - 1; + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); int a = (f.m_a + f.m_a).at(i, j, k); int b = f.m_a.at(i, j, k) + f.m_a.at(i, j, k); EXPECT_EQ(a, b); @@ -230,8 +230,8 @@ namespace xt XT_EXPECT_ANY_THROW((f.m_a + f.m_a).at(10, 10, 10)); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); int a = (f.m_a + f.m_b).at(i, j, k); int b = f.m_a.at(i, j, k) + f.m_b.at(i, 0, k); EXPECT_EQ(a, b); @@ -239,8 +239,8 @@ namespace xt XT_EXPECT_ANY_THROW((f.m_a + f.m_a).at(10, 10, 10)); } + SUBCASE("different dimensions") { - SCOPED_TRACE("different dimensions"); int a = (f.m_a + f.m_c).at(1, i, j, k); int b = f.m_a.at(i, j, k) + f.m_c.at(1, i, j, k); EXPECT_EQ(a, b); @@ -256,15 +256,15 @@ namespace xt size_t j = f.m_a.shape()[1]; size_t k = f.m_a.shape()[2]; + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); int a = (f.m_a + f.m_a)(0, 0, 0); int b = (f.m_a + f.m_a).periodic(i, j, k); EXPECT_EQ(a, b); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); int a = (f.m_a + f.m_b)(0, 0, 0); int b = (f.m_a + f.m_b).periodic(i, j, k); EXPECT_EQ(a, b); @@ -302,14 +302,14 @@ namespace xt size_t j = f.m_a.shape()[1]; size_t k = f.m_a.shape()[2]; + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); EXPECT_TRUE((f.m_a + f.m_a).in_bounds(0, 0, 0) == true); EXPECT_TRUE((f.m_a + f.m_a).in_bounds(i, j, k) == false); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); EXPECT_TRUE((f.m_a + f.m_b).in_bounds(0, 0, 0) == true); EXPECT_TRUE((f.m_a + f.m_b).in_bounds(i, j, k) == false); } @@ -323,16 +323,16 @@ namespace xt index[1] = f.m_a.shape()[1] - 1; index[2] = f.m_a.shape()[2] - 1; + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); int a = (f.m_a + f.m_a)[index]; int b = f.m_a[index] + f.m_a[index]; EXPECT_EQ(a, b); EXPECT_EQ(((f.m_a + f.m_a)[{0, 0, 0}]), (f.m_a[{0, 0, 0}] + f.m_a[{0, 0, 0}])); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); int a = (f.m_a + f.m_b)[index]; xindex index2 = index; index2[1] = 0; @@ -341,8 +341,8 @@ namespace xt EXPECT_EQ(((f.m_a + f.m_b)[{0, 0, 0}]), (f.m_a[{0, 0, 0}] + f.m_b[{0, 0, 0}])); } + SUBCASE("different dimensions") { - SCOPED_TRACE("different dimensions"); xindex index2(f.m_c.dimension()); index2[0] = 1; index2[1] = index[0]; @@ -374,18 +374,18 @@ namespace xt { xfunction_features f; + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); test_xfunction_iterator(f.m_a, f.m_a); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); test_xfunction_iterator(f.m_a, f.m_b); } + SUBCASE("different dimensions") { - SCOPED_TRACE("different dimensions"); test_xfunction_iterator(f.m_c, f.m_a); } } @@ -407,18 +407,18 @@ namespace xt { xfunction_features f; + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); test_xfunction_iterator_end(f.m_a, f.m_a); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); test_xfunction_iterator_end(f.m_a, f.m_b); } + SUBCASE("different dimensions") { - SCOPED_TRACE("different dimensions"); test_xfunction_iterator_end(f.m_c, f.m_a); } } diff --git a/test/test_xfunctor_adaptor.cpp b/test/test_xfunctor_adaptor.cpp index a4614545b..5756b26c4 100644 --- a/test/test_xfunctor_adaptor.cpp +++ b/test/test_xfunctor_adaptor.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xcomplex.hpp" diff --git a/test/test_xhistogram.cpp b/test/test_xhistogram.cpp index b9a096cb4..7b2d0c7ed 100644 --- a/test/test_xhistogram.cpp +++ b/test/test_xhistogram.cpp @@ -10,7 +10,7 @@ #include #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xtensor.hpp" #include "xtensor/xhistogram.hpp" #include "xtensor/xrandom.hpp" diff --git a/test/test_xindex_view.cpp b/test/test_xindex_view.cpp index 9fea13335..a0a72bc80 100644 --- a/test/test_xindex_view.cpp +++ b/test/test_xindex_view.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xadapt.hpp" #include "xtensor/xrandom.hpp" diff --git a/test/test_xinfo.cpp b/test/test_xinfo.cpp index a99aa1234..889c1e679 100644 --- a/test/test_xinfo.cpp +++ b/test/test_xinfo.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include #include diff --git a/test/test_xio.cpp b/test/test_xio.cpp index a9506fb55..42b096c0e 100644 --- a/test/test_xio.cpp +++ b/test/test_xio.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include #include diff --git a/test/test_xiterator.cpp b/test/test_xiterator.cpp index c04f736e8..5c7bd6b6e 100644 --- a/test/test_xiterator.cpp +++ b/test/test_xiterator.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" @@ -24,10 +24,6 @@ namespace xt using result_type = R; }; - using testing_types = ::testing::Types, column_major_result<>, - central_major_result<>, unit_shape_result<>>; - TYPED_TEST_SUITE(xiterator_test, testing_types); - using std::size_t; template @@ -54,38 +50,8 @@ namespace xt iter2++; } - EXPECT_EQ(*iter, expected) << "preincrement operator doesn't give expected result"; - EXPECT_EQ(*iter2, expected) << "postincrement operator doesn't give expected result"; - } - - TYPED_TEST(xiterator_test, increment) - { - typename TestFixture::result_type rm; - { - SCOPED_TRACE("same shape - row_major iterator"); - test_increment(rm, rm.shape()); - } - - { - SCOPED_TRACE("broadcasting shape - row_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_increment(rm, rm.shape()); - } - - { - SCOPED_TRACE("same shape - column_major iterator"); - test_increment(rm, rm.shape()); - } - - { - SCOPED_TRACE("broadcasting shape - column_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_increment(rm, rm.shape()); - } + CHECK_MESSAGE(*iter==expected, "preincrement operator doesn't give expected result"); + CHECK_MESSAGE(*iter2==expected, "postincrement operator doesn't give expected result"); } template @@ -110,39 +76,12 @@ namespace xt iter += nb_inc; auto iter3 = iter2 + nb_inc; - EXPECT_EQ(*iter, expected) << "preincrement operator doesn't give expected result"; - EXPECT_EQ(*iter3, expected) << "postincrement operator doesn't give expected result"; - EXPECT_EQ(iter2[nb_inc], expected) << "postincrement operator doesn't give expected result"; - } - - TYPED_TEST(xiterator_test, random_increment) - { - typename TestFixture::result_type rm; - { - SCOPED_TRACE("same shape - row_major iterator"); - test_random_increment(rm, rm.shape()); - } - { - SCOPED_TRACE("broadcasting shape - row_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_random_increment(rm, rm.shape()); - } - { - SCOPED_TRACE("same shape - column_major iterator"); - test_random_increment(rm, rm.shape()); - } + CHECK_MESSAGE(*iter==expected, "preincrement operator doesn't give expected result"); + CHECK_MESSAGE(*iter3==expected, "postincrement operator doesn't give expected result"); + CHECK_MESSAGE(iter2[nb_inc]==expected, "postincrement operator doesn't give expected result"); - { - SCOPED_TRACE("broadcasting shape - column_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_random_increment(rm, rm.shape()); - } } template @@ -161,40 +100,10 @@ namespace xt ++iter; } - EXPECT_EQ(iter, last) << "iterator doesn't reach the end"; + CHECK_MESSAGE(iter==last, "iterator doesn't reach the end"); EXPECT_FALSE(iter < last); } - TYPED_TEST(xiterator_test, end) - { - typename TestFixture::result_type rm; - { - SCOPED_TRACE("same shape - row_major iterator"); - test_end(rm, rm.shape()); - } - - { - SCOPED_TRACE("broadcasting shape - row_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_end(rm, sh); - } - - { - SCOPED_TRACE("same shape - column_major iterator"); - test_end(rm, rm.shape()); - } - - { - SCOPED_TRACE("broadcasting shape - column_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_end(rm, sh); - } - } - template void test_decrement(const R& result, const S& shape) { @@ -218,38 +127,8 @@ namespace xt ++iter; iter2++; } - EXPECT_EQ(*iter, expected) << "predecrement operator doesn't give expected result"; - EXPECT_EQ(*iter2, expected) << "postdecrement operator doesn't give expected result"; - } - - TYPED_TEST(xiterator_test, decrement) - { - typename TestFixture::result_type rm; - { - SCOPED_TRACE("same shape - row_major iterator"); - test_decrement(rm, rm.shape()); - } - - { - SCOPED_TRACE("broadcasting shape - row_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_decrement(rm, sh); - } - - { - SCOPED_TRACE("same shape - column_major iterator"); - test_decrement(rm, rm.shape()); - } - - { - SCOPED_TRACE("broadcasting shape - column_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_decrement(rm, sh); - } + CHECK_MESSAGE(*iter == expected, "predecrement operator doesn't give expected result"); + CHECK_MESSAGE(*iter2 == expected, "postdecrement operator doesn't give expected result"); } template @@ -275,38 +154,8 @@ namespace xt iter += nb_inc; auto iter3 = iter2 + nb_inc; - EXPECT_EQ(*iter, expected) << "predecrement operator doesn't give expected result"; - EXPECT_EQ(*iter3, expected) << "postdecrement operator doesn't give expected result"; - } - - TYPED_TEST(xiterator_test, random_decrement) - { - typename TestFixture::result_type rm; - { - SCOPED_TRACE("same shape - row_major iterator"); - test_random_decrement(rm, rm.shape()); - } - - { - SCOPED_TRACE("broadcasting shape - row_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_random_decrement(rm, sh); - } - - { - SCOPED_TRACE("same shape - column_major iterator"); - test_random_decrement(rm, rm.shape()); - } - - { - SCOPED_TRACE("broadcasting shape - column_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_random_decrement(rm, sh); - } + CHECK_MESSAGE(*iter == expected , "predecrement operator doesn't give expected result"); + CHECK_MESSAGE(*iter3 == expected , "postdecrement operator doesn't give expected result"); } template @@ -321,47 +170,218 @@ namespace xt auto iter = a.template rbegin(shape); auto last = a.template rend(shape); - EXPECT_EQ(*iter, data.back()) << "dereferencing rbegin does not result in last element"; - EXPECT_EQ(*last, data.front()) << "dereferencing rend does not result in first element"; + CHECK_MESSAGE(*iter==data.back(), "dereferencing rbegin does not result in last element"); + CHECK_MESSAGE(*last==data.front(), "dereferencing rend does not result in first element"); for (size_type i = 0; i < size; ++i) { ++iter; } - EXPECT_EQ(iter, last) << "reverse iterator doesn't reach the end"; + CHECK_MESSAGE(iter==last, "reverse iterator doesn't reach the end"); } - TYPED_TEST(xiterator_test, reverse_end) + #define XITERATOR_TEST_TYPES\ + row_major_result<>,\ + column_major_result<>,\ + central_major_result<>,\ + unit_shape_result<> + + TEST_SUITE("xiterator_test") { - typename TestFixture::result_type rm; + TEST_CASE_TEMPLATE("increment", TypeParam, XITERATOR_TEST_TYPES) { - SCOPED_TRACE("same shape - row_major iterator"); - test_rend(rm, rm.shape()); + using TestFixture = xiterator_test; + typename TestFixture::result_type rm; + SUBCASE("same shape - row_major iterator") + { + test_increment(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - row_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_increment(rm, rm.shape()); + } + + SUBCASE("same shape - column_major iterator") + { + test_increment(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - column_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_increment(rm, rm.shape()); + } } + + TEST_CASE_TEMPLATE("random_increment", TypeParam, XITERATOR_TEST_TYPES) { - SCOPED_TRACE("broadcasting shape - row_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_rend(rm, sh); + using TestFixture = xiterator_test; + typename TestFixture::result_type rm; + SUBCASE("same shape - row_major iterator") + { + test_random_increment(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - row_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_random_increment(rm, rm.shape()); + } + + SUBCASE("same shape - column_major iterator") + { + test_random_increment(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - column_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_random_increment(rm, rm.shape()); + } } + + TEST_CASE_TEMPLATE("end", TypeParam, XITERATOR_TEST_TYPES) { - SCOPED_TRACE("same shape - column_major iterator"); - test_rend(rm, rm.shape()); + using TestFixture = xiterator_test; + typename TestFixture::result_type rm; + SUBCASE("same shape - row_major iterator") + { + test_end(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - row_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_end(rm, sh); + } + + SUBCASE("same shape - column_major iterator") + { + test_end(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - column_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_end(rm, sh); + } } + + TEST_CASE_TEMPLATE("decrement", TypeParam, XITERATOR_TEST_TYPES) { - SCOPED_TRACE("broadcasting shape - column_major iterator"); - layout_result<>::shape_type sh = rm.shape(); - sh.insert(sh.begin(), 2); - sh.insert(sh.begin(), 4); - test_rend(rm, sh); + using TestFixture = xiterator_test; + typename TestFixture::result_type rm; + SUBCASE("same shape - row_major iterator") + { + test_decrement(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - row_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_decrement(rm, sh); + } + + SUBCASE("same shape - column_major iterator") + { + test_decrement(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - column_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_decrement(rm, sh); + } + } + + TEST_CASE_TEMPLATE("random_decrement", TypeParam, XITERATOR_TEST_TYPES) + { + using TestFixture = xiterator_test; + typename TestFixture::result_type rm; + SUBCASE("same shape - row_major iterator") + { + test_random_decrement(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - row_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_random_decrement(rm, sh); + } + + SUBCASE("same shape - column_major iterator") + { + test_random_decrement(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - column_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_random_decrement(rm, sh); + } + } + + + TEST_CASE_TEMPLATE("reverse_end", TypeParam, XITERATOR_TEST_TYPES) + { + using TestFixture = xiterator_test; + typename TestFixture::result_type rm; + SUBCASE("same shape - row_major iterator") + { + test_rend(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - row_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_rend(rm, sh); + } + + SUBCASE("same shape - column_major iterator") + { + test_rend(rm, rm.shape()); + } + + SUBCASE("broadcasting shape - column_major iterator") + { + layout_result<>::shape_type sh = rm.shape(); + sh.insert(sh.begin(), 2); + sh.insert(sh.begin(), 4); + test_rend(rm, sh); + } } } + + template void test_minus(const R& result, const S& shape) { @@ -383,29 +403,29 @@ namespace xt auto iter = a.template begin() + nb_inc; auto iter2 = a.template begin() + nb_inc2; - EXPECT_EQ(iter2 - iter, expected) << "operator- doesn't give expected result"; + CHECK_MESSAGE(iter2 - iter == expected, "operator- doesn't give expected result"); auto riter = a.template rbegin() + nb_inc; auto riter2 = a.template rbegin() + nb_inc2; - EXPECT_EQ(riter2 - riter, expected) << "operator- doesn't give expected result"; + CHECK_MESSAGE(riter2 - riter == expected, "operator- doesn't give expected result"); auto diff = a.template end() - a.template begin(); - EXPECT_EQ(size_type(diff), a.size()); + CHECK_EQ(size_type(diff), a.size()); auto rdiff = a.template rend() - a.template rbegin(); - EXPECT_EQ(size_type(rdiff), a.size()); + CHECK_EQ(size_type(rdiff), a.size()); } TEST(xiterator, row_major_minus) { row_major_result<> rm; + SUBCASE("same shape - row_major iterator") { - SCOPED_TRACE("same shape - row_major iterator"); test_minus(rm, rm.shape()); } + SUBCASE("broadcasting shape - row_major iterator") { - SCOPED_TRACE("broadcasting shape - row_major iterator"); layout_result<>::shape_type sh = rm.shape(); sh.insert(sh.begin(), 2); sh.insert(sh.begin(), 4); @@ -416,13 +436,13 @@ namespace xt TEST(xiterator, column_major_minus) { column_major_result<> rm; + SUBCASE("same shape - column_major iterator") { - SCOPED_TRACE("same shape - column_major iterator"); test_minus(rm, rm.shape()); } + SUBCASE("broadcasting shape - column_major iterator") { - SCOPED_TRACE("broadcasting shape - column_major iterator"); layout_result<>::shape_type sh = rm.shape(); sh.insert(sh.begin(), 2); sh.insert(sh.begin(), 4); @@ -490,15 +510,15 @@ namespace xt using vector_type = row_major_result<>::vector_type; xarray_adaptor a(rm.storage(), rm.shape(), rm.strides()); + SUBCASE("row_major iterator") { - SCOPED_TRACE("row_major iterator"); xarray dst(a.shape(), 1); std::copy(a.cbegin(), a.cend(), dst.begin()); EXPECT_EQ(a, dst); } + SUBCASE("column_major iterator") { - SCOPED_TRACE("column_major iterator"); xarray dst(a.shape(), 1); std::copy(a.cbegin(), a.cend(), dst.begin()); EXPECT_EQ(a, dst); @@ -511,15 +531,15 @@ namespace xt using vector_type = row_major_result<>::vector_type; xarray_adaptor a(rm.storage(), rm.shape(), rm.strides()); + SUBCASE("row_major iterator") { - SCOPED_TRACE("row_major iterator"); xarray dst(a.shape(), 1); std::copy(a.crbegin(), a.crend(), dst.rbegin()); EXPECT_EQ(a, dst); } + SUBCASE("column_major iterator") { - SCOPED_TRACE("column_major iterator"); xarray dst(a.shape(), 1); std::copy(a.crbegin(), a.crend(), dst.rbegin()); EXPECT_EQ(a, dst); diff --git a/test/test_xjson.cpp b/test/test_xjson.cpp index 68735a647..06e53ec3f 100644 --- a/test/test_xjson.cpp +++ b/test/test_xjson.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include diff --git a/test/test_xlayout.cpp b/test/test_xlayout.cpp index c287cb03b..e33d3c078 100644 --- a/test/test_xlayout.cpp +++ b/test/test_xlayout.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xio.hpp" #include "xtensor/xtensor.hpp" diff --git a/test/test_xmanipulation.cpp b/test/test_xmanipulation.cpp index 01a084ec5..5c65eda85 100644 --- a/test/test_xmanipulation.cpp +++ b/test/test_xmanipulation.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" diff --git a/test/test_xmasked_view.cpp b/test/test_xmasked_view.cpp index 5299ad750..f11111682 100644 --- a/test/test_xmasked_view.cpp +++ b/test/test_xmasked_view.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_common_macros.hpp" #include "xtensor/xoptional_assembly.hpp" #include "xtensor/xmasked_view.hpp" diff --git a/test/test_xmath.cpp b/test/test_xmath.cpp index 4b9a80957..279f0b5e7 100644 --- a/test/test_xmath.cpp +++ b/test/test_xmath.cpp @@ -10,7 +10,7 @@ #include #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xadapt.hpp" #include "xtensor/xoptional_assembly.hpp" @@ -330,8 +330,8 @@ namespace xt using array_type = xarray; array_type a = { {1.2, 2.3}, {3.4, 4.5} }; + SUBCASE("unary function") { - SCOPED_TRACE("unary function"); auto fexp = exp(a); using assign_traits = xassign_traits; #if XTENSOR_USE_XSIMD @@ -345,8 +345,8 @@ namespace xt #endif } + SUBCASE("binary function") { - SCOPED_TRACE("binary function"); auto fpow = pow(a, a); using assign_traits = xassign_traits; #if XTENSOR_USE_XSIMD @@ -360,8 +360,8 @@ namespace xt #endif } + SUBCASE("ternary function") { - SCOPED_TRACE("ternary function"); auto ffma = xt::fma(a, a, a); using assign_traits = xassign_traits; #if XTENSOR_USE_XSIMD diff --git a/test/test_xmath_result_type.cpp b/test/test_xmath_result_type.cpp index c54a66076..3bded76a1 100644 --- a/test/test_xmath_result_type.cpp +++ b/test/test_xmath_result_type.cpp @@ -9,7 +9,7 @@ #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" // The following disables the conversion warnings. These warnings // are legit and we don't want to avoid them with specific cast diff --git a/test/test_xmime.cpp b/test/test_xmime.cpp index ffe788394..3be9bcec6 100644 --- a/test/test_xmime.cpp +++ b/test/test_xmime.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include diff --git a/test/test_xnan_functions.cpp b/test/test_xnan_functions.cpp index ce349c106..37a46655b 100644 --- a/test/test_xnan_functions.cpp +++ b/test/test_xnan_functions.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #if (defined(__GNUC__) && !defined(__clang__)) #pragma GCC diagnostic push diff --git a/test/test_xnoalias.cpp b/test/test_xnoalias.cpp index 3d3557dac..2eb5725f0 100644 --- a/test/test_xnoalias.cpp +++ b/test/test_xnoalias.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xnoalias.hpp" #include "xtensor/xio.hpp" @@ -24,347 +24,349 @@ namespace xt using storage_type = C; }; - using testing_types = ::testing::Types; - TYPED_TEST_SUITE(xnoalias, testing_types); + #define XNOALIAS_TEST_TYPES xarray_dynamic, xtensor_dynamic - TYPED_TEST(xnoalias, a_plus_b) + TEST_SUITE("xnoalias") { - operation_tester, TypeParam> tester; + TEST_CASE_TEMPLATE("a_plus_b", TypeParam, XNOALIAS_TEST_TYPES) + { + operation_tester, TypeParam> tester; + + SUBCASE("row_major + row_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a + tester.ra; + EXPECT_EQ(tester.res_rr, b); + } + + SUBCASE("row_major + column_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a + tester.ca; + EXPECT_EQ(tester.res_rc, b); + } + + SUBCASE("row_major + central_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a + tester.cta; + EXPECT_EQ(tester.res_rct, b); + } + + SUBCASE("row_major + unit_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a + tester.ua; + EXPECT_EQ(tester.res_ru, b); + } + } + + TEST_CASE_TEMPLATE("a_minus_b", TypeParam, XNOALIAS_TEST_TYPES) + { + operation_tester, TypeParam> tester; + + SUBCASE("row_major - row_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a - tester.ra; + EXPECT_EQ(tester.res_rr, b); + } + + SUBCASE("row_major - column_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a - tester.ca; + EXPECT_EQ(tester.res_rc, b); + } + + SUBCASE("row_major - central_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a - tester.cta; + EXPECT_EQ(tester.res_rct, b); + } + + SUBCASE("row_major - unit_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a - tester.ua; + EXPECT_EQ(tester.res_ru, b); + } + } + + TEST_CASE_TEMPLATE("a_multiplies_b", TypeParam, XNOALIAS_TEST_TYPES) + { + operation_tester, TypeParam> tester; + + SUBCASE("row_major * row_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a * tester.ra; + EXPECT_EQ(tester.res_rr, b); + } + + SUBCASE("row_major * column_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a * tester.ca; + EXPECT_EQ(tester.res_rc, b); + } + + SUBCASE("row_major * central_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a * tester.cta; + EXPECT_EQ(tester.res_rct, b); + } + + SUBCASE("row_major * unit_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a * tester.ua; + EXPECT_EQ(tester.res_ru, b); + } + } + + TEST_CASE_TEMPLATE("a_divides_by_b", TypeParam, XNOALIAS_TEST_TYPES) + { + operation_tester, TypeParam> tester; + + SUBCASE("row_major / row_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a / tester.ra; + EXPECT_EQ(tester.res_rr, b); + } + + SUBCASE("row_major / column_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a / tester.ca; + EXPECT_EQ(tester.res_rc, b); + } + + SUBCASE("row_major / central_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a / tester.cta; + EXPECT_EQ(tester.res_rct, b); + } + + SUBCASE("row_major / unit_major") + { + TypeParam b(tester.ca.shape(), 0); + noalias(b) = tester.a / tester.ua; + EXPECT_EQ(tester.res_ru, b); + } + } + + TEST_CASE_TEMPLATE("a_plus_equal_b", TypeParam, XNOALIAS_TEST_TYPES) + { + operation_tester, TypeParam> tester; + + SUBCASE("row_major += row_major") + { + TypeParam b = tester.a; + noalias(b) += tester.ra; + EXPECT_EQ(tester.res_rr, b); + } + + SUBCASE("row_major += column_major") + { + TypeParam b = tester.a; + noalias(b) += tester.ca; + EXPECT_EQ(tester.res_rc, b); + } + + SUBCASE("row_major += central_major") + { + TypeParam b = tester.a; + noalias(b) += tester.cta; + EXPECT_EQ(tester.res_rct, b); + } + + SUBCASE("row_major += unit_major") + { + TypeParam b = tester.a; + noalias(b) += tester.ua; + EXPECT_EQ(tester.res_ru, b); + } + } + + TEST_CASE_TEMPLATE("a_minus_equal_b", TypeParam, XNOALIAS_TEST_TYPES) + { + operation_tester, TypeParam> tester; + + SUBCASE("row_major -= row_major") + { + TypeParam b = tester.a; + noalias(b) -= tester.ra; + EXPECT_EQ(tester.res_rr, b); + } + + SUBCASE("row_major -= column_major") + { + TypeParam b = tester.a; + noalias(b) -= tester.ca; + EXPECT_EQ(tester.res_rc, b); + } + + SUBCASE("row_major -= central_major") + { + TypeParam b = tester.a; + noalias(b) -= tester.cta; + EXPECT_EQ(tester.res_rct, b); + } + + SUBCASE("row_major -= unit_major") + { + TypeParam b = tester.a; + noalias(b) -= tester.ua; + EXPECT_EQ(tester.res_ru, b); + } + } + + TEST_CASE_TEMPLATE("a_times_equal_b", TypeParam, XNOALIAS_TEST_TYPES) + { + operation_tester, TypeParam> tester; + + SUBCASE("row_major *= row_major") + { + TypeParam b = tester.a; + noalias(b) *= tester.ra; + EXPECT_EQ(tester.res_rr, b); + } + + SUBCASE("row_major *= column_major") + { + TypeParam b = tester.a; + noalias(b) *= tester.ca; + EXPECT_EQ(tester.res_rc, b); + } + + SUBCASE("row_major *= central_major") + { + TypeParam b = tester.a; + noalias(b) *= tester.cta; + EXPECT_EQ(tester.res_rct, b); + } + + SUBCASE("row_major *= unit_major") + { + TypeParam b = tester.a; + noalias(b) *= tester.ua; + EXPECT_EQ(tester.res_ru, b); + } + } + + TEST_CASE_TEMPLATE("a_divide_by_equal_b", TypeParam, XNOALIAS_TEST_TYPES) + { + operation_tester, TypeParam> tester; + + SUBCASE("row_major /= row_major") + { + TypeParam b = tester.a; + noalias(b) /= tester.ra; + EXPECT_EQ(tester.res_rr, b); + } + + SUBCASE("row_major /= column_major") + { + TypeParam b = tester.a; + noalias(b) /= tester.ca; + EXPECT_EQ(tester.res_rc, b); + } + + SUBCASE("row_major /= central_major") + { + TypeParam b = tester.a; + noalias(b) /= tester.cta; + EXPECT_EQ(tester.res_rct, b); + } + + SUBCASE("row_major /= unit_major") + { + TypeParam b = tester.a; + noalias(b) /= tester.ua; + EXPECT_EQ(tester.res_ru, b); + } + } + + TEST_CASE("scalar_ops") + { + xarray a = {{1,2,3}, {4,5,6}, {7,8,9}}; + xarray b = {{1,2,3}, {4,5,6}, {7,8,9}}; + xarray c = {{1,2,3}, {4,5,6}, {7,8,9}}; + + xscalar one(1), five(5), twelve(12), seven(7), bhalf(0b00001111), bxor(0b01001111); + + xt::noalias(a) += 1; + b += 1; + xt::noalias(c) += one; + EXPECT_EQ(a, b); + EXPECT_EQ(a, c); + + xt::noalias(a) -= 5; + b -= 5; + xt::noalias(c) -= five; + EXPECT_EQ(a, b); + EXPECT_EQ(a, c); + + xt::noalias(a) *= 12; + b *= 12; + xt::noalias(c) *= twelve; + EXPECT_EQ(a, b); + EXPECT_EQ(a, c); + + xt::noalias(a) /= 7; + b /= 7; + xt::noalias(c) /= seven; + EXPECT_EQ(a, b); + EXPECT_EQ(a, c); + + xt::noalias(a) %= 7; + b %= 7; + xt::noalias(c) %= seven; + EXPECT_EQ(a, b); + EXPECT_EQ(a, c); + + xt::noalias(a) &= 0b00001111; + b &= 0b00001111; + xt::noalias(c) &= bhalf; + EXPECT_EQ(a, b); + EXPECT_EQ(a, c); + + xt::noalias(a) |= 0b00001111; + b |= 0b00001111; + xt::noalias(c) |= bhalf; + EXPECT_EQ(a, b); + EXPECT_EQ(a, c); + + xt::noalias(a) ^= 0b01001111; + b ^= 0b01001111; + xt::noalias(c) ^= bxor; + EXPECT_EQ(a, b); + EXPECT_EQ(a, c); + + xt::noalias(a) = 123; + b = 123; - { - SCOPED_TRACE("row_major + row_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a + tester.ra; - EXPECT_EQ(tester.res_rr, b); - } - - { - SCOPED_TRACE("row_major + column_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a + tester.ca; - EXPECT_EQ(tester.res_rc, b); - } - - { - SCOPED_TRACE("row_major + central_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a + tester.cta; - EXPECT_EQ(tester.res_rct, b); - } + EXPECT_EQ(a, b); + } + TEST_CASE("rvalue") { - SCOPED_TRACE("row_major + unit_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a + tester.ua; - EXPECT_EQ(tester.res_ru, b); - } - } - - TYPED_TEST(xnoalias, a_minus_b) - { - operation_tester, TypeParam> tester; + xarray a = {{1,2,3}, {4,5,6}, {7,8,9}}; + xarray b = {{1,2,3}, {4,5,6}, {7,8,9}}; - { - SCOPED_TRACE("row_major - row_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a - tester.ra; - EXPECT_EQ(tester.res_rr, b); - } - - { - SCOPED_TRACE("row_major - column_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a - tester.ca; - EXPECT_EQ(tester.res_rc, b); - } - - { - SCOPED_TRACE("row_major - central_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a - tester.cta; - EXPECT_EQ(tester.res_rct, b); - } - - { - SCOPED_TRACE("row_major - unit_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a - tester.ua; - EXPECT_EQ(tester.res_ru, b); - } - } - - TYPED_TEST(xnoalias, a_multiplies_b) - { - operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major * row_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a * tester.ra; - EXPECT_EQ(tester.res_rr, b); - } - - { - SCOPED_TRACE("row_major * column_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a * tester.ca; - EXPECT_EQ(tester.res_rc, b); - } - - { - SCOPED_TRACE("row_major * central_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a * tester.cta; - EXPECT_EQ(tester.res_rct, b); - } - - { - SCOPED_TRACE("row_major * unit_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a * tester.ua; - EXPECT_EQ(tester.res_ru, b); - } - } - - TYPED_TEST(xnoalias, a_divides_by_b) - { - operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major / row_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a / tester.ra; - EXPECT_EQ(tester.res_rr, b); - } - - { - SCOPED_TRACE("row_major / column_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a / tester.ca; - EXPECT_EQ(tester.res_rc, b); - } - - { - SCOPED_TRACE("row_major / central_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a / tester.cta; - EXPECT_EQ(tester.res_rct, b); - } - - { - SCOPED_TRACE("row_major / unit_major"); - TypeParam b(tester.ca.shape(), 0); - noalias(b) = tester.a / tester.ua; - EXPECT_EQ(tester.res_ru, b); - } - } - - TYPED_TEST(xnoalias, a_plus_equal_b) - { - operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major += row_major"); - TypeParam b = tester.a; - noalias(b) += tester.ra; - EXPECT_EQ(tester.res_rr, b); - } - - { - SCOPED_TRACE("row_major += column_major"); - TypeParam b = tester.a; - noalias(b) += tester.ca; - EXPECT_EQ(tester.res_rc, b); + xt::noalias(xt::view(a, 1)) += 10; + xt::view(b, 1) += 10; + + EXPECT_EQ(a, b); + + xt::noalias(xt::view(a, 1)) = 10; + xt::view(b, 1) = 10; + EXPECT_EQ(a, b); } - - { - SCOPED_TRACE("row_major += central_major"); - TypeParam b = tester.a; - noalias(b) += tester.cta; - EXPECT_EQ(tester.res_rct, b); - } - - { - SCOPED_TRACE("row_major += unit_major"); - TypeParam b = tester.a; - noalias(b) += tester.ua; - EXPECT_EQ(tester.res_ru, b); - } - } - - TYPED_TEST(xnoalias, a_minus_equal_b) - { - operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major -= row_major"); - TypeParam b = tester.a; - noalias(b) -= tester.ra; - EXPECT_EQ(tester.res_rr, b); - } - - { - SCOPED_TRACE("row_major -= column_major"); - TypeParam b = tester.a; - noalias(b) -= tester.ca; - EXPECT_EQ(tester.res_rc, b); - } - - { - SCOPED_TRACE("row_major -= central_major"); - TypeParam b = tester.a; - noalias(b) -= tester.cta; - EXPECT_EQ(tester.res_rct, b); - } - - { - SCOPED_TRACE("row_major -= unit_major"); - TypeParam b = tester.a; - noalias(b) -= tester.ua; - EXPECT_EQ(tester.res_ru, b); - } - } - - TYPED_TEST(xnoalias, a_times_equal_b) - { - operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major *= row_major"); - TypeParam b = tester.a; - noalias(b) *= tester.ra; - EXPECT_EQ(tester.res_rr, b); - } - - { - SCOPED_TRACE("row_major *= column_major"); - TypeParam b = tester.a; - noalias(b) *= tester.ca; - EXPECT_EQ(tester.res_rc, b); - } - - { - SCOPED_TRACE("row_major *= central_major"); - TypeParam b = tester.a; - noalias(b) *= tester.cta; - EXPECT_EQ(tester.res_rct, b); - } - - { - SCOPED_TRACE("row_major *= unit_major"); - TypeParam b = tester.a; - noalias(b) *= tester.ua; - EXPECT_EQ(tester.res_ru, b); - } - } - - TYPED_TEST(xnoalias, a_divide_by_equal_b) - { - operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major /= row_major"); - TypeParam b = tester.a; - noalias(b) /= tester.ra; - EXPECT_EQ(tester.res_rr, b); - } - - { - SCOPED_TRACE("row_major /= column_major"); - TypeParam b = tester.a; - noalias(b) /= tester.ca; - EXPECT_EQ(tester.res_rc, b); - } - - { - SCOPED_TRACE("row_major /= central_major"); - TypeParam b = tester.a; - noalias(b) /= tester.cta; - EXPECT_EQ(tester.res_rct, b); - } - - { - SCOPED_TRACE("row_major /= unit_major"); - TypeParam b = tester.a; - noalias(b) /= tester.ua; - EXPECT_EQ(tester.res_ru, b); - } - } - - TEST(xnoalias, scalar_ops) - { - xarray a = {{1,2,3}, {4,5,6}, {7,8,9}}; - xarray b = {{1,2,3}, {4,5,6}, {7,8,9}}; - xarray c = {{1,2,3}, {4,5,6}, {7,8,9}}; - - xscalar one(1), five(5), twelve(12), seven(7), bhalf(0b00001111), bxor(0b01001111); - - xt::noalias(a) += 1; - b += 1; - xt::noalias(c) += one; - EXPECT_EQ(a, b); - EXPECT_EQ(a, c); - - xt::noalias(a) -= 5; - b -= 5; - xt::noalias(c) -= five; - EXPECT_EQ(a, b); - EXPECT_EQ(a, c); - - xt::noalias(a) *= 12; - b *= 12; - xt::noalias(c) *= twelve; - EXPECT_EQ(a, b); - EXPECT_EQ(a, c); - - xt::noalias(a) /= 7; - b /= 7; - xt::noalias(c) /= seven; - EXPECT_EQ(a, b); - EXPECT_EQ(a, c); - - xt::noalias(a) %= 7; - b %= 7; - xt::noalias(c) %= seven; - EXPECT_EQ(a, b); - EXPECT_EQ(a, c); - - xt::noalias(a) &= 0b00001111; - b &= 0b00001111; - xt::noalias(c) &= bhalf; - EXPECT_EQ(a, b); - EXPECT_EQ(a, c); - - xt::noalias(a) |= 0b00001111; - b |= 0b00001111; - xt::noalias(c) |= bhalf; - EXPECT_EQ(a, b); - EXPECT_EQ(a, c); - - xt::noalias(a) ^= 0b01001111; - b ^= 0b01001111; - xt::noalias(c) ^= bxor; - EXPECT_EQ(a, b); - EXPECT_EQ(a, c); - - xt::noalias(a) = 123; - b = 123; - - EXPECT_EQ(a, b); - } - - TEST(xnoalias, rvalue) - { - xarray a = {{1,2,3}, {4,5,6}, {7,8,9}}; - xarray b = {{1,2,3}, {4,5,6}, {7,8,9}}; - - xt::noalias(xt::view(a, 1)) += 10; - xt::view(b, 1) += 10; - - EXPECT_EQ(a, b); - - xt::noalias(xt::view(a, 1)) = 10; - xt::view(b, 1) = 10; - EXPECT_EQ(a, b); } } diff --git a/test/test_xnorm.cpp b/test/test_xnorm.cpp index 51f45c26e..7d5b9e74e 100644 --- a/test/test_xnorm.cpp +++ b/test/test_xnorm.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xnorm.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xbuilder.hpp" diff --git a/test/test_xnpy.cpp b/test/test_xnpy.cpp index ef3f9e4dc..96e30a6c9 100644 --- a/test/test_xnpy.cpp +++ b/test/test_xnpy.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xnpy.hpp" #include "xtensor/xarray.hpp" @@ -65,8 +65,7 @@ namespace xt std::ifstream dstream(get_load_filename("files/xnpy_files/double")); auto darr_loaded_stream = load_npy(dstream); - EXPECT_TRUE(all(isclose(darr, darr_loaded_stream))) - << "Loading double numpy array from stream failed"; + CHECK_MESSAGE(all(isclose(darr, darr_loaded_stream)),"Loading double numpy array from stream failed"); dstream.close(); auto barr_loaded = load_npy(get_load_filename("files/xnpy_files/bool")); @@ -74,8 +73,7 @@ namespace xt std::ifstream bstream(get_load_filename("files/xnpy_files/bool")); auto barr_loaded_stream = load_npy(bstream); - EXPECT_TRUE(all(equal(barr, barr_loaded_stream))) - << "Loading boolean numpy array from stream failed"; + CHECK_MESSAGE(all(equal(barr, barr_loaded_stream)),"Loading boolean numpy array from stream failed"); bstream.close(); auto dfarr_loaded = load_npy(get_load_filename("files/xnpy_files/double_fortran")); @@ -132,7 +130,7 @@ namespace xt std::string barr_str = dump_npy(barr); std::string barr_disk = read_file(compare_name); - EXPECT_EQ(barr_str, barr_disk) << "Dumping boolean numpy file to string failed"; + CHECK_MESSAGE(barr_str==barr_disk,"Dumping boolean numpy file to string failed"); std::remove(filename.c_str()); @@ -147,7 +145,7 @@ namespace xt std::string ularr_str = dump_npy(ularr); std::string ularr_disk = read_file(compare_name); - EXPECT_EQ(ularr_str, ularr_disk) << "Dumping boolean numpy file to string failed"; + CHECK_MESSAGE(ularr_str==ularr_disk,"Dumping boolean numpy file to string failed"); std::remove(filename.c_str()); } diff --git a/test/test_xoperation.cpp b/test/test_xoperation.cpp index 20a083a40..cb2e5b517 100644 --- a/test/test_xoperation.cpp +++ b/test/test_xoperation.cpp @@ -7,7 +7,9 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" + +#include "test_common.hpp" +#include "test_common_macros.hpp" #include @@ -83,763 +85,777 @@ namespace xt using storage_type = C; }; - using testing_types = ::testing::Types, xtensor>; - TYPED_TEST_SUITE(operation, testing_types); - TYPED_TEST(operation, plus) - { - using shape_type = typename TypeParam::shape_type; - shape_type shape = {3, 2}; - TypeParam a(shape, 4.5); - double ref = +(a(0, 0)); - double actual = (+a)(0, 0); - EXPECT_EQ(ref, actual); - } - TYPED_TEST(operation, minus) - { - using shape_type = typename TypeParam::shape_type; - shape_type shape = {3, 2}; - TypeParam a(shape, 4.5); - double ref = -(a(0, 0)); - double actual = (-a)(0, 0); - EXPECT_EQ(ref, actual); - } + template + struct int_rebind; - TYPED_TEST(operation, add) + template <> + struct int_rebind> { - using shape_type = typename TypeParam::shape_type; - shape_type shape = {3, 2}; - TypeParam a(shape, 4.5); - TypeParam b(shape, 1.3); - EXPECT_EQ((a + b)(0, 0), a(0, 0) + b(0, 0)); + using type = xarray; + }; - double sb = 1.2; - EXPECT_EQ((a + sb)(0, 0), a(0, 0) + sb); + template <> + struct int_rebind> + { + using type = xtensor; + }; - double sa = 4.6; - EXPECT_EQ((sa + b)(0, 0), sa + b(0, 0)); - } + template + using int_rebind_t = typename int_rebind::type; - TYPED_TEST(operation, subtract) + struct vtype { - using shape_type = typename TypeParam::shape_type; - shape_type shape = {3, 2}; - TypeParam a(shape, 4.5); - TypeParam b(shape, 1.3); - EXPECT_EQ((a - b)(0, 0), a(0, 0) - b(0, 0)); + double a = 0; + size_t b = 0; + + explicit operator double() const { return a; } + }; - double sb = 1.2; - EXPECT_EQ((a - sb)(0, 0), a(0, 0) - sb); - double sa = 4.6; - EXPECT_EQ((sa - b)(0, 0), sa - b(0, 0)); - } + using xarray_type = xarray; + using xtensor_2_type = xtensor; - TYPED_TEST(operation, multiply) + #define XOPERATION_TEST_TYPES xarray_type, xtensor_2_type + + TEST_SUITE("operation") { - using shape_type = typename TypeParam::shape_type; - shape_type shape = {3, 2}; - TypeParam a(shape, 4.5); - TypeParam b(shape, 1.3); - EXPECT_EQ((a * b)(0, 0), a(0, 0) * b(0, 0)); + TEST_CASE_TEMPLATE("plus", TypeParam, XOPERATION_TEST_TYPES) + { + using shape_type = typename TypeParam::shape_type; + shape_type shape = {3, 2}; + TypeParam a(shape, 4.5); + double ref = +(a(0, 0)); + double actual = (+a)(0, 0); + EXPECT_EQ(ref, actual); + } - double sb = 1.2; - EXPECT_EQ((a * sb)(0, 0), a(0, 0) * sb); + TEST_CASE_TEMPLATE("minus", TypeParam, XOPERATION_TEST_TYPES) + { + using shape_type = typename TypeParam::shape_type; + shape_type shape = {3, 2}; + TypeParam a(shape, 4.5); + double ref = -(a(0, 0)); + double actual = (-a)(0, 0); + EXPECT_EQ(ref, actual); + } - double sa = 4.6; - EXPECT_EQ((sa * b)(0, 0), sa * b(0, 0)); - } + TEST_CASE_TEMPLATE("add", TypeParam, XOPERATION_TEST_TYPES) + { + using shape_type = typename TypeParam::shape_type; + shape_type shape = {3, 2}; + TypeParam a(shape, 4.5); + TypeParam b(shape, 1.3); + EXPECT_EQ((a + b)(0, 0), a(0, 0) + b(0, 0)); - TYPED_TEST(operation, divide) - { - using shape_type = typename TypeParam::shape_type; - shape_type shape = {3, 2}; - TypeParam a(shape, 4.5); - TypeParam b(shape, 1.3); - EXPECT_EQ((a / b)(0, 0), a(0, 0) / b(0, 0)); + double sb = 1.2; + EXPECT_EQ((a + sb)(0, 0), a(0, 0) + sb); - double sb = 1.2; - EXPECT_EQ((a / sb)(0, 0), a(0, 0) / sb); + double sa = 4.6; + EXPECT_EQ((sa + b)(0, 0), sa + b(0, 0)); + } - double sa = 4.6; - EXPECT_EQ((sa / b)(0, 0), sa / b(0, 0)); - } + TEST_CASE_TEMPLATE("subtract", TypeParam, XOPERATION_TEST_TYPES) + { + using shape_type = typename TypeParam::shape_type; + shape_type shape = {3, 2}; + TypeParam a(shape, 4.5); + TypeParam b(shape, 1.3); + EXPECT_EQ((a - b)(0, 0), a(0, 0) - b(0, 0)); - TYPED_TEST(operation, modulus) - { - using int_container = xop_test::rebind_container_t; - using shape_type = typename int_container::shape_type; + double sb = 1.2; + EXPECT_EQ((a - sb)(0, 0), a(0, 0) - sb); - shape_type shape = {3, 2}; - int_container a(shape, 11); - int_container b(shape, 3); - EXPECT_EQ((a % b)(0, 0), a(0, 0) % b(0, 0)); + double sa = 4.6; + EXPECT_EQ((sa - b)(0, 0), sa - b(0, 0)); + } - int sb = 3; - EXPECT_EQ((a % sb)(0, 0), a(0, 0) % sb); + TEST_CASE_TEMPLATE("multiply", TypeParam, XOPERATION_TEST_TYPES) + { + using shape_type = typename TypeParam::shape_type; + shape_type shape = {3, 2}; + TypeParam a(shape, 4.5); + TypeParam b(shape, 1.3); + EXPECT_EQ((a * b)(0, 0), a(0, 0) * b(0, 0)); - int sa = 11; - EXPECT_EQ((sa % b)(0, 0), sa % b(0, 0)); - } + double sb = 1.2; + EXPECT_EQ((a * sb)(0, 0), a(0, 0) * sb); - template - struct int_rebind; + double sa = 4.6; + EXPECT_EQ((sa * b)(0, 0), sa * b(0, 0)); + } - template <> - struct int_rebind> - { - using type = xarray; - }; + TEST_CASE_TEMPLATE("divide", TypeParam, XOPERATION_TEST_TYPES) + { + using shape_type = typename TypeParam::shape_type; + shape_type shape = {3, 2}; + TypeParam a(shape, 4.5); + TypeParam b(shape, 1.3); + EXPECT_EQ((a / b)(0, 0), a(0, 0) / b(0, 0)); - template <> - struct int_rebind> - { - using type = xtensor; - }; + double sb = 1.2; + EXPECT_EQ((a / sb)(0, 0), a(0, 0) / sb); - template - using int_rebind_t = typename int_rebind::type; + double sa = 4.6; + EXPECT_EQ((sa / b)(0, 0), sa / b(0, 0)); + } - TYPED_TEST(operation, bitwise_and) - { - using int_tensor = int_rebind_t; - using shape_type = typename int_tensor::shape_type; - shape_type shape = {3, 2}; - int_tensor a(shape, 14); - int_tensor b(shape, 15); - EXPECT_EQ((a & b)(0, 0), a(0, 0) & b(0, 0)); - - int sb = 48; - EXPECT_EQ((a & sb)(0, 0), a(0, 0) & sb); - - int sa = 24; - EXPECT_EQ((sa & b)(0, 0), sa & b(0, 0)); - } + TEST_CASE_TEMPLATE("modulus", TypeParam, XOPERATION_TEST_TYPES) + { + using int_container = xop_test::rebind_container_t; + using shape_type = typename int_container::shape_type; - TYPED_TEST(operation, bitwise_or) - { - using int_tensor = int_rebind_t; - using shape_type = typename int_tensor::shape_type; - shape_type shape = {3, 2}; - int_tensor a(shape, 14); - int_tensor b(shape, 15); - EXPECT_EQ((a | b)(0, 0), a(0, 0) | b(0, 0)); - - int sb = 48; - EXPECT_EQ((a | sb)(0, 0), a(0, 0) | sb); - - int sa = 24; - EXPECT_EQ((sa | b)(0, 0), sa | b(0, 0)); - } + shape_type shape = {3, 2}; + int_container a(shape, 11); + int_container b(shape, 3); + EXPECT_EQ((a % b)(0, 0), a(0, 0) % b(0, 0)); - TYPED_TEST(operation, bitwise_xor) - { - using int_tensor = int_rebind_t; - using shape_type = typename int_tensor::shape_type; - shape_type shape = {3, 2}; - int_tensor a(shape, 14); - int_tensor b(shape, 15); - EXPECT_EQ((a ^ b)(0, 0), a(0, 0) ^ b(0, 0)); - - int sb = 48; - EXPECT_EQ((a ^ sb)(0, 0), a(0, 0) ^ sb); - - int sa = 24; - EXPECT_EQ((sa ^ b)(0, 0), sa ^ b(0, 0)); - } + int sb = 3; + EXPECT_EQ((a % sb)(0, 0), a(0, 0) % sb); - TYPED_TEST(operation, bitwise_not) - { - using int_tensor = int_rebind_t; - using shape_type = typename int_tensor::shape_type; - shape_type shape = {3, 2}; - int_tensor a(shape, 15); - EXPECT_EQ((~a)(0, 0), ~(a(0, 0))); - } + int sa = 11; + EXPECT_EQ((sa % b)(0, 0), sa % b(0, 0)); + } - TYPED_TEST(operation, less) - { - using container_1d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - container_1d a = {1, 2, 3, 4, 5}; - bool_container expected = {1, 1, 1, 0, 0}; - bool_container b = a < 4; - EXPECT_EQ(expected, b); - bool_container b2 = less(a, 4); - EXPECT_EQ(expected, b2); - } - TYPED_TEST(operation, less_equal) - { - using container_1d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - container_1d a = {1, 2, 3, 4, 5}; - bool_container expected = {1, 1, 1, 1, 0}; - bool_container b = a <= 4; - EXPECT_EQ(expected, b); - bool_container b2 = less_equal(a, 4); - EXPECT_EQ(expected, b2); - } + TEST_CASE_TEMPLATE("bitwise_and", TypeParam, XOPERATION_TEST_TYPES) + { + using int_tensor = int_rebind_t; + using shape_type = typename int_tensor::shape_type; + shape_type shape = {3, 2}; + int_tensor a(shape, 14); + int_tensor b(shape, 15); + EXPECT_EQ((a & b)(0, 0), a(0, 0) & b(0, 0)); + + int sb = 48; + EXPECT_EQ((a & sb)(0, 0), a(0, 0) & sb); + + int sa = 24; + EXPECT_EQ((sa & b)(0, 0), sa & b(0, 0)); + } - TYPED_TEST(operation, greater) - { - using container_1d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - container_1d a = {1, 2, 3, 4, 5}; - bool_container expected = {0, 0, 0, 0, 1}; - bool_container b = a > 4; - EXPECT_EQ(expected, b); - bool_container b2 = greater(a, 4); - EXPECT_EQ(expected, b2); - } + TEST_CASE_TEMPLATE("bitwise_or", TypeParam, XOPERATION_TEST_TYPES) + { + using int_tensor = int_rebind_t; + using shape_type = typename int_tensor::shape_type; + shape_type shape = {3, 2}; + int_tensor a(shape, 14); + int_tensor b(shape, 15); + EXPECT_EQ((a | b)(0, 0), a(0, 0) | b(0, 0)); + + int sb = 48; + EXPECT_EQ((a | sb)(0, 0), a(0, 0) | sb); + + int sa = 24; + EXPECT_EQ((sa | b)(0, 0), sa | b(0, 0)); + } - TYPED_TEST(operation, greater_equal) - { - using container_1d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - container_1d a = {1, 2, 3, 4, 5}; - bool_container expected = {0, 0, 0, 1, 1}; - bool_container b = a >= 4; - EXPECT_EQ(expected, b); - bool_container b2 = greater_equal(a, 4); - EXPECT_EQ(expected, b2); - } + TEST_CASE_TEMPLATE("bitwise_xor", TypeParam, XOPERATION_TEST_TYPES) + { + using int_tensor = int_rebind_t; + using shape_type = typename int_tensor::shape_type; + shape_type shape = {3, 2}; + int_tensor a(shape, 14); + int_tensor b(shape, 15); + EXPECT_EQ((a ^ b)(0, 0), a(0, 0) ^ b(0, 0)); + + int sb = 48; + EXPECT_EQ((a ^ sb)(0, 0), a(0, 0) ^ sb); + + int sa = 24; + EXPECT_EQ((sa ^ b)(0, 0), sa ^ b(0, 0)); + } - TYPED_TEST(operation, negate) - { - using container_1d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - container_1d a = {1, 2, 3, 4, 5}; - bool_container expected = {1, 1, 1, 0, 0}; - bool_container b = !(a >= 4); - EXPECT_EQ(expected, b); - } + TEST_CASE_TEMPLATE("bitwise_not", TypeParam, XOPERATION_TEST_TYPES) + { + using int_tensor = int_rebind_t; + using shape_type = typename int_tensor::shape_type; + shape_type shape = {3, 2}; + int_tensor a(shape, 15); + EXPECT_EQ((~a)(0, 0), ~(a(0, 0))); + } - TYPED_TEST(operation, equal) - { - using container_1d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - container_1d a = {1, 2, 3, 4, 5}; - bool_container expected = {0, 0, 0, 1, 0}; - bool_container b = equal(a, 4); - EXPECT_EQ(expected, b); - - container_1d other = {1, 2, 3, 0, 0}; - bool_container b_2 = equal(a, other); - bool_container expected_2 = {1, 1, 1, 0, 0}; - EXPECT_EQ(expected_2, b_2); - } + TEST_CASE_TEMPLATE("less", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + container_1d a = {1, 2, 3, 4, 5}; + bool_container expected = {1, 1, 1, 0, 0}; + bool_container b = a < 4; + EXPECT_EQ(expected, b); + bool_container b2 = less(a, 4); + EXPECT_EQ(expected, b2); + } - TYPED_TEST(operation, not_equal) - { - using container_1d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - container_1d a = {1, 2, 3, 4, 5}; - bool_container expected = {1, 1, 1, 0, 1}; - bool_container b = not_equal(a, 4); - EXPECT_EQ(expected, b); - - container_1d other = {1, 2, 3, 0, 0}; - bool_container b_2 = not_equal(a, other); - bool_container expected_2 = {0, 0, 0, 1, 1}; - EXPECT_EQ(expected_2, b_2); - } + TEST_CASE_TEMPLATE("less_equal", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + container_1d a = {1, 2, 3, 4, 5}; + bool_container expected = {1, 1, 1, 1, 0}; + bool_container b = a <= 4; + EXPECT_EQ(expected, b); + bool_container b2 = less_equal(a, 4); + EXPECT_EQ(expected, b2); + } - TYPED_TEST(operation, logical_and) - { - using container_1d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - bool_container a = {0, 0, 0, 1, 0}; - bool_container expected = {0, 0, 0, 0, 0}; - bool_container b = a && false; - bool_container c = a && a; - EXPECT_EQ(expected, b); - EXPECT_EQ(c, a); - } + TEST_CASE_TEMPLATE("greater", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + container_1d a = {1, 2, 3, 4, 5}; + bool_container expected = {0, 0, 0, 0, 1}; + bool_container b = a > 4; + EXPECT_EQ(expected, b); + bool_container b2 = greater(a, 4); + EXPECT_EQ(expected, b2); + } - TYPED_TEST(operation, logical_or) - { - using container_1d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - bool_container a = {0, 0, 0, 1, 0}; - bool_container other = {0, 0, 0, 0, 0}; - bool_container b = a || other; - bool_container c = a || false; - bool_container d = a || true; - EXPECT_EQ(b, a); - EXPECT_EQ(c, a); - - bool_container expected = {1, 1, 1, 1, 1}; - EXPECT_EQ(expected, d); - } + TEST_CASE_TEMPLATE("greater_equal", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + container_1d a = {1, 2, 3, 4, 5}; + bool_container expected = {0, 0, 0, 1, 1}; + bool_container b = a >= 4; + EXPECT_EQ(expected, b); + bool_container b2 = greater_equal(a, 4); + EXPECT_EQ(expected, b2); + } - TYPED_TEST(operation, any) - { - using container_1d = redim_container_t; - using int_container = xop_test::rebind_container_t; - using int_container_2d = xop_test::rebind_container_t; - int_container a = {0, 0, 3}; - EXPECT_EQ(true, any(a)); - int_container_2d b = {{0, 0, 0}, {0, 0, 0}}; - EXPECT_EQ(false, any(b)); - } + TEST_CASE_TEMPLATE("negate", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + container_1d a = {1, 2, 3, 4, 5}; + bool_container expected = {1, 1, 1, 0, 0}; + bool_container b = !(a >= 4); + EXPECT_EQ(expected, b); + } - TYPED_TEST(operation, minimum) - { - using container_1d = redim_container_t; - using int_container = xop_test::rebind_container_t; - int_container a = {0, 0, 3}; - int_container b = {-1, 0, 10}; - int_container expected = {-1, 0, 3}; - EXPECT_TRUE(all(equal(minimum(a, b), expected))); - } + TEST_CASE_TEMPLATE("equal", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + container_1d a = {1, 2, 3, 4, 5}; + bool_container expected = {0, 0, 0, 1, 0}; + bool_container b = equal(a, 4); + EXPECT_EQ(expected, b); + + container_1d other = {1, 2, 3, 0, 0}; + bool_container b_2 = equal(a, other); + bool_container expected_2 = {1, 1, 1, 0, 0}; + EXPECT_EQ(expected_2, b_2); + } - TYPED_TEST(operation, maximum) - { - using container_1d = redim_container_t; - using int_container = xop_test::rebind_container_t; - int_container a = {0, 0, 3}; - int_container b = {-1, 0, 10}; - int_container expected = {0, 0, 10}; - int_container expected_2 = {0, 1, 10}; - EXPECT_TRUE(all(equal(maximum(a, b), expected))); - EXPECT_TRUE(all(equal(maximum(arange(0, 3), b), expected_2))); - } + TEST_CASE_TEMPLATE("not_equal", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + container_1d a = {1, 2, 3, 4, 5}; + bool_container expected = {1, 1, 1, 0, 1}; + bool_container b = not_equal(a, 4); + EXPECT_EQ(expected, b); + + container_1d other = {1, 2, 3, 0, 0}; + bool_container b_2 = not_equal(a, other); + bool_container expected_2 = {0, 0, 0, 1, 1}; + EXPECT_EQ(expected_2, b_2); + } - TYPED_TEST(operation, amax) - { - using int_container_2d = xop_test::rebind_container_t; - using container_1d = redim_container_t; - using int_container_1d = xop_test::rebind_container_t; - int_container_2d a = {{0, 0, 3}, {1, 2, 10}}; - EXPECT_EQ(10, amax(a)()); - int_container_1d e1 = {1, 2, 10}; - EXPECT_EQ(e1, amax(a, {0})); - int_container_1d e2 = {3, 10}; - EXPECT_EQ(e2, amax(a, {1})); - } + TEST_CASE_TEMPLATE("logical_and", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + bool_container a = {0, 0, 0, 1, 0}; + bool_container expected = {0, 0, 0, 0, 0}; + bool_container b = a && false; + bool_container c = a && a; + EXPECT_EQ(expected, b); + EXPECT_EQ(c, a); + } - TYPED_TEST(operation, amin) - { - using int_container_2d = xop_test::rebind_container_t; - using container_1d = redim_container_t; - using int_container_1d = xop_test::rebind_container_t; - int_container_2d a = {{0, 0, 3}, {1, 2, 10}}; - EXPECT_EQ(0, amin(a)()); - int_container_1d e1 = {0, 0, 3}; - EXPECT_EQ(e1, amin(a, {0})); - int_container_1d e2 = {0, 1}; - EXPECT_EQ(e2, amin(a, {1})); - } + TEST_CASE_TEMPLATE("logical_or", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + bool_container a = {0, 0, 0, 1, 0}; + bool_container other = {0, 0, 0, 0, 0}; + bool_container b = a || other; + bool_container c = a || false; + bool_container d = a || true; + EXPECT_EQ(b, a); + EXPECT_EQ(c, a); + + bool_container expected = {1, 1, 1, 1, 1}; + EXPECT_EQ(expected, d); + } - TYPED_TEST(operation, all) - { - using int_container_2d = xop_test::rebind_container_t; - using container_1d = redim_container_t; - using int_container_1d = xop_test::rebind_container_t; - int_container_1d a = {1, 1, 3}; - EXPECT_EQ(true, all(a)); - int_container_2d b = {{0, 2, 1}, {2, 1, 0}}; - EXPECT_EQ(false, all(b)); - } + TEST_CASE_TEMPLATE("any", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using int_container = xop_test::rebind_container_t; + using int_container_2d = xop_test::rebind_container_t; + int_container a = {0, 0, 3}; + EXPECT_EQ(true, any(a)); + int_container_2d b = {{0, 0, 0}, {0, 0, 0}}; + EXPECT_EQ(false, any(b)); + } - TYPED_TEST(operation, all_layout) - { - xarray a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - xarray b = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; - EXPECT_EQ(a(0, 1), b(0, 1)); - EXPECT_TRUE(all(equal(a, b))); - } + TEST_CASE_TEMPLATE("minimum", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using int_container = xop_test::rebind_container_t; + int_container a = {0, 0, 3}; + int_container b = {-1, 0, 10}; + int_container expected = {-1, 0, 3}; + EXPECT_TRUE(all(equal(minimum(a, b), expected))); + } - TYPED_TEST(operation, nonzero) - { - using int_container_2d = xop_test::rebind_container_t; - using container_1d = redim_container_t; - using int_container_1d = xop_test::rebind_container_t; - using container_3d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - using shape_type = typename container_3d::shape_type; - - int_container_1d a = {1, 0, 3}; - std::vector> expected = {{0, 2}}; - EXPECT_EQ(expected, nonzero(a)); - - int_container_2d b = {{0, 2, 1}, {2, 1, 0}}; - std::vector> expected_b = {{0, 0, 1, 1}, {1, 2, 0, 1}}; - EXPECT_EQ(expected_b, nonzero(b)); - - auto c = equal(b, 0); - std::vector> expected_c = {{0, 1}, {0, 2}}; - EXPECT_EQ(expected_c, nonzero(c)); - - shape_type s = {3, 3, 3}; - bool_container d(s); - std::fill(d.begin(), d.end(), true); - - auto d_nz = nonzero(d); - EXPECT_EQ(size_t(3), d_nz.size()); - EXPECT_EQ(size_t(27 * 27 * 27), d_nz[0].size() * d_nz[1].size() * d_nz[2].size()); - } + TEST_CASE_TEMPLATE("maximum", TypeParam, XOPERATION_TEST_TYPES) + { + using container_1d = redim_container_t; + using int_container = xop_test::rebind_container_t; + int_container a = {0, 0, 3}; + int_container b = {-1, 0, 10}; + int_container expected = {0, 0, 10}; + int_container expected_2 = {0, 1, 10}; + EXPECT_TRUE(all(equal(maximum(a, b), expected))); + EXPECT_TRUE(all(equal(maximum(arange(0, 3), b), expected_2))); + } - TYPED_TEST(operation, where_only_condition) - { - using int_container_2d = xop_test::rebind_container_t; - int_container_2d a = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; - std::vector> expected = {{0, 1, 2}, {0, 1, 2}}; - EXPECT_EQ(expected, where(a)); - } + TEST_CASE_TEMPLATE("amax", TypeParam, XOPERATION_TEST_TYPES) + { + using int_container_2d = xop_test::rebind_container_t; + using container_1d = redim_container_t; + using int_container_1d = xop_test::rebind_container_t; + int_container_2d a = {{0, 0, 3}, {1, 2, 10}}; + EXPECT_EQ(10, amax(a)()); + int_container_1d e1 = {1, 2, 10}; + EXPECT_EQ(e1, amax(a, {0})); + int_container_1d e2 = {3, 10}; + EXPECT_EQ(e2, amax(a, {1})); + } - TYPED_TEST(operation, where) - { - TypeParam a = { { 1, 2, 3 },{ 0, 1, 0 },{ 0, 4, 1 } }; - double b = 1.0; - TypeParam res = where(a > b, b, a); - TypeParam expected = { { 1, 1, 1 },{ 0, 1, 0 },{ 0, 1, 1 } }; - EXPECT_EQ(expected, res); - -#ifdef XTENSOR_USE_XSIMD - // This will fail to compile if simd is broken for conditional_ternary - auto func = where(a > b, b, a); - auto s = func.template load_simd(0); - (void)s; - - using assign_traits = xassign_traits; - - EXPECT_TRUE(assign_traits::simd_linear_assign()); -#endif - } + TEST_CASE_TEMPLATE("amin", TypeParam, XOPERATION_TEST_TYPES) + { + using int_container_2d = xop_test::rebind_container_t; + using container_1d = redim_container_t; + using int_container_1d = xop_test::rebind_container_t; + int_container_2d a = {{0, 0, 3}, {1, 2, 10}}; + EXPECT_EQ(0, amin(a)()); + int_container_1d e1 = {0, 0, 3}; + EXPECT_EQ(e1, amin(a, {0})); + int_container_1d e2 = {0, 1}; + EXPECT_EQ(e2, amin(a, {1})); + } - TYPED_TEST(operation, where_optional) - { - using opt_type = xoptional_assembly>; - auto missing = xtl::missing(); - opt_type a = { { 1, missing, 3 },{ 0, 1, 0 },{ missing, 4, 1 } }; - double b = 1.0; - - opt_type res = where(a > b, b, a); - opt_type expected = { { 1, missing, 1 },{ 0, 1, 0 },{ missing, 1, 1 } }; - EXPECT_EQ(expected, res); - - opt_type res1 = where(true, a + 3, a); - opt_type expected1 = { { 4, missing, 6 },{ 3, 4, 3 },{ missing, 7, 4 } }; - EXPECT_EQ(expected1, res1); - } + TEST_CASE_TEMPLATE("all", TypeParam, XOPERATION_TEST_TYPES) + { + using int_container_2d = xop_test::rebind_container_t; + using container_1d = redim_container_t; + using int_container_1d = xop_test::rebind_container_t; + int_container_1d a = {1, 1, 3}; + EXPECT_EQ(true, all(a)); + int_container_2d b = {{0, 2, 1}, {2, 1, 0}}; + EXPECT_EQ(false, all(b)); + } - TYPED_TEST(operation, where_cast) - { - using int_container_2d = xop_test::rebind_container_t; - int_container_2d a = {{0, 1, 0}, {3, 0, 5}}; - double res1 = 1.2; - TypeParam b = where(equal(a, 0.0), res1, 0.0); - TypeParam expected = { {1.2, 0., 1.2}, {0., 1.2, 0.} }; - EXPECT_EQ(b, expected); - } + TEST_CASE_TEMPLATE("all_layout", TypeParam, XOPERATION_TEST_TYPES) + { + xarray a = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + xarray b = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; + EXPECT_EQ(a(0, 1), b(0, 1)); + EXPECT_TRUE(all(equal(a, b))); + } - TYPED_TEST(operation, argwhere) - { - using int_container_2d = xop_test::rebind_container_t; - using container_1d = redim_container_t; - using int_container_1d = xop_test::rebind_container_t; - using container_3d = redim_container_t; - using bool_container = xop_test::rebind_container_t; - using shape_type = typename container_3d::shape_type; - - int_container_1d a = {1, 0, 3}; - std::vector> expected = {{0}, {2}}; - EXPECT_EQ(expected, argwhere(a)); - - int_container_2d b = {{0, 2, 1}, {2, 1, 0}}; - std::vector> expected_b = {{0, 1}, {0, 2}, {1, 0}, {1, 1}}; - EXPECT_EQ(expected_b, argwhere(b)); - - auto c = equal(b, 0); - std::vector> expected_c = {{0, 0}, {1, 2}}; - EXPECT_EQ(expected_c, argwhere(c)); - - shape_type s = {3, 3, 3}; - bool_container d(s); - std::fill(d.begin(), d.end(), true); - - auto d_nz = argwhere(d); - EXPECT_EQ(size_t(3 * 3 * 3), d_nz.size()); - xindex_type_t last_idx = {2, 2, 2}; - EXPECT_EQ(last_idx, d_nz.back()); - } + TEST_CASE_TEMPLATE("nonzero", TypeParam, XOPERATION_TEST_TYPES) + { + using int_container_2d = xop_test::rebind_container_t; + using container_1d = redim_container_t; + using int_container_1d = xop_test::rebind_container_t; + using container_3d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + using shape_type = typename container_3d::shape_type; + + int_container_1d a = {1, 0, 3}; + std::vector> expected = {{0, 2}}; + EXPECT_EQ(expected, nonzero(a)); + + int_container_2d b = {{0, 2, 1}, {2, 1, 0}}; + std::vector> expected_b = {{0, 0, 1, 1}, {1, 2, 0, 1}}; + EXPECT_EQ(expected_b, nonzero(b)); + + auto c = equal(b, 0); + std::vector> expected_c = {{0, 1}, {0, 2}}; + EXPECT_EQ(expected_c, nonzero(c)); + + shape_type s = {3, 3, 3}; + bool_container d(s); + std::fill(d.begin(), d.end(), true); + + auto d_nz = nonzero(d); + EXPECT_EQ(size_t(3), d_nz.size()); + EXPECT_EQ(size_t(27 * 27 * 27), d_nz[0].size() * d_nz[1].size() * d_nz[2].size()); + } - TYPED_TEST(operation, cast) - { - using int_container_t = xop_test::rebind_container_t; - using shape_type = typename int_container_t::shape_type; - shape_type shape = {3, 2}; - int_container_t a(shape, 5); - auto ref = static_cast(a(0, 0)) / 2; - auto actual = (cast(a) / 2)(0, 0); - EXPECT_EQ(ref, actual); - } + TEST_CASE_TEMPLATE("where_only_condition", TypeParam, XOPERATION_TEST_TYPES) + { + using int_container_2d = xop_test::rebind_container_t; + int_container_2d a = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; + std::vector> expected = {{0, 1, 2}, {0, 1, 2}}; + EXPECT_EQ(expected, where(a)); + } - struct vtype - { - double a = 0; - size_t b = 0; + TEST_CASE_TEMPLATE("where", TypeParam, XOPERATION_TEST_TYPES) + { + TypeParam a = { { 1, 2, 3 },{ 0, 1, 0 },{ 0, 4, 1 } }; + double b = 1.0; + TypeParam res = where(a > b, b, a); + TypeParam expected = { { 1, 1, 1 },{ 0, 1, 0 },{ 0, 1, 1 } }; + EXPECT_EQ(expected, res); + + #ifdef XTENSOR_USE_XSIMD + // This will fail to compile if simd is broken for conditional_ternary + auto func = where(a > b, b, a); + auto s = func.template load_simd(0); + (void)s; + + using assign_traits = xassign_traits; + + EXPECT_TRUE(assign_traits::simd_linear_assign()); + #endif + } - explicit operator double() const { return a; } - }; + TEST_CASE_TEMPLATE("where_optional", TypeParam, XOPERATION_TEST_TYPES) + { + using opt_type = xoptional_assembly>; + auto missing = xtl::missing(); + opt_type a = { { 1, missing, 3 },{ 0, 1, 0 },{ missing, 4, 1 } }; + double b = 1.0; + + opt_type res = where(a > b, b, a); + opt_type expected = { { 1, missing, 1 },{ 0, 1, 0 },{ missing, 1, 1 } }; + EXPECT_EQ(expected, res); + + opt_type res1 = where(true, a + 3, a); + opt_type expected1 = { { 4, missing, 6 },{ 3, 4, 3 },{ missing, 7, 4 } }; + EXPECT_EQ(expected1, res1); + } - TYPED_TEST(operation, cast_custom_type) - { - using vtype_container_t = xop_test::rebind_container_t; - using shape_type = typename vtype_container_t::shape_type; - shape_type shape = { 3, 2 }; - vtype_container_t a(shape); - auto ref = static_cast(a(0, 0)); - auto actual = (cast(a))(0, 0); - EXPECT_EQ(ref, actual); - } + TEST_CASE_TEMPLATE("where_cast", TypeParam, XOPERATION_TEST_TYPES) + { + using int_container_2d = xop_test::rebind_container_t; + int_container_2d a = {{0, 1, 0}, {3, 0, 5}}; + double res1 = 1.2; + TypeParam b = where(equal(a, 0.0), res1, 0.0); + TypeParam expected = { {1.2, 0., 1.2}, {0., 1.2, 0.} }; + EXPECT_EQ(b, expected); + } - TYPED_TEST(operation, mixed_arithmetic) - { - using int_container_t = xop_test::rebind_container_t; - TypeParam a = {{0., 1., 2.}, {3., 4., 5.}}; - int_container_t b = {{0, 1, 2}, {3, 4, 5}}; - int_container_t c = b; - TypeParam res = a + (b + c); - TypeParam expected = {{0., 3., 6.}, {9., 12., 15.}}; - EXPECT_EQ(res, expected); - } + TEST_CASE_TEMPLATE("argwhere", TypeParam, XOPERATION_TEST_TYPES) + { + using int_container_2d = xop_test::rebind_container_t; + using container_1d = redim_container_t; + using int_container_1d = xop_test::rebind_container_t; + using container_3d = redim_container_t; + using bool_container = xop_test::rebind_container_t; + using shape_type = typename container_3d::shape_type; + + int_container_1d a = {1, 0, 3}; + std::vector> expected = {{0}, {2}}; + EXPECT_EQ(expected, argwhere(a)); + + int_container_2d b = {{0, 2, 1}, {2, 1, 0}}; + std::vector> expected_b = {{0, 1}, {0, 2}, {1, 0}, {1, 1}}; + EXPECT_EQ(expected_b, argwhere(b)); + + auto c = equal(b, 0); + std::vector> expected_c = {{0, 0}, {1, 2}}; + EXPECT_EQ(expected_c, argwhere(c)); + + shape_type s = {3, 3, 3}; + bool_container d(s); + std::fill(d.begin(), d.end(), true); + + auto d_nz = argwhere(d); + EXPECT_EQ(size_t(3 * 3 * 3), d_nz.size()); + xindex_type_t last_idx = {2, 2, 2}; + EXPECT_EQ(last_idx, d_nz.back()); + } - TYPED_TEST(operation, assign_traits) - { - TypeParam a = { { 0., 1., 2. },{ 3., 4., 5. } }; - TypeParam b = { { 0., 1., 2. },{ 3., 4., 5. } }; - - { - SCOPED_TRACE("xarray + xarray"); - auto fd = a + b; - using assign_traits_double = xassign_traits; -#if XTENSOR_USE_XSIMD - EXPECT_TRUE(assign_traits_double::simd_linear_assign()); -#else - // SFINAE on load_simd is broken on mingw when xsimd is disabled. This using - // triggers the same error as the one caught by mingw. - using return_type = decltype(fd.template load_simd(std::size_t(0))); - EXPECT_FALSE(assign_traits_double::simd_linear_assign()); - EXPECT_TRUE((std::is_same::value)); -#endif - } - - { - SCOPED_TRACE("double * xarray"); - xscalar sd = 2.; - auto fsd = sd * a; - using assign_traits_scalar_double = xassign_traits; -#if XTENSOR_USE_XSIMD - auto batch = fsd.template load_simd(0); - (void)batch; - EXPECT_TRUE(assign_traits_scalar_double::simd_linear_assign()); -#else - using return_type = decltype(fsd.template load_simd(std::size_t(0))); - EXPECT_FALSE(assign_traits_scalar_double::simd_linear_assign()); - EXPECT_TRUE((std::is_same::value)); -#endif - } - - { - SCOPED_TRACE("xarray + xarray"); + TEST_CASE_TEMPLATE("cast", TypeParam, XOPERATION_TEST_TYPES) + { using int_container_t = xop_test::rebind_container_t; - int_container_t c = { { 0, 1, 2 },{ 3, 4, 5 } }; - auto fm = a + c; - using assign_traits_mixed = xassign_traits; -#if XTENSOR_USE_XSIMD - EXPECT_TRUE(assign_traits_mixed::simd_linear_assign()); -#else - using return_type = decltype(fm.template load_simd(std::size_t(0))); - EXPECT_FALSE(assign_traits_mixed::simd_linear_assign()); - EXPECT_TRUE((std::is_same::value)); -#endif - } - - { - SCOPED_TRACE("int * xarray"); - xscalar si = 2; - auto fsm = si * a; - using assign_traits_scalar_mixed = xassign_traits; -#if XTENSOR_USE_XSIMD - EXPECT_TRUE(assign_traits_scalar_mixed::simd_linear_assign()); -#else - using return_type = decltype(fsm.template load_simd(std::size_t(0))); - EXPECT_FALSE(assign_traits_scalar_mixed::simd_linear_assign()); - EXPECT_TRUE((std::is_same::value)); -#endif - } - - { - SCOPED_TRACE("xarray + xarray"); - using char_container_t = xop_test::rebind_container_t; - char_container_t d = { { 0, 1, 2 },{ 3, 4, 5 } }; - auto fdc = a + d; - using assign_traits_char_double = xassign_traits; -#if XTENSOR_USE_XSIMD - EXPECT_TRUE(assign_traits_char_double::simd_linear_assign()); -#else - using return_type = decltype(fdc.template load_simd(std::size_t(0))); - EXPECT_FALSE(assign_traits_char_double::simd_linear_assign()); - EXPECT_TRUE((std::is_same::value)); -#endif - } - - { - SCOPED_TRACE("xarray + xarray"); - using md_container_t = xop_test::rebind_container_t; - md_container_t d = { { 0, 1, 2 },{ 3, 4, 5 } }; - auto fdm = a + d; - using assign_traits_md_double = xassign_traits; -#if XTENSOR_USE_XSIMD - EXPECT_FALSE(assign_traits_md_double::simd_linear_assign()); -#else - using return_type = decltype(fdm.template load_simd(std::size_t(0))); - EXPECT_FALSE(assign_traits_md_double::simd_linear_assign()); - EXPECT_TRUE((std::is_same::value)); -#endif - } - - { - SCOPED_TRACE("xarray > xarray"); - auto fgt = a > b; - using bool_container_t = xop_test::rebind_container_t; - using assign_traits_gt = xassign_traits; -#if XTENSOR_USE_XSIMD - EXPECT_TRUE(assign_traits_gt::simd_linear_assign()); -#else - using return_type = decltype(fgt.template load_simd(std::size_t(0))); - EXPECT_FALSE(assign_traits_gt::simd_linear_assign()); - EXPECT_TRUE((std::is_same::value)); -#endif - } - - { - SCOPED_TRACE("xarray || xarray"); - using bool_container_t = xop_test::rebind_container_t; - bool_container_t b0 = {{true, false, true}, {false, false, true}}; - bool_container_t b1 = {{true, true, false}, {false, true, true}}; - auto fb = b0 || b1; - using assign_traits_bool_bool = xassign_traits; -#if XTENSOR_USE_XSIMD - EXPECT_TRUE(assign_traits_bool_bool::simd_linear_assign()); -#else - using return_type = decltype(fb.template load_simd(std::size_t(0))); - EXPECT_FALSE(assign_traits_bool_bool::simd_linear_assign()); - EXPECT_TRUE((std::is_same::value)); -#endif + using shape_type = typename int_container_t::shape_type; + shape_type shape = {3, 2}; + int_container_t a(shape, 5); + auto ref = static_cast(a(0, 0)) / 2; + auto actual = (cast(a) / 2)(0, 0); + EXPECT_EQ(ref, actual); } - } - TEST(operation, mixed_assign) - { - xt::xarray asrc = { 1., 2. }; - xt::xarray bsrc = { std::size_t(3), std::size_t(4) }; + TEST_CASE_TEMPLATE("cast_custom_type", TypeParam, XOPERATION_TEST_TYPES) + { + using vtype_container_t = xop_test::rebind_container_t; + using shape_type = typename vtype_container_t::shape_type; + shape_type shape = { 3, 2 }; + vtype_container_t a(shape); + auto ref = static_cast(a(0, 0)); + auto actual = (cast(a))(0, 0); + EXPECT_EQ(ref, actual); + } - xt::xarray a(asrc); - xt::xarray aexp = { 3., 4. }; - a = bsrc; + TEST_CASE_TEMPLATE("mixed_arithmetic", TypeParam, XOPERATION_TEST_TYPES) + { + using int_container_t = xop_test::rebind_container_t; + TypeParam a = {{0., 1., 2.}, {3., 4., 5.}}; + int_container_t b = {{0, 1, 2}, {3, 4, 5}}; + int_container_t c = b; + TypeParam res = a + (b + c); + TypeParam expected = {{0., 3., 6.}, {9., 12., 15.}}; + EXPECT_EQ(res, expected); + } - xt::xarray b(bsrc); - xt::xarray bexp = { std::size_t(1), std::size_t(2) }; - b = asrc; - EXPECT_EQ(b, bexp); - } + TEST_CASE_TEMPLATE("assign_traits", TypeParam, XOPERATION_TEST_TYPES) + { + TypeParam a = { { 0., 1., 2. },{ 3., 4., 5. } }; + TypeParam b = { { 0., 1., 2. },{ 3., 4., 5. } }; + + SUBCASE("xarray + xarray") + { + auto fd = a + b; + using assign_traits_double = xassign_traits; + #if XTENSOR_USE_XSIMD + EXPECT_TRUE(assign_traits_double::simd_linear_assign()); + #else + // SFINAE on load_simd is broken on mingw when xsimd is disabled. This using + // triggers the same error as the one caught by mingw. + using return_type = decltype(fd.template load_simd(std::size_t(0))); + EXPECT_FALSE(assign_traits_double::simd_linear_assign()); + EXPECT_TRUE((std::is_same::value)); + #endif + } + + SUBCASE("double * xarray") + { + xscalar sd = 2.; + auto fsd = sd * a; + using assign_traits_scalar_double = xassign_traits; + #if XTENSOR_USE_XSIMD + auto batch = fsd.template load_simd(0); + (void)batch; + EXPECT_TRUE(assign_traits_scalar_double::simd_linear_assign()); + #else + using return_type = decltype(fsd.template load_simd(std::size_t(0))); + EXPECT_FALSE(assign_traits_scalar_double::simd_linear_assign()); + EXPECT_TRUE((std::is_same::value)); + #endif + } + + SUBCASE("xarray + xarray") + { + using int_container_t = xop_test::rebind_container_t; + int_container_t c = { { 0, 1, 2 },{ 3, 4, 5 } }; + auto fm = a + c; + using assign_traits_mixed = xassign_traits; + #if XTENSOR_USE_XSIMD + EXPECT_TRUE(assign_traits_mixed::simd_linear_assign()); + #else + using return_type = decltype(fm.template load_simd(std::size_t(0))); + EXPECT_FALSE(assign_traits_mixed::simd_linear_assign()); + EXPECT_TRUE((std::is_same::value)); + #endif + } + + SUBCASE("int * xarray") + { + xscalar si = 2; + auto fsm = si * a; + using assign_traits_scalar_mixed = xassign_traits; + #if XTENSOR_USE_XSIMD + EXPECT_TRUE(assign_traits_scalar_mixed::simd_linear_assign()); + #else + using return_type = decltype(fsm.template load_simd(std::size_t(0))); + EXPECT_FALSE(assign_traits_scalar_mixed::simd_linear_assign()); + EXPECT_TRUE((std::is_same::value)); + #endif + } + + SUBCASE("xarray + xarray") + { + using char_container_t = xop_test::rebind_container_t; + char_container_t d = { { 0, 1, 2 },{ 3, 4, 5 } }; + auto fdc = a + d; + using assign_traits_char_double = xassign_traits; + #if XTENSOR_USE_XSIMD + EXPECT_TRUE(assign_traits_char_double::simd_linear_assign()); + #else + using return_type = decltype(fdc.template load_simd(std::size_t(0))); + EXPECT_FALSE(assign_traits_char_double::simd_linear_assign()); + EXPECT_TRUE((std::is_same::value)); + #endif + } + + SUBCASE("xarray + xarray") + { + using md_container_t = xop_test::rebind_container_t; + md_container_t d = { { 0, 1, 2 },{ 3, 4, 5 } }; + auto fdm = a + d; + using assign_traits_md_double = xassign_traits; + #if XTENSOR_USE_XSIMD + EXPECT_FALSE(assign_traits_md_double::simd_linear_assign()); + #else + using return_type = decltype(fdm.template load_simd(std::size_t(0))); + EXPECT_FALSE(assign_traits_md_double::simd_linear_assign()); + EXPECT_TRUE((std::is_same::value)); + #endif + } + + SUBCASE("xarray > xarray") + { + auto fgt = a > b; + using bool_container_t = xop_test::rebind_container_t; + using assign_traits_gt = xassign_traits; + #if XTENSOR_USE_XSIMD + EXPECT_TRUE(assign_traits_gt::simd_linear_assign()); + #else + using return_type = decltype(fgt.template load_simd(std::size_t(0))); + EXPECT_FALSE(assign_traits_gt::simd_linear_assign()); + EXPECT_TRUE((std::is_same::value)); + #endif + } + + SUBCASE("xarray || xarray") + { + using bool_container_t = xop_test::rebind_container_t; + bool_container_t b0 = {{true, false, true}, {false, false, true}}; + bool_container_t b1 = {{true, true, false}, {false, true, true}}; + auto fb = b0 || b1; + using assign_traits_bool_bool = xassign_traits; + #if XTENSOR_USE_XSIMD + EXPECT_TRUE(assign_traits_bool_bool::simd_linear_assign()); + #else + using return_type = decltype(fb.template load_simd(std::size_t(0))); + EXPECT_FALSE(assign_traits_bool_bool::simd_linear_assign()); + EXPECT_TRUE((std::is_same::value)); + #endif + } + } - TEST(operation, mixed_bool_assign) - { - xt::xarray a = { 1., 6. }; - xt::xarray b = { 2., 3. }; - using uchar = unsigned char; - xt::xarray res = a > b; - xt::xarray exp = { uchar(0), uchar(1) }; - EXPECT_EQ(res, exp); - } - TEST(operation, dynamic_simd_assign) - { - using array_type = xt::xarray; - array_type a({2, 3}, layout_type::row_major); - array_type b({2, 3}, layout_type::column_major); - auto frr = a + a; - auto frc = a + b; - auto fcc = b + b; - using frr_traits = xassign_traits; - using frc_traits = xassign_traits; - using fcc_traits = xassign_traits; + TEST(operation, mixed_assign) + { + xt::xarray asrc = { 1., 2. }; + xt::xarray bsrc = { std::size_t(3), std::size_t(4) }; - EXPECT_FALSE(frr_traits::simd_linear_assign()); - EXPECT_FALSE(frc_traits::simd_linear_assign()); - EXPECT_FALSE(fcc_traits::simd_linear_assign()); + xt::xarray a(asrc); + xt::xarray aexp = { 3., 4. }; + a = bsrc; - { - SCOPED_TRACE("row_major + row_major"); -#if XTENSOR_USE_XSIMD - EXPECT_TRUE(frr_traits::simd_linear_assign(a, frr)); -#else - EXPECT_FALSE(frr_traits::simd_linear_assign(a, frr)); -#endif - EXPECT_FALSE(frr_traits::simd_linear_assign(b, frr)); + xt::xarray b(bsrc); + xt::xarray bexp = { std::size_t(1), std::size_t(2) }; + b = asrc; + EXPECT_EQ(b, bexp); } + TEST(operation, mixed_bool_assign) { - SCOPED_TRACE("row_major + column_major"); - EXPECT_FALSE(frc_traits::simd_linear_assign(a, frc)); - EXPECT_FALSE(frc_traits::simd_linear_assign(b, frc)); + xt::xarray a = { 1., 6. }; + xt::xarray b = { 2., 3. }; + using uchar = unsigned char; + xt::xarray res = a > b; + xt::xarray exp = { uchar(0), uchar(1) }; + EXPECT_EQ(res, exp); } + TEST(operation, dynamic_simd_assign) { - SCOPED_TRACE("row_major + column_major"); - EXPECT_FALSE(fcc_traits::simd_linear_assign(a, fcc)); -#if XTENSOR_USE_XSIMD - EXPECT_TRUE(fcc_traits::simd_linear_assign(b, fcc)); -#else - EXPECT_FALSE(fcc_traits::simd_linear_assign(b, fcc)); -#endif + using array_type = xt::xarray; + array_type a({2, 3}, layout_type::row_major); + array_type b({2, 3}, layout_type::column_major); + + auto frr = a + a; + auto frc = a + b; + auto fcc = b + b; + + using frr_traits = xassign_traits; + using frc_traits = xassign_traits; + using fcc_traits = xassign_traits; + + EXPECT_FALSE(frr_traits::simd_linear_assign()); + EXPECT_FALSE(frc_traits::simd_linear_assign()); + EXPECT_FALSE(fcc_traits::simd_linear_assign()); + + SUBCASE("row_major + row_major") + { + #if XTENSOR_USE_XSIMD + EXPECT_TRUE(frr_traits::simd_linear_assign(a, frr)); + #else + EXPECT_FALSE(frr_traits::simd_linear_assign(a, frr)); + #endif + EXPECT_FALSE(frr_traits::simd_linear_assign(b, frr)); + } + + SUBCASE("row_major + column_major") + { + EXPECT_FALSE(frc_traits::simd_linear_assign(a, frc)); + EXPECT_FALSE(frc_traits::simd_linear_assign(b, frc)); + } + + SUBCASE("row_major + column_major") + { + EXPECT_FALSE(fcc_traits::simd_linear_assign(a, fcc)); + #if XTENSOR_USE_XSIMD + EXPECT_TRUE(fcc_traits::simd_linear_assign(b, fcc)); + #else + EXPECT_FALSE(fcc_traits::simd_linear_assign(b, fcc)); + #endif + } + } - } - TEST(operation, left_shift) - { - xarray arr({5,1, 1000}); - xarray arr2({2,1, 3}); - xarray res1 = left_shift(arr, 4); - xarray res2 = left_shift(arr, arr2); - EXPECT_EQ(left_shift(arr, 4)(1), 16); - xarray expected1 = {80, 16, 16000}; - xarray expected2 = {20, 2, 8000}; - - EXPECT_EQ(expected1, res1); - EXPECT_EQ(expected2, res2); - - xarray res3 = arr << 4; - xarray res4 = arr << arr2; - EXPECT_EQ(expected1, res3); - EXPECT_EQ(expected2, res4); - } + TEST_CASE("left_shift") + { + xarray arr({5,1, 1000}); + xarray arr2({2,1, 3}); + xarray res1 = left_shift(arr, 4); + xarray res2 = left_shift(arr, arr2); + EXPECT_EQ(left_shift(arr, 4)(1), 16); + xarray expected1 = {80, 16, 16000}; + xarray expected2 = {20, 2, 8000}; + + EXPECT_EQ(expected1, res1); + EXPECT_EQ(expected2, res2); + + xarray res3 = arr << 4; + xarray res4 = arr << arr2; + EXPECT_EQ(expected1, res3); + EXPECT_EQ(expected2, res4); + } - TEST(operation, right_shift) - { - xarray arr({5,1, 1000}); - xarray arr2({2,1, 3}); - xarray res1 = right_shift(arr, 4); - xarray res2 = right_shift(arr, arr2); - EXPECT_EQ(right_shift(arr, 4)(1), 0); - xarray expected1 = {0, 0, 62}; - xarray expected2 = {1, 0, 125}; - - EXPECT_EQ(expected1, res1); - EXPECT_EQ(expected2, res2); - - xarray res3 = arr >> 4; - xarray res4 = arr >> arr2; - EXPECT_EQ(expected1, res3); - EXPECT_EQ(expected2, res4); + TEST_CASE("right_shift") + { + xarray arr({5,1, 1000}); + xarray arr2({2,1, 3}); + xarray res1 = right_shift(arr, 4); + xarray res2 = right_shift(arr, arr2); + EXPECT_EQ(right_shift(arr, 4)(1), 0); + xarray expected1 = {0, 0, 62}; + xarray expected2 = {1, 0, 125}; + + EXPECT_EQ(expected1, res1); + EXPECT_EQ(expected2, res2); + + xarray res3 = arr >> 4; + xarray res4 = arr >> arr2; + EXPECT_EQ(expected1, res3); + EXPECT_EQ(expected2, res4); + } } + #undef XOPERATION_TEST_TYPES } diff --git a/test/test_xoptional.cpp b/test/test_xoptional.cpp index 28b388854..bba00ffef 100644 --- a/test/test_xoptional.cpp +++ b/test/test_xoptional.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include #include diff --git a/test/test_xoptional_assembly.cpp b/test/test_xoptional_assembly.cpp index 25c1026b5..dc626f0be 100644 --- a/test/test_xoptional_assembly.cpp +++ b/test/test_xoptional_assembly.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xio.hpp" @@ -25,22 +25,22 @@ namespace xt TEST(xoptional_assembly, shaped_constructor) { + SUBCASE("row_major constructor") { - SCOPED_TRACE("row_major constructor"); row_major_result<> rm; dyn_opt_ass_type ra(rm.m_shape, layout_type::row_major); compare_shape(ra, rm); } + SUBCASE("column_major constructor") { - SCOPED_TRACE("column_major constructor"); column_major_result<> cm; cm_opt_ass_type ca(cm.m_shape); compare_shape(ca, cm); } + SUBCASE("from shape") { - SCOPED_TRACE("from shape"); std::array shp = {5, 4, 2}; std::vector shp_as_vec = {5, 4, 2}; auto ca = cm_opt_ass_type::from_shape({3, 2, 1}); @@ -60,8 +60,8 @@ namespace xt TEST(xoptional_assembly, valued_constructor) { + SUBCASE("row_major valued constructor") { - SCOPED_TRACE("row_major valued constructor"); row_major_result<> rm; int value = 2; dyn_opt_ass_type ra(rm.m_shape, value, layout_type::row_major); @@ -70,8 +70,8 @@ namespace xt EXPECT_EQ(ra.value().storage(), vec); } + SUBCASE("column_major valued constructor") { - SCOPED_TRACE("column_major valued constructor"); column_major_result<> cm; int value = 2; cm_opt_ass_type ca(cm.m_shape, value); @@ -141,15 +141,15 @@ namespace xt int value = 2; dyn_opt_ass_type a(res.m_shape, res.m_strides, value); + SUBCASE("copy constructor") { - SCOPED_TRACE("copy constructor"); dyn_opt_ass_type b(a); compare_shape(a, b); EXPECT_EQ(a.storage(), b.storage()); } + SUBCASE("assignment operator") { - SCOPED_TRACE("assignment operator"); row_major_result<> r; dyn_opt_ass_type c(r.m_shape, dyn_opt_ass_type::value_type(0, false)); EXPECT_NE(a.storage(), c.storage()); @@ -165,16 +165,16 @@ namespace xt int value = 2; dyn_opt_ass_type a(res.m_shape, res.m_strides, value); + SUBCASE("move constructor") { - SCOPED_TRACE("move constructor"); dyn_opt_ass_type tmp(a); dyn_opt_ass_type b(std::move(tmp)); compare_shape(a, b); EXPECT_EQ(a.storage(), b.storage()); } + SUBCASE("move assignment") { - SCOPED_TRACE("move assignment"); row_major_result<> r; dyn_opt_ass_type c(r.m_shape, dyn_opt_ass_type::value_type(0, false)); EXPECT_NE(a.value().storage(), c.value().storage()); @@ -280,16 +280,16 @@ namespace xt shape_type s = {3, 1, 4, 2}; opt_ass_type vec(s); + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); shape_type s1 = s; bool res = vec.broadcast_shape(s1); EXPECT_EQ(s1, s); EXPECT_TRUE(res); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); shape_type s2 = {3, 5, 1, 2}; shape_type s2r = {3, 5, 4, 2}; bool res = vec.broadcast_shape(s2); @@ -297,16 +297,16 @@ namespace xt EXPECT_FALSE(res); } + SUBCASE("incompatible shapes") { - SCOPED_TRACE("incompatible shapes"); shape_type s4 = {2, 1, 3, 2}; XT_EXPECT_THROW(vec.broadcast_shape(s4), broadcast_error); } { shape_type s2 = {3, 1, 4, 2}; + SUBCASE("different dimensions") vec.resize(s2); - SCOPED_TRACE("different dimensions"); shape_type s3 = {5, 3, 1, 4, 2}; shape_type s3r = s3; bool res = vec.broadcast_shape(s3); @@ -320,8 +320,8 @@ namespace xt using opt = xtl::xoptional; std::vector vec = {opt(1), opt(2, false), opt(3, false), opt(4)}; + SUBCASE("row_major storage iterator") { - SCOPED_TRACE("row_major storage iterator"); opt_ass_type rma(opt_ass_type::shape_type({2, 2})); std::copy(vec.cbegin(), vec.cend(), rma.begin()); EXPECT_EQ(vec[0], rma(0, 0)); @@ -331,8 +331,8 @@ namespace xt EXPECT_EQ(vec.size(), std::size_t(std::distance(rma.begin(), rma.end()))); } + SUBCASE("column_major storage iterator") { - SCOPED_TRACE("column_major storage iterator"); cm_opt_ass_type cma(opt_ass_type::shape_type({2, 2})); std::copy(vec.cbegin(), vec.cend(), cma.begin()); EXPECT_EQ(vec[0], cma(0, 0)); diff --git a/test/test_xoptional_assembly_adaptor.cpp b/test/test_xoptional_assembly_adaptor.cpp index c850dc815..aaf8f4f3b 100644 --- a/test/test_xoptional_assembly_adaptor.cpp +++ b/test/test_xoptional_assembly_adaptor.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xio.hpp" @@ -35,16 +35,16 @@ namespace xt flag_array_type hv = {{true, false, true}, {false, true, false}}; adaptor_type a(v, hv); + SUBCASE("copy constructor") { - SCOPED_TRACE("copy constructor"); adaptor_type b(a); compare_shape(a, b); EXPECT_EQ(a.value().storage(), b.value().storage()); EXPECT_EQ(a.has_value().storage(), b.has_value().storage()); } + SUBCASE("assignment operator") { - SCOPED_TRACE("assignment operator"); array_type v2 = {{1, 2, 13}, {14, 15, 16}}; flag_array_type hv2 = {{false, true, true}, {false, true, false}}; adaptor_type c(v2, hv2); @@ -63,8 +63,8 @@ namespace xt flag_array_type hv = {{true, false, true}, {false, true, false}}; adaptor_type a(v, hv); + SUBCASE("copy constructor") { - SCOPED_TRACE("copy constructor"); adaptor_type tmp(a); adaptor_type b(std::move(tmp)); compare_shape(a, b); @@ -72,8 +72,8 @@ namespace xt EXPECT_EQ(a.has_value().storage(), b.has_value().storage()); } + SUBCASE("assignment operator") { - SCOPED_TRACE("assignment operator"); array_type v2 = {{1, 2, 13}, {14, 15, 16}}; flag_array_type hv2 = {{false, true, true}, {false, true, false}}; adaptor_type c(v2, hv2); @@ -181,16 +181,16 @@ namespace xt flag_array_type hv(s); adaptor_type a(v, hv); + SUBCASE("same shape") { - SCOPED_TRACE("same shape"); shape_type s1 = s; bool res = a.broadcast_shape(s1); EXPECT_EQ(s1, s); EXPECT_TRUE(res); } + SUBCASE("different shape") { - SCOPED_TRACE("different shape"); shape_type s2 = {3, 5, 1, 2}; shape_type s2r = {3, 5, 4, 2}; bool res = a.broadcast_shape(s2); @@ -198,16 +198,16 @@ namespace xt EXPECT_FALSE(res); } + SUBCASE("incompatible shapes") { - SCOPED_TRACE("incompatible shapes"); shape_type s4 = {2, 1, 3, 2}; XT_EXPECT_THROW(a.broadcast_shape(s4), broadcast_error); } { shape_type s2 = {3, 1, 4, 2}; + SUBCASE("different dimensions") a.resize(s2); - SCOPED_TRACE("different dimensions"); shape_type s3 = {5, 3, 1, 4, 2}; shape_type s3r = s3; bool res = a.broadcast_shape(s3); @@ -221,8 +221,8 @@ namespace xt using opt = xtl::xoptional; std::vector vec = {opt(1), opt(2, false), opt(3, false), opt(4)}; + SUBCASE("row_major storage iterator") { - SCOPED_TRACE("row_major storage iterator"); xarray v; xarray hv; xoptional_assembly_adaptor rma(v, hv); @@ -235,8 +235,8 @@ namespace xt EXPECT_EQ(vec.size(), std::size_t(std::distance(rma.begin(), rma.end()))); } + SUBCASE("column_major storage iterator") { - SCOPED_TRACE("column_major storage iterator"); xarray v; xarray hv; xoptional_assembly_adaptor cma(v, hv); diff --git a/test/test_xoptional_assembly_storage.cpp b/test/test_xoptional_assembly_storage.cpp index fcb2e9cc3..22b2067a8 100644 --- a/test/test_xoptional_assembly_storage.cpp +++ b/test/test_xoptional_assembly_storage.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xstorage.hpp" #include "xtensor/xio.hpp" diff --git a/test/test_xpad.cpp b/test/test_xpad.cpp index 09bd899a3..e6c470588 100644 --- a/test/test_xpad.cpp +++ b/test/test_xpad.cpp @@ -10,7 +10,7 @@ #include #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xpad.hpp" #include "xtensor/xio.hpp" diff --git a/test/test_xrandom.cpp b/test/test_xrandom.cpp index 0b7eb1810..e513d23cb 100644 --- a/test/test_xrandom.cpp +++ b/test/test_xrandom.cpp @@ -9,7 +9,7 @@ #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_common_macros.hpp" #if (defined(__GNUC__) && !defined(__clang__)) #pragma GCC diagnostic push diff --git a/test/test_xreducer.cpp b/test/test_xreducer.cpp index 13081faeb..b1708f65a 100644 --- a/test/test_xreducer.cpp +++ b/test/test_xreducer.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_common_macros.hpp" #if (defined(__GNUC__) && !defined(__clang__)) #pragma GCC diagnostic push diff --git a/test/test_xrepeat.cpp b/test/test_xrepeat.cpp index a1537ad96..439eca52f 100644 --- a/test/test_xrepeat.cpp +++ b/test/test_xrepeat.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xrepeat.hpp" #include "xtensor/xview.hpp" diff --git a/test/test_xscalar.cpp b/test/test_xscalar.cpp index 8cd951abb..4f4704e0c 100644 --- a/test/test_xscalar.cpp +++ b/test/test_xscalar.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_common_macros.hpp" #include "xtensor/xscalar.hpp" #include "xtensor/xarray.hpp" diff --git a/test/test_xscalar_semantic.cpp b/test/test_xscalar_semantic.cpp index 7bf0835e8..2cf2d5099 100644 --- a/test/test_xscalar_semantic.cpp +++ b/test/test_xscalar_semantic.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xnoalias.hpp" #include "test_xsemantic.hpp" @@ -28,270 +28,274 @@ namespace xt using storage_type = C; }; - using testing_types = ::testing::Types; - TYPED_TEST_SUITE(scalar_semantic, testing_types); + #define SCALAR_SEMANTIC_TEST_TYPES xarray_dynamic, xtensor_dynamic - TYPED_TEST(scalar_semantic, a_plus_equal_b) + TEST_SUITE("scalar_semantic") { - scalar_operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major += scalar"); - TypeParam a = tester.ra; - a += tester.b; - EXPECT_TRUE(full_equal(tester.res_r, a)); - } - - { - SCOPED_TRACE("column_major += scalar"); - TypeParam a = tester.ca; - a += tester.b; - EXPECT_TRUE(full_equal(tester.res_c, a)); - } - - { - SCOPED_TRACE("central_major += scalar"); - TypeParam a = tester.cta; - a += tester.b; - EXPECT_TRUE(full_equal(tester.res_ct, a)); - } - - { - SCOPED_TRACE("unit_major += scalar"); - TypeParam a = tester.ua; - a += tester.b; - EXPECT_TRUE(full_equal(tester.res_u, a)); - } - } - - TYPED_TEST(scalar_semantic, a_minus_equal_b) - { - scalar_operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major -= scalar"); - TypeParam a = tester.ra; - a -= tester.b; - EXPECT_TRUE(full_equal(tester.res_r, a)); - } - - { - SCOPED_TRACE("column_major -= scalar"); - TypeParam a = tester.ca; - a -= tester.b; - EXPECT_TRUE(full_equal(tester.res_c, a)); - } - - { - SCOPED_TRACE("central_major -= scalar"); - TypeParam a = tester.cta; - a -= tester.b; - EXPECT_TRUE(full_equal(tester.res_ct, a)); - } - - { - SCOPED_TRACE("unit_major -= scalar"); - TypeParam a = tester.ua; - a -= tester.b; - EXPECT_TRUE(full_equal(tester.res_u, a)); - } - } - - TYPED_TEST(scalar_semantic, a_times_equal_b) - { - scalar_operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major *= scalar"); - TypeParam a = tester.ra; - a *= tester.b; - EXPECT_TRUE(full_equal(tester.res_r, a)); - } - - { - SCOPED_TRACE("column_major *= scalar"); - TypeParam a = tester.ca; - a *= tester.b; - EXPECT_TRUE(full_equal(tester.res_c, a)); - } - - { - SCOPED_TRACE("central_major *= scalar"); - TypeParam a = tester.cta; - a *= tester.b; - EXPECT_TRUE(full_equal(tester.res_ct, a)); - } - - { - SCOPED_TRACE("unit_major *= scalar"); - TypeParam a = tester.ua; - a *= tester.b; - EXPECT_TRUE(full_equal(tester.res_u, a)); + TEST_CASE_TEMPLATE("a_plus_equal_b", TypeParam, SCALAR_SEMANTIC_TEST_TYPES) + { + scalar_operation_tester, TypeParam> tester; + + SUBCASE("row_major += scalar") + { + TypeParam a = tester.ra; + a += tester.b; + EXPECT_TRUE(full_equal(tester.res_r, a)); + } + + SUBCASE("column_major += scalar") + { + TypeParam a = tester.ca; + a += tester.b; + EXPECT_TRUE(full_equal(tester.res_c, a)); + } + + SUBCASE("central_major += scalar") + { + TypeParam a = tester.cta; + a += tester.b; + EXPECT_TRUE(full_equal(tester.res_ct, a)); + } + + SUBCASE("unit_major += scalar") + { + TypeParam a = tester.ua; + a += tester.b; + EXPECT_TRUE(full_equal(tester.res_u, a)); + } + } + + TEST_CASE_TEMPLATE("a_minus_equal_b", TypeParam, SCALAR_SEMANTIC_TEST_TYPES) + { + scalar_operation_tester, TypeParam> tester; + + SUBCASE("row_major -= scalar") + { + TypeParam a = tester.ra; + a -= tester.b; + EXPECT_TRUE(full_equal(tester.res_r, a)); + } + + SUBCASE("column_major -= scalar") + { + TypeParam a = tester.ca; + a -= tester.b; + EXPECT_TRUE(full_equal(tester.res_c, a)); + } + + SUBCASE("central_major -= scalar") + { + TypeParam a = tester.cta; + a -= tester.b; + EXPECT_TRUE(full_equal(tester.res_ct, a)); + } + + SUBCASE("unit_major -= scalar") + { + TypeParam a = tester.ua; + a -= tester.b; + EXPECT_TRUE(full_equal(tester.res_u, a)); + } + } + + TEST_CASE_TEMPLATE("a_times_equal_b", TypeParam, SCALAR_SEMANTIC_TEST_TYPES) + { + scalar_operation_tester, TypeParam> tester; + + SUBCASE("row_major *= scalar") + { + TypeParam a = tester.ra; + a *= tester.b; + EXPECT_TRUE(full_equal(tester.res_r, a)); + } + + SUBCASE("column_major *= scalar") + { + TypeParam a = tester.ca; + a *= tester.b; + EXPECT_TRUE(full_equal(tester.res_c, a)); + } + + SUBCASE("central_major *= scalar") + { + TypeParam a = tester.cta; + a *= tester.b; + EXPECT_TRUE(full_equal(tester.res_ct, a)); + } + + SUBCASE("unit_major *= scalar") + { + TypeParam a = tester.ua; + a *= tester.b; + EXPECT_TRUE(full_equal(tester.res_u, a)); + } + } + + TEST_CASE_TEMPLATE("a_divide_by_equal_b", TypeParam, SCALAR_SEMANTIC_TEST_TYPES) + { + scalar_operation_tester, TypeParam> tester; + + SUBCASE("row_major /= scalar") + { + TypeParam a = tester.ra; + a /= tester.b; + EXPECT_TRUE(full_equal(tester.res_r, a)); + } + + SUBCASE("column_major /= scalar") + { + TypeParam a = tester.ca; + a /= tester.b; + EXPECT_TRUE(full_equal(tester.res_c, a)); + } + + SUBCASE("central_major /= scalar") + { + TypeParam a = tester.cta; + a /= tester.b; + EXPECT_TRUE(full_equal(tester.res_ct, a)); + } + + SUBCASE("unit_major /= scalar") + { + TypeParam a = tester.ua; + a /= tester.b; + EXPECT_TRUE(full_equal(tester.res_u, a)); + } + } + + TEST_CASE_TEMPLATE("assign_a_plus_b", TypeParam, SCALAR_SEMANTIC_TEST_TYPES) + { + scalar_operation_tester, TypeParam> tester; + + SUBCASE("row_major + scalar") + { + TypeParam a(tester.ra.shape(), tester.ra.strides(), 0); + noalias(a) = tester.ra + tester.b; + EXPECT_TRUE(full_equal(tester.res_r, a)); + } + + SUBCASE("column_major + scalar") + { + TypeParam a(tester.ca.shape(), tester.ca.strides(), 0); + noalias(a) = tester.ca + tester.b; + EXPECT_TRUE(full_equal(tester.res_c, a)); + } + + SUBCASE("central_major + scalar") + { + TypeParam a(tester.cta.shape(), tester.cta.strides(), 0); + noalias(a) = tester.cta + tester.b; + EXPECT_TRUE(full_equal(tester.res_ct, a)); + } + + SUBCASE("unit_major + scalar") + { + TypeParam a(tester.ua.shape(), tester.ua.strides(), 0); + noalias(a) = tester.ua + tester.b; + EXPECT_TRUE(full_equal(tester.res_u, a)); + } + } + + TEST_CASE_TEMPLATE("assign_a_minus_b", TypeParam, SCALAR_SEMANTIC_TEST_TYPES) + { + scalar_operation_tester, TypeParam> tester; + + SUBCASE("row_major - scalar") + { + TypeParam a(tester.ra.shape(), tester.ra.strides(), 0); + noalias(a) = tester.ra - tester.b; + EXPECT_TRUE(full_equal(tester.res_r, a)); + } + + SUBCASE("column_major - scalar") + { + TypeParam a(tester.ca.shape(), tester.ca.strides(), 0); + noalias(a) = tester.ca - tester.b; + EXPECT_TRUE(full_equal(tester.res_c, a)); + } + + SUBCASE("central_major - scalar") + { + TypeParam a(tester.cta.shape(), tester.cta.strides(), 0); + noalias(a) = tester.cta - tester.b; + EXPECT_TRUE(full_equal(tester.res_ct, a)); + } + + SUBCASE("unit_major - scalar") + { + TypeParam a(tester.ua.shape(), tester.ua.strides(), 0); + noalias(a) = tester.ua - tester.b; + EXPECT_TRUE(full_equal(tester.res_u, a)); + } + } + + TEST_CASE_TEMPLATE("assign_a_times_b", TypeParam, SCALAR_SEMANTIC_TEST_TYPES) + { + scalar_operation_tester, TypeParam> tester; + + SUBCASE("row_major * scalar") + { + TypeParam a(tester.ra.shape(), tester.ra.strides(), 0); + noalias(a) = tester.ra * tester.b; + EXPECT_TRUE(full_equal(tester.res_r, a)); + } + + SUBCASE("column_major * scalar") + { + TypeParam a(tester.ca.shape(), tester.ca.strides(), 0); + noalias(a) = tester.ca * tester.b; + EXPECT_TRUE(full_equal(tester.res_c, a)); + } + + SUBCASE("central_major * scalar") + { + TypeParam a(tester.cta.shape(), tester.cta.strides(), 0); + noalias(a) = tester.cta * tester.b; + EXPECT_TRUE(full_equal(tester.res_ct, a)); + } + + SUBCASE("unit_major * scalar") + { + TypeParam a(tester.ua.shape(), tester.ua.strides(), 0); + noalias(a) = tester.ua * tester.b; + EXPECT_TRUE(full_equal(tester.res_u, a)); + } + } + + TEST_CASE_TEMPLATE("assign_a_divide_by_b", TypeParam, SCALAR_SEMANTIC_TEST_TYPES) + { + scalar_operation_tester, TypeParam> tester; + + SUBCASE("row_major / scalar") + { + TypeParam a(tester.ra.shape(), tester.ra.strides(), 0); + noalias(a) = tester.ra / tester.b; + EXPECT_TRUE(full_equal(tester.res_r, a)); + } + + SUBCASE("column_major / scalar") + { + TypeParam a(tester.ca.shape(), tester.ca.strides(), 0); + noalias(a) = tester.ca / tester.b; + EXPECT_TRUE(full_equal(tester.res_c, a)); + } + + SUBCASE("central_major / scalar") + { + TypeParam a(tester.cta.shape(), tester.cta.strides(), 0); + noalias(a) = tester.cta / tester.b; + EXPECT_TRUE(full_equal(tester.res_ct, a)); + } + + SUBCASE("unit_major / scalar") + { + TypeParam a(tester.ua.shape(), tester.ua.strides(), 0); + noalias(a) = tester.ua / tester.b; + EXPECT_TRUE(full_equal(tester.res_u, a)); + } } } - TYPED_TEST(scalar_semantic, a_divide_by_equal_b) - { - scalar_operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major /= scalar"); - TypeParam a = tester.ra; - a /= tester.b; - EXPECT_TRUE(full_equal(tester.res_r, a)); - } - - { - SCOPED_TRACE("column_major /= scalar"); - TypeParam a = tester.ca; - a /= tester.b; - EXPECT_TRUE(full_equal(tester.res_c, a)); - } - - { - SCOPED_TRACE("central_major /= scalar"); - TypeParam a = tester.cta; - a /= tester.b; - EXPECT_TRUE(full_equal(tester.res_ct, a)); - } - - { - SCOPED_TRACE("unit_major /= scalar"); - TypeParam a = tester.ua; - a /= tester.b; - EXPECT_TRUE(full_equal(tester.res_u, a)); - } - } - - TYPED_TEST(scalar_semantic, assign_a_plus_b) - { - scalar_operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major + scalar"); - TypeParam a(tester.ra.shape(), tester.ra.strides(), 0); - noalias(a) = tester.ra + tester.b; - EXPECT_TRUE(full_equal(tester.res_r, a)); - } - - { - SCOPED_TRACE("column_major + scalar"); - TypeParam a(tester.ca.shape(), tester.ca.strides(), 0); - noalias(a) = tester.ca + tester.b; - EXPECT_TRUE(full_equal(tester.res_c, a)); - } - - { - SCOPED_TRACE("central_major + scalar"); - TypeParam a(tester.cta.shape(), tester.cta.strides(), 0); - noalias(a) = tester.cta + tester.b; - EXPECT_TRUE(full_equal(tester.res_ct, a)); - } - - { - SCOPED_TRACE("unit_major + scalar"); - TypeParam a(tester.ua.shape(), tester.ua.strides(), 0); - noalias(a) = tester.ua + tester.b; - EXPECT_TRUE(full_equal(tester.res_u, a)); - } - } - - TYPED_TEST(scalar_semantic, assign_a_minus_b) - { - scalar_operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major - scalar"); - TypeParam a(tester.ra.shape(), tester.ra.strides(), 0); - noalias(a) = tester.ra - tester.b; - EXPECT_TRUE(full_equal(tester.res_r, a)); - } - - { - SCOPED_TRACE("column_major - scalar"); - TypeParam a(tester.ca.shape(), tester.ca.strides(), 0); - noalias(a) = tester.ca - tester.b; - EXPECT_TRUE(full_equal(tester.res_c, a)); - } - - { - SCOPED_TRACE("central_major - scalar"); - TypeParam a(tester.cta.shape(), tester.cta.strides(), 0); - noalias(a) = tester.cta - tester.b; - EXPECT_TRUE(full_equal(tester.res_ct, a)); - } - - { - SCOPED_TRACE("unit_major - scalar"); - TypeParam a(tester.ua.shape(), tester.ua.strides(), 0); - noalias(a) = tester.ua - tester.b; - EXPECT_TRUE(full_equal(tester.res_u, a)); - } - } - - TYPED_TEST(scalar_semantic, assign_a_times_b) - { - scalar_operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major * scalar"); - TypeParam a(tester.ra.shape(), tester.ra.strides(), 0); - noalias(a) = tester.ra * tester.b; - EXPECT_TRUE(full_equal(tester.res_r, a)); - } - - { - SCOPED_TRACE("column_major * scalar"); - TypeParam a(tester.ca.shape(), tester.ca.strides(), 0); - noalias(a) = tester.ca * tester.b; - EXPECT_TRUE(full_equal(tester.res_c, a)); - } - - { - SCOPED_TRACE("central_major * scalar"); - TypeParam a(tester.cta.shape(), tester.cta.strides(), 0); - noalias(a) = tester.cta * tester.b; - EXPECT_TRUE(full_equal(tester.res_ct, a)); - } - - { - SCOPED_TRACE("unit_major * scalar"); - TypeParam a(tester.ua.shape(), tester.ua.strides(), 0); - noalias(a) = tester.ua * tester.b; - EXPECT_TRUE(full_equal(tester.res_u, a)); - } - } - - TYPED_TEST(scalar_semantic, assign_a_divide_by_b) - { - scalar_operation_tester, TypeParam> tester; - - { - SCOPED_TRACE("row_major / scalar"); - TypeParam a(tester.ra.shape(), tester.ra.strides(), 0); - noalias(a) = tester.ra / tester.b; - EXPECT_TRUE(full_equal(tester.res_r, a)); - } - - { - SCOPED_TRACE("column_major / scalar"); - TypeParam a(tester.ca.shape(), tester.ca.strides(), 0); - noalias(a) = tester.ca / tester.b; - EXPECT_TRUE(full_equal(tester.res_c, a)); - } - - { - SCOPED_TRACE("central_major / scalar"); - TypeParam a(tester.cta.shape(), tester.cta.strides(), 0); - noalias(a) = tester.cta / tester.b; - EXPECT_TRUE(full_equal(tester.res_ct, a)); - } - - { - SCOPED_TRACE("unit_major / scalar"); - TypeParam a(tester.ua.shape(), tester.ua.strides(), 0); - noalias(a) = tester.ua / tester.b; - EXPECT_TRUE(full_equal(tester.res_u, a)); - } - } + #undef SCALAR_SEMANTIC_TEST_TYPES } diff --git a/test/test_xset_operation.cpp b/test/test_xset_operation.cpp index fa18cf4e8..49383ab5b 100644 --- a/test/test_xset_operation.cpp +++ b/test/test_xset_operation.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include diff --git a/test/test_xshape.cpp b/test/test_xshape.cpp index 7cdc56eb9..d06797e8e 100644 --- a/test/test_xshape.cpp +++ b/test/test_xshape.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xbroadcast.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xstrides.hpp" diff --git a/test/test_xsimd.cpp b/test/test_xsimd.cpp index ee935ca54..01cbb1cc0 100644 --- a/test/test_xsimd.cpp +++ b/test/test_xsimd.cpp @@ -6,14 +6,35 @@ * * * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ +#if defined(_MSC_VER) && !defined(__clang__) +#define VS_SKIP_XFIXED 1 +#endif + +// xfixed leads to ICE in debug mode, this provides +// an easy way to prevent compilation +#ifndef VS_SKIP_XFIXED + + +#if (_MSC_VER < 1910 && _WIN64) || (_MSC_VER >= 1910 && !defined(DISABLE_VS2017)) || !defined(_MSC_VER) #include #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xfixed.hpp" #include "xtensor/xtensor_config.hpp" +// On VS2015, when compiling in x86 mode, alignas(T) leads to C2718 +// when used for a function parameter, even indirectly. This means that +// we cannot pass parameters whose class is declared with alignas specifier +// or any type wrapping or inheriting from such a type. +// The xtensor_fixed class internally uses aligned_array which is declared as +// alignas(something_different_from_0), hence the workaround. +#if _MSC_VER < 1910 && !_WIN64 +#define VS_X86_WORKAROUND 1 +#endif + + template class alignas(XTENSOR_FIXED_ALIGN) Foo { @@ -50,3 +71,5 @@ namespace xt } } +#endif +#endif // VS_SKIP_XFIXED diff --git a/test/test_xsort.cpp b/test/test_xsort.cpp index a92efba67..8b367f575 100644 --- a/test/test_xsort.cpp +++ b/test/test_xsort.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xadapt.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xtensor.hpp" diff --git a/test/test_xstorage.cpp b/test/test_xstorage.cpp index 54ac95e2a..16d331191 100644 --- a/test/test_xstorage.cpp +++ b/test/test_xstorage.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_common_macros.hpp" #include "xtensor/xtensor_config.hpp" #include "xtensor/xstorage.hpp" diff --git a/test/test_xstrided_view.cpp b/test/test_xstrided_view.cpp index 8f1a82f5d..e6956a6ab 100644 --- a/test/test_xstrided_view.cpp +++ b/test/test_xstrided_view.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xbuilder.hpp" diff --git a/test/test_xstrides.cpp b/test/test_xstrides.cpp index 9173cef48..80f995099 100644 --- a/test/test_xstrides.cpp +++ b/test/test_xstrides.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "test_common.hpp" @@ -52,8 +52,8 @@ namespace xt TEST(xstrides, unravel_from_strides) { + SUBCASE("row_major strides") { - SCOPED_TRACE("row_major strides"); row_major_result<> rm; using index_type = xt::dynamic_shape; index_type index = { 2, 1, 1 }; @@ -62,8 +62,8 @@ namespace xt EXPECT_TRUE(std::equal(unrav_index.cbegin(), unrav_index.cend(), index.cbegin())); } + SUBCASE("column_major strides") { - SCOPED_TRACE("column_major strides"); column_major_result<> cm; using index_type = xt::dynamic_shape; index_type index = { 2, 1, 1 }; @@ -72,8 +72,8 @@ namespace xt EXPECT_TRUE(std::equal(unrav_index.cbegin(), unrav_index.cend(), index.cbegin())); } + SUBCASE("unit_major strides") { - SCOPED_TRACE("unit_major strides"); unit_shape_result<> um; using index_type = xt::dynamic_shape; index_type index = { 2, 0, 1 }; @@ -85,8 +85,8 @@ namespace xt TEST(xstrides, unravel_index) { + SUBCASE("row_major strides") { - SCOPED_TRACE("row_major strides"); row_major_result<> rm; using index_type = xt::dynamic_shape; index_type index = { 2, 1, 1 }; @@ -95,8 +95,8 @@ namespace xt EXPECT_TRUE(std::equal(unrav_index.cbegin(), unrav_index.cend(), index.cbegin())); } + SUBCASE("column_major strides") { - SCOPED_TRACE("column_major strides"); column_major_result<> cm; using index_type = xt::dynamic_shape; index_type index = { 2, 1, 1 }; @@ -105,8 +105,8 @@ namespace xt EXPECT_TRUE(std::equal(unrav_index.cbegin(), unrav_index.cend(), index.cbegin())); } + SUBCASE("unit_major strides") { - SCOPED_TRACE("unit_major strides"); unit_shape_result<> um; using index_type = xt::dynamic_shape; index_type index = { 2, 0, 1 }; diff --git a/test/test_xtensor.cpp b/test/test_xtensor.cpp index 1d8aedbdb..1bb77a9aa 100644 --- a/test/test_xtensor.cpp +++ b/test/test_xtensor.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xtensor.hpp" #include "xtensor/xarray.hpp" #include "test_common.hpp" @@ -44,22 +44,22 @@ namespace xt TEST(xtensor, shaped_constructor) { + SUBCASE("row_major constructor") { - SCOPED_TRACE("row_major constructor"); row_major_result rm; xtensor_dynamic ra(rm.m_shape, layout_type::row_major); compare_shape(ra, rm); } + SUBCASE("column_major constructor") { - SCOPED_TRACE("column_major constructor"); column_major_result cm; xtensor_dynamic ca(cm.m_shape, layout_type::column_major); compare_shape(ca, cm); } + SUBCASE("from shape") { - SCOPED_TRACE("from shape"); std::array shp = {5, 4, 2}; std::vector shp_as_vec = {5, 4, 2}; auto ca = xtensor::from_shape({3, 2, 1}); @@ -79,8 +79,8 @@ namespace xt TEST(xtensor, valued_constructor) { + SUBCASE("row_major valued constructor") { - SCOPED_TRACE("row_major valued constructor"); row_major_result rm; int value = 2; xtensor_dynamic ra(rm.m_shape, value, layout_type::row_major); @@ -89,8 +89,8 @@ namespace xt EXPECT_EQ(ra.storage(), vec); } + SUBCASE("column_major valued constructor") { - SCOPED_TRACE("column_major valued constructor"); column_major_result cm; int value = 2; xtensor_dynamic ca(cm.m_shape, value, layout_type::column_major); @@ -123,15 +123,15 @@ namespace xt int value = 2; xtensor_dynamic a(res.m_shape, res.m_strides, value); + SUBCASE("copy constructor") { - SCOPED_TRACE("copy constructor"); xtensor_dynamic b(a); compare_shape(a, b); EXPECT_EQ(a.storage(), b.storage()); } + SUBCASE("assignment operator") { - SCOPED_TRACE("assignment operator"); row_major_result r; xtensor_dynamic c(r.m_shape, 0); EXPECT_NE(a.storage(), c.storage()); @@ -147,16 +147,16 @@ namespace xt int value = 2; xtensor_dynamic a(res.m_shape, res.m_strides, value); + SUBCASE("move constructor") { - SCOPED_TRACE("move constructor"); xtensor_dynamic tmp(a); xtensor_dynamic b(std::move(tmp)); compare_shape(a, b); EXPECT_EQ(a.storage(), b.storage()); } + SUBCASE("move assignment") { - SCOPED_TRACE("move assignment"); row_major_result r; xtensor_dynamic c(r.m_shape, 0); EXPECT_NE(a.storage(), c.storage()); diff --git a/test/test_xtensor_adaptor.cpp b/test/test_xtensor_adaptor.cpp index 1bd9cc18c..1c03b45c4 100644 --- a/test/test_xtensor_adaptor.cpp +++ b/test/test_xtensor_adaptor.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xtensor.hpp" #include "test_common.hpp" @@ -19,16 +19,16 @@ namespace xt TEST(xtensor_adaptor, shaped_constructor) { + SUBCASE("row_major constructor") { - SCOPED_TRACE("row_major constructor"); row_major_result rm; vec_type v; adaptor_type a(v, rm.shape(), layout_type::row_major); compare_shape(a, rm); } + SUBCASE("column_major constructor") { - SCOPED_TRACE("column_major constructor"); column_major_result cm; vec_type v; adaptor_type a(v, cm.shape(), layout_type::column_major); @@ -51,15 +51,15 @@ namespace xt vec_type v(res.size(), value); adaptor_type a(v, res.shape(), res.strides()); + SUBCASE("copy constructor") { - SCOPED_TRACE("copy constructor"); adaptor_type b(a); compare_shape(a, b); EXPECT_EQ(a.storage(), b.storage()); } + SUBCASE("assignment operator") { - SCOPED_TRACE("assignment operator"); row_major_result r; vec_type v2(r.size(), 0); adaptor_type c(v2, r.shape()); @@ -77,16 +77,16 @@ namespace xt vec_type v(res.size(), value); adaptor_type a(v, res.shape(), res.strides()); + SUBCASE("move constructor") { - SCOPED_TRACE("move constructor"); adaptor_type tmp(a); adaptor_type b(std::move(tmp)); compare_shape(a, b); EXPECT_EQ(a.storage(), b.storage()); } + SUBCASE("move assignment") { - SCOPED_TRACE("move assignment"); row_major_result r; vec_type v2(r.size(), 0); adaptor_type c(v2, r.shape()); diff --git a/test/test_xtensor_semantic.cpp b/test/test_xtensor_semantic.cpp index 8eaaa5f0f..36a0135b1 100644 --- a/test/test_xtensor_semantic.cpp +++ b/test/test_xtensor_semantic.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xtensor.hpp" #include "xtensor/xarray.hpp" #include "test_common.hpp" diff --git a/test/test_xutils.cpp b/test/test_xutils.cpp index 71fd55fc8..8f41839fa 100644 --- a/test/test_xutils.cpp +++ b/test/test_xutils.cpp @@ -12,7 +12,7 @@ #include #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_common_macros.hpp" #include "xtensor/xtensor.hpp" #include "xtensor/xarray.hpp" diff --git a/test/test_xvectorize.cpp b/test/test_xvectorize.cpp index d49c888e1..e31281bb0 100644 --- a/test/test_xvectorize.cpp +++ b/test/test_xvectorize.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xarray.hpp" #include "xtensor/xvectorize.hpp" diff --git a/test/test_xview.cpp b/test/test_xview.cpp index f0705c868..503dee38c 100644 --- a/test/test_xview.cpp +++ b/test/test_xview.cpp @@ -9,7 +9,7 @@ #include -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "test_common_macros.hpp" // Workaround to avoid warnings regarding initialization @@ -178,8 +178,8 @@ namespace xt std::vector data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; std::copy(data.cbegin(), data.cend(), a.template begin()); + SUBCASE("copy constructor") { - SCOPED_TRACE("copy constructor"); auto view1 = view(a, 1, range(1, 4)); auto view2(view1); EXPECT_EQ(a(1, 1), view2(0)); @@ -195,8 +195,8 @@ namespace xt } } + SUBCASE("copy assignment operator") { - SCOPED_TRACE("copy assignment operator"); auto view1 = view(a, 1, range(1, 4)); auto view2 = view(a, 2, range(0, 3)); view2 = view1; @@ -213,8 +213,8 @@ namespace xt std::vector data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; std::copy(data.cbegin(), data.cend(), a.template begin()); + SUBCASE("copy constructor") { - SCOPED_TRACE("copy constructor"); auto view1 = view(a, 1, range(1, 4)); auto view2(std::move(view1)); EXPECT_EQ(a(1, 1), view2(0)); @@ -230,8 +230,8 @@ namespace xt } } + SUBCASE("copy assignment operator") { - SCOPED_TRACE("copy assignment operator"); auto view1 = view(a, 1, range(1, 4)); auto view2 = view(a, 2, range(0, 3)); view2 = std::move(view1); @@ -1727,12 +1727,4 @@ namespace xt std::invalid_argument ); } - - // This code should not compile! - //TEST(xview, col_on_3dim_xtensor) - //{ - // xt::xtensor tensor; - // xt::row(tensor, 0); - // xt::col(tensor, 0); - //} } diff --git a/test/test_xview_semantic.cpp b/test/test_xview_semantic.cpp index 383d7fa94..a7fc04766 100644 --- a/test/test_xview_semantic.cpp +++ b/test/test_xview_semantic.cpp @@ -7,7 +7,7 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ -#include "gtest/gtest.h" +#include "test_common_macros.hpp" #include "xtensor/xview.hpp" #include "test_xsemantic.hpp" #include "xtensor/xnoalias.hpp" @@ -79,387 +79,391 @@ namespace xt using storage_type = C; }; - using testing_types = ::testing::Types; - TYPED_TEST_SUITE(view_semantic, testing_types); + #define VIEW_SEMANTIC_TEST_TYPES xarray_dynamic, xtensor_dynamic - TYPED_TEST(view_semantic, a_plus_b) + TEST_SUITE("view_semantic") { - view_op_tester, TypeParam> t; - auto viewa = view(t.a, t.x_slice, t.y_slice, t.z_slice); - + TEST_CASE_TEMPLATE("a_plus_b", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major + row_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa + viewra; - EXPECT_EQ(t.vres_rr, b); - } + view_op_tester, TypeParam> t; + auto viewa = view(t.a, t.x_slice, t.y_slice, t.z_slice); - { - SCOPED_TRACE("row_major + column_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa + viewca; - EXPECT_EQ(t.vres_rc, b); - } + SUBCASE("row_major + row_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa + viewra; + EXPECT_EQ(t.vres_rr, b); + } - { - SCOPED_TRACE("row_major + central_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa + viewcta; - EXPECT_EQ(t.vres_rct, b); + SUBCASE("row_major + column_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa + viewca; + EXPECT_EQ(t.vres_rc, b); + } + + SUBCASE("row_major + central_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa + viewcta; + EXPECT_EQ(t.vres_rct, b); + } + + SUBCASE("row_major + unit_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa + viewua; + EXPECT_EQ(t.vres_ru, b); + } } + TEST_CASE_TEMPLATE("a_minus_b", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major + unit_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa + viewua; - EXPECT_EQ(t.vres_ru, b); - } - } + view_op_tester, TypeParam> t; + auto viewa = view(t.a, t.x_slice, t.y_slice, t.z_slice); - TYPED_TEST(view_semantic, a_minus_b) - { - view_op_tester, TypeParam> t; - auto viewa = view(t.a, t.x_slice, t.y_slice, t.z_slice); + SUBCASE("row_major - row_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa - viewra; + EXPECT_EQ(t.vres_rr, b); + } - { - SCOPED_TRACE("row_major - row_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa - viewra; - EXPECT_EQ(t.vres_rr, b); - } + SUBCASE("row_major - column_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa - viewca; + EXPECT_EQ(t.vres_rc, b); + } - { - SCOPED_TRACE("row_major - column_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa - viewca; - EXPECT_EQ(t.vres_rc, b); - } + SUBCASE("row_major - central_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa - viewcta; + EXPECT_EQ(t.vres_rct, b); + } - { - SCOPED_TRACE("row_major - central_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa - viewcta; - EXPECT_EQ(t.vres_rct, b); + SUBCASE("row_major - unit_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa - viewua; + EXPECT_EQ(t.vres_ru, b); + } } + TEST_CASE_TEMPLATE("a_times_b", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major - unit_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa - viewua; - EXPECT_EQ(t.vres_ru, b); - } - } + view_op_tester, TypeParam> t; + auto viewa = view(t.a, t.x_slice, t.y_slice, t.z_slice); - TYPED_TEST(view_semantic, a_times_b) - { - view_op_tester, TypeParam> t; - auto viewa = view(t.a, t.x_slice, t.y_slice, t.z_slice); + SUBCASE("row_major * row_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa * viewra; + EXPECT_EQ(t.vres_rr, b); + } - { - SCOPED_TRACE("row_major * row_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa * viewra; - EXPECT_EQ(t.vres_rr, b); - } + SUBCASE("row_major * column_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa * viewca; + EXPECT_EQ(t.vres_rc, b); + } - { - SCOPED_TRACE("row_major * column_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa * viewca; - EXPECT_EQ(t.vres_rc, b); - } + SUBCASE("row_major * central_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa * viewcta; + EXPECT_EQ(t.vres_rct, b); + } - { - SCOPED_TRACE("row_major * central_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa * viewcta; - EXPECT_EQ(t.vres_rct, b); + SUBCASE("row_major * unit_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa * viewua; + EXPECT_EQ(t.vres_ru, b); + } } + TEST_CASE_TEMPLATE("a_divdide_by_b", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major * unit_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa * viewua; - EXPECT_EQ(t.vres_ru, b); - } - } + view_op_tester, TypeParam> t; + auto viewa = view(t.a, t.x_slice, t.y_slice, t.z_slice); - TYPED_TEST(view_semantic, a_divdide_by_b) - { - view_op_tester, TypeParam> t; - auto viewa = view(t.a, t.x_slice, t.y_slice, t.z_slice); + SUBCASE("row_major / row_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa / viewra; + EXPECT_EQ(t.vres_rr, b); + } - { - SCOPED_TRACE("row_major / row_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa / viewra; - EXPECT_EQ(t.vres_rr, b); - } + SUBCASE("row_major / column_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa / viewca; + EXPECT_EQ(t.vres_rc, b); + } - { - SCOPED_TRACE("row_major / column_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa / viewca; - EXPECT_EQ(t.vres_rc, b); - } + SUBCASE("row_major / central_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa / viewcta; + EXPECT_EQ(t.vres_rct, b); + } - { - SCOPED_TRACE("row_major / central_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa / viewcta; - EXPECT_EQ(t.vres_rct, b); + SUBCASE("row_major / unit_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); + viewb = viewa / viewua; + EXPECT_EQ(t.vres_ru, b); + } } + TEST_CASE_TEMPLATE("a_plus_equal_b", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major / unit_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); - viewb = viewa / viewua; - EXPECT_EQ(t.vres_ru, b); - } - } + view_op_tester, TypeParam> t; - TYPED_TEST(view_semantic, a_plus_equal_b) - { - view_op_tester, TypeParam> t; + SUBCASE("row_major += row_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); + viewb += viewra; + EXPECT_EQ(t.vres_rr, b); + } - { - SCOPED_TRACE("row_major += row_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); - viewb += viewra; - EXPECT_EQ(t.vres_rr, b); - } + SUBCASE("row_major += column_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); + viewb += viewca; + EXPECT_EQ(t.vres_rc, b); + } - { - SCOPED_TRACE("row_major += column_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); - viewb += viewca; - EXPECT_EQ(t.vres_rc, b); - } + SUBCASE("row_major += central_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); + viewb += viewcta; + EXPECT_EQ(t.vres_rct, b); + } - { - SCOPED_TRACE("row_major += central_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); - viewb += viewcta; - EXPECT_EQ(t.vres_rct, b); + SUBCASE("row_major += unit_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); + viewb += viewua; + EXPECT_EQ(t.vres_ru, b); + } } + TEST_CASE_TEMPLATE("a_minus_equal_b", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major += unit_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); - viewb += viewua; - EXPECT_EQ(t.vres_ru, b); - } - } + view_op_tester, TypeParam> t; - TYPED_TEST(view_semantic, a_minus_equal_b) - { - view_op_tester, TypeParam> t; + SUBCASE("row_major -= row_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); + viewb -= viewra; + EXPECT_EQ(t.vres_rr, b); + } - { - SCOPED_TRACE("row_major -= row_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); - viewb -= viewra; - EXPECT_EQ(t.vres_rr, b); - } + SUBCASE("row_major -= column_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); + viewb -= viewca; + EXPECT_EQ(t.vres_rc, b); + } - { - SCOPED_TRACE("row_major -= column_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); - viewb -= viewca; - EXPECT_EQ(t.vres_rc, b); - } + SUBCASE("row_major -= central_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); + viewb -= viewcta; + EXPECT_EQ(t.vres_rct, b); + } - { - SCOPED_TRACE("row_major -= central_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); - viewb -= viewcta; - EXPECT_EQ(t.vres_rct, b); + SUBCASE("row_major -= unit_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); + viewb -= viewua; + EXPECT_EQ(t.vres_ru, b); + } } + TEST_CASE_TEMPLATE("a_times_equal_b", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major -= unit_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); - viewb -= viewua; - EXPECT_EQ(t.vres_ru, b); - } - } + view_op_tester, TypeParam> t; - TYPED_TEST(view_semantic, a_times_equal_b) - { - view_op_tester, TypeParam> t; + SUBCASE("row_major *= row_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); + viewb *= viewra; + EXPECT_EQ(t.vres_rr, b); + } - { - SCOPED_TRACE("row_major *= row_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); - viewb *= viewra; - EXPECT_EQ(t.vres_rr, b); - } + SUBCASE("row_major *= column_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); + viewb *= viewca; + EXPECT_EQ(t.vres_rc, b); + } - { - SCOPED_TRACE("row_major *= column_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); - viewb *= viewca; - EXPECT_EQ(t.vres_rc, b); - } + SUBCASE("row_major *= central_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); + viewb *= viewcta; + EXPECT_EQ(t.vres_rct, b); + } - { - SCOPED_TRACE("row_major *= central_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); - viewb *= viewcta; - EXPECT_EQ(t.vres_rct, b); + SUBCASE("row_major *= unit_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); + viewb *= viewua; + EXPECT_EQ(t.vres_ru, b); + } } + TEST_CASE_TEMPLATE("a_divide_by_equal_b", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major *= unit_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); - viewb *= viewua; - EXPECT_EQ(t.vres_ru, b); - } - } + view_op_tester, TypeParam> t; - TYPED_TEST(view_semantic, a_divide_by_equal_b) - { - view_op_tester, TypeParam> t; + SUBCASE("row_major /= row_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); + viewb /= viewra; + EXPECT_EQ(t.vres_rr, b); + } - { - SCOPED_TRACE("row_major /= row_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewra = view(t.ra, t.x_slice, t.y_slice, t.z_slice); - viewb /= viewra; - EXPECT_EQ(t.vres_rr, b); + SUBCASE("row_major /= column_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); + viewb /= viewca; + EXPECT_EQ(t.vres_rc, b); + } + + SUBCASE("row_major /= central_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); + viewb /= viewcta; + EXPECT_EQ(t.vres_rct, b); + } + + SUBCASE("row_major /= unit_major") + { + TypeParam b = t.a; + auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); + auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); + viewb /= viewua; + EXPECT_EQ(t.vres_ru, b); + } } + TEST_CASE_TEMPLATE("broadcast_equal", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major /= column_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewca = view(t.ca, t.x_slice, t.y_slice, t.z_slice); - viewb /= viewca; - EXPECT_EQ(t.vres_rc, b); + using container_1d = redim_container_t; + using container_2d = redim_container_t; + container_2d a = {{1, 2, 3, 4}, + {5, 6, 7, 8}, + {9, 10, 11, 12}}; + container_2d b = a; + auto viewa = view(a, all(), range(1, 4)); + auto viewb = view(b, all(), range(1, 4)); + container_1d c = {1, 2, 3}; + viewa = c; + noalias(viewb) = c; + container_2d res = {{1, 1, 2, 3}, + {5, 1, 2, 3}, + {9, 1, 2, 3}}; + + EXPECT_EQ(res, a); + EXPECT_EQ(res, b); } + TEST_CASE_TEMPLATE("scalar_equal", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major /= central_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewcta = view(t.cta, t.x_slice, t.y_slice, t.z_slice); - viewb /= viewcta; - EXPECT_EQ(t.vres_rct, b); + using container_2d = redim_container_t; + container_2d a = {{1, 2, 3, 4}, + {5, 6, 7, 8}, + {9, 10, 11, 12}}; + auto viewa = view(a, all(), range(1, 4)); + int b = 1; + viewa = b; + container_2d res = {{1, 1, 1, 1}, + {5, 1, 1, 1}, + {9, 1, 1, 1}}; + + EXPECT_EQ(res, a); } + TEST_CASE_TEMPLATE("higher_dimension_broadcast", TypeParam, VIEW_SEMANTIC_TEST_TYPES) { - SCOPED_TRACE("row_major /= unit_major"); - TypeParam b = t.a; - auto viewb = view(b, t.x_slice, t.y_slice, t.z_slice); - auto viewua = view(t.ua, t.x_slice, t.y_slice, t.z_slice); - viewb /= viewua; - EXPECT_EQ(t.vres_ru, b); - } - } + using container_2d = redim_container_t; - TYPED_TEST(view_semantic, broadcast_equal) - { - using container_1d = redim_container_t; - using container_2d = redim_container_t; - container_2d a = {{1, 2, 3, 4}, - {5, 6, 7, 8}, - {9, 10, 11, 12}}; - container_2d b = a; - auto viewa = view(a, all(), range(1, 4)); - auto viewb = view(b, all(), range(1, 4)); - container_1d c = {1, 2, 3}; - viewa = c; - noalias(viewb) = c; - container_2d res = {{1, 1, 2, 3}, - {5, 1, 2, 3}, - {9, 1, 2, 3}}; - - EXPECT_EQ(res, a); - EXPECT_EQ(res, b); - } + container_2d a = { {1, 2, 3}, {4, 5, 6} }; + container_2d b = { {11, 12, 13} }; + container_2d res = { { 11, 12, 13 }, { 4, 5, 6 } }; - TYPED_TEST(view_semantic, scalar_equal) - { - using container_2d = redim_container_t; - container_2d a = {{1, 2, 3, 4}, - {5, 6, 7, 8}, - {9, 10, 11, 12}}; - auto viewa = view(a, all(), range(1, 4)); - int b = 1; - viewa = b; - container_2d res = {{1, 1, 1, 1}, - {5, 1, 1, 1}, - {9, 1, 1, 1}}; - - EXPECT_EQ(res, a); + auto viewa = view(a, 0, all()); + XT_EXPECT_ANY_THROW(viewa = b); + } } - TYPED_TEST(view_semantic, higher_dimension_broadcast) - { - using container_2d = redim_container_t; - - container_2d a = { {1, 2, 3}, {4, 5, 6} }; - container_2d b = { {11, 12, 13} }; - container_2d res = { { 11, 12, 13 }, { 4, 5, 6 } }; - - auto viewa = view(a, 0, all()); - XT_EXPECT_ANY_THROW(viewa = b); - } + #undef VIEW_SEMANTIC_TEST_TYPES }