From ea8e593497ea21ec40c41a5d0327229e84053d28 Mon Sep 17 00:00:00 2001 From: Simon Vidanovic Date: Fri, 1 Nov 2024 10:43:36 -0700 Subject: [PATCH] Handling local test files is added. Matrices comparison is now separate rotine that can be reused. --- src/MultiLayerOptics/CMakeLists.txt | 21 +++-- src/SingleLayerOptics/CMakeLists.txt | 22 ++++-- .../units/VenetianUniformShadeMatrix.unit.cpp | 76 ++++--------------- src/Tarcog/CMakeLists.txt | 2 +- src/helper/csvHandlers.cpp | 59 ++++++++++++++ src/helper/csvHandlers.hpp | 18 +++++ src/helper/matrixTesting.cpp | 19 +++++ src/helper/matrixTesting.hpp | 11 +++ 8 files changed, 154 insertions(+), 74 deletions(-) create mode 100644 src/helper/csvHandlers.cpp create mode 100644 src/helper/csvHandlers.hpp create mode 100644 src/helper/matrixTesting.cpp create mode 100644 src/helper/matrixTesting.hpp diff --git a/src/MultiLayerOptics/CMakeLists.txt b/src/MultiLayerOptics/CMakeLists.txt index 4ff47c9f..17d1faf6 100644 --- a/src/MultiLayerOptics/CMakeLists.txt +++ b/src/MultiLayerOptics/CMakeLists.txt @@ -35,13 +35,22 @@ install(TARGETS ${target_name} if( BUILD_WCE_TESTING ) # common helper files for the testing include_directories( ../helper ) - file( GLOB all_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "../helper/*.hpp" ) - file( GLOB all_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "../helper/*.cpp" ) - LIST( APPEND test_src ${all_test_src} ) + + # Collect helper files + file( GLOB helper_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "../helper/*.hpp" "../helper/*.cpp") + list( APPEND test_src ${helper_test_src} ) + + # Include main test files include_directories( include ) - file( GLOB all_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" tst/units/*.cpp ) - set( test_src ${all_test_src} ) + file( GLOB unit_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "tst/units/*.cpp" ) + list( APPEND test_src ${unit_test_src} ) + + # Create test targets CREATE_TEST_TARGETS_WCE( ${target_name} "${test_src}" "" ) -endif () + + # Set test data directory + set(TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tst") + target_compile_definitions(${target_name}_tests PRIVATE TEST_DATA_DIR="${TEST_DATA_DIR}") +endif() warning_level_update_wce() \ No newline at end of file diff --git a/src/SingleLayerOptics/CMakeLists.txt b/src/SingleLayerOptics/CMakeLists.txt index 86dde384..6b13ce0c 100644 --- a/src/SingleLayerOptics/CMakeLists.txt +++ b/src/SingleLayerOptics/CMakeLists.txt @@ -33,13 +33,23 @@ install(TARGETS ${target_name} if( BUILD_WCE_TESTING ) # common helper files for the testing include_directories( ../helper ) - file( GLOB all_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "../helper/*.hpp" ) - file( GLOB all_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "../helper/*.cpp" ) - LIST( APPEND test_src ${all_test_src} ) + + # Collect helper files + file( GLOB helper_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "../helper/*.hpp" "../helper/*.cpp") + list( APPEND test_src ${helper_test_src} ) + + # Include main test files include_directories( include ) - file( GLOB all_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" tst/units/*.cpp ) - set( test_src ${all_test_src} ) + file( GLOB unit_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "tst/units/*.cpp" ) + list( APPEND test_src ${unit_test_src} ) + + # Create test targets CREATE_TEST_TARGETS_WCE( ${target_name} "${test_src}" "" ) -endif () + + # Set test data directory + set(TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tst") + target_compile_definitions(${target_name}_tests PRIVATE TEST_DATA_DIR="${TEST_DATA_DIR}") +endif() + warning_level_update_wce() \ No newline at end of file diff --git a/src/SingleLayerOptics/tst/units/VenetianUniformShadeMatrix.unit.cpp b/src/SingleLayerOptics/tst/units/VenetianUniformShadeMatrix.unit.cpp index 5908f7ac..afb4b626 100644 --- a/src/SingleLayerOptics/tst/units/VenetianUniformShadeMatrix.unit.cpp +++ b/src/SingleLayerOptics/tst/units/VenetianUniformShadeMatrix.unit.cpp @@ -4,27 +4,30 @@ #include "WCECommon.hpp" #include "WCESingleLayerOptics.hpp" +#include "csvHandlers.hpp" +#include "matrixTesting.hpp" + class TestVenetianUniformShadeMatrix : public testing::Test { private: std::shared_ptr m_Shade; protected: - virtual void SetUp() + void SetUp() override { // create material - const auto Tmat = 0.1; - const auto Rfmat = 0.7; - const auto Rbmat = 0.7; + const auto Tmat = 0.0; + const auto Rfmat = 0.1; + const auto Rbmat = 0.1; const auto aMaterial = SingleLayerOptics::Material::singleBandMaterial(Tmat, Tmat, Rfmat, Rbmat); // make cell geometry - const auto slatWidth = 0.010; // m - const auto slatSpacing = 0.010; // m - const auto slatTiltAngle = 45; + const auto slatWidth = 0.016; // m + const auto slatSpacing = 0.012; // m + const auto slatTiltAngle = 0; const auto curvatureRadius = 0; - const size_t numOfSlatSegments = 5; + const size_t numOfSlatSegments = 1; // create BSDF const auto aBSDF = @@ -60,58 +63,9 @@ TEST_F(TestVenetianUniformShadeMatrix, TestVenetianMatrix) FenestrationCommon::SquareMatrix & aT = aResults.getMatrix(FenestrationCommon::Side::Front, FenestrationCommon::PropertySimple::T); - // clang-format off - std::vector> correctResults{ - {3.85984,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,4.156385,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,6.422513,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,7.361174,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,6.422513,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,4.156385,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,1.890257,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.951597,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,1.890257,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,3.856836,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,7.17719,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,9.607858,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,10.497544,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,9.607858,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,7.17719,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,3.856836,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.536482,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.536482,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,3.856836,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,10.147005,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,11.254628,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,9.581077,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,11.254628,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,10.147005,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,3.856836,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,3.668835,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,3.668835,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303}, - {0.050107,0.050107,0.038595,0.033826,0.038595,0.050107,0.061619,0.066388,0.061619,0.050107,0.031904,0.018579,0.013702,0.018579,0.031904,0.050107,0.06831,0.065066,0.062441,0.065066,0.06831,0.050107,0.015623,0.022003,0.043137,0.022003,0.015623,0.050107,0.063475,0.055055,0.05249,0.055055,0.063475,0.050107,0.148234,0.131012,0.148234,0.050107,0.044303,0.042115,0.044303} - }; - // clang-format on + const std::string fileName = + TEST_DATA_DIR "/data/TestVenetianUniformShadeMatrix_T=0_R=0.1_Slat=0.csv"; + const auto correctResults{Helper::readVectorFromCSV(fileName)}; - EXPECT_EQ(aT.size(), aT.size()); - for(size_t i = 0; i < aT.size(); ++i) - { - for(size_t j = 0u; j < aT.size(); ++j) - { - EXPECT_NEAR(correctResults[i][j], aT(i, j), 1e-6); - } - } + Helper::compareMatrices(correctResults, aT.getMatrix()); } diff --git a/src/Tarcog/CMakeLists.txt b/src/Tarcog/CMakeLists.txt index 66f49903..fae99ffd 100644 --- a/src/Tarcog/CMakeLists.txt +++ b/src/Tarcog/CMakeLists.txt @@ -35,7 +35,7 @@ if( BUILD_WCE_TESTING ) file( GLOB all_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "../helper/*.cpp" ) LIST( APPEND test_src ${all_test_src} ) - include_directories( include ) + include_directories( include ) file( GLOB all_test_src RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" tst/units/*.cpp ) set( test_src ${all_test_src} ) CREATE_TEST_TARGETS_WCE( ${target_name} "${test_src}" "" ) diff --git a/src/helper/csvHandlers.cpp b/src/helper/csvHandlers.cpp new file mode 100644 index 00000000..ad13150a --- /dev/null +++ b/src/helper/csvHandlers.cpp @@ -0,0 +1,59 @@ +#include + +#include "csvHandlers.hpp" + +namespace Helper +{ + void writeVectorToCSV(const std::vector> & data, + const std::string & filename) + { + std::ofstream file(filename); + if(!file.is_open()) + { + throw std::runtime_error("Could not open file to write"); + } + + file << std::fixed << std::setprecision(9); // Set precision to 9 decimal places + + for(const auto & row : data) + { + for(size_t i = 0; i < row.size(); ++i) + { + file << row[i]; + if(i < row.size() - 1) + { + file << ","; // Add comma if not the last element + } + } + file << "\n"; + } + file.close(); + } + + std::vector> readVectorFromCSV(const std::string & filename) + { + std::ifstream file(filename); + if(!file.is_open()) + { + throw std::runtime_error("Could not open file to read"); + } + + std::vector> data; + std::string line; + + while(std::getline(file, line)) + { + std::vector row; + std::stringstream ss(line); + std::string value; + + while(std::getline(ss, value, ',')) + { + row.push_back(std::stod(value)); // Convert string to double and add to row + } + data.push_back(row); + } + file.close(); + return data; + } +} // namespace Helper diff --git a/src/helper/csvHandlers.hpp b/src/helper/csvHandlers.hpp new file mode 100644 index 00000000..cbb3800f --- /dev/null +++ b/src/helper/csvHandlers.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace Helper +{ + // Function to write a 2D vector to a CSV file + void writeVectorToCSV(const std::vector> & data, + const std::string & filename); + + // Function to read a 2D vector from a CSV file + std::vector> readVectorFromCSV(const std::string & filename); +} // namespace Helper \ No newline at end of file diff --git a/src/helper/matrixTesting.cpp b/src/helper/matrixTesting.cpp new file mode 100644 index 00000000..be256a4e --- /dev/null +++ b/src/helper/matrixTesting.cpp @@ -0,0 +1,19 @@ +#include "matrixTesting.hpp" + +namespace Helper +{ + void compareMatrices(const std::vector> & expected, + const std::vector> & actual, + double tolerance) + { + ASSERT_EQ(expected.size(), actual.size()); + for(size_t i = 0; i < expected.size(); ++i) + { + ASSERT_EQ(expected[i].size(), actual[i].size()); + for(size_t j = 0; j < expected[i].size(); ++j) + { + EXPECT_NEAR(expected[i][j], actual[i][j], tolerance); + } + } + } +} \ No newline at end of file diff --git a/src/helper/matrixTesting.hpp b/src/helper/matrixTesting.hpp new file mode 100644 index 00000000..c67e7cd6 --- /dev/null +++ b/src/helper/matrixTesting.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include +#include "gtest/gtest.h" + +namespace Helper +{ + void compareMatrices(const std::vector> & expected, + const std::vector> & actual, + double tolerance = 1e-6); +} \ No newline at end of file