From 0468c7cb1d32c5479c2537911ab04290f92079dc Mon Sep 17 00:00:00 2001 From: FrancoisCarouge Date: Mon, 7 Oct 2024 18:35:31 -0700 Subject: [PATCH] [linalg] lazy linalg tests --- linalg/CMakeLists.txt | 1 + support/CMakeLists.txt | 30 ++++++++ test/CMakeLists.txt | 16 ++++- ...onstructor_initializer_lists_deduction.cpp | 71 +++++++++++++++++++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 test/linalg_constructor_initializer_lists_deduction.cpp diff --git a/linalg/CMakeLists.txt b/linalg/CMakeLists.txt index d5f6457d4..dcb8aef75 100644 --- a/linalg/CMakeLists.txt +++ b/linalg/CMakeLists.txt @@ -37,4 +37,5 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to ]] add_subdirectory("eigen") +add_subdirectory("lazy") add_subdirectory("naive") diff --git a/support/CMakeLists.txt b/support/CMakeLists.txt index 69fc1e702..9824cf006 100644 --- a/support/CMakeLists.txt +++ b/support/CMakeLists.txt @@ -115,3 +115,33 @@ install( EXPORT "kalman-target" FILE_SET "kalman_print_headers" DESTINATION "include/fcarouge") + +include(CheckSourceCompiles) +include(FetchContent) + +add_library(kalman_generator INTERFACE) + +check_source_compiles( + CXX + " + #include + int main() {} + " + CPP_LIB_GENERATOR) + +if(NOT CPP_LIB_GENERATOR) + FetchContent_Declare( + stdgenerator + GIT_REPOSITORY "https://github.com/FrancoisCarouge/generator" + FIND_PACKAGE_ARGS NAMES stdgenerator) + FetchContent_MakeAvailable(stdgenerator) + + target_sources(kalman_generator INTERFACE FILE_SET "kalman_generator_headers" + TYPE "HEADERS" FILES "generator") + target_link_libraries(kalman_generator INTERFACE stdgenerator::stdgenerator) + install( + TARGETS kalman_generator + EXPORT "kalman-target" + FILE_SET "kalman_generator_headers" + DESTINATION "include/fcarouge") +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3e94c4dea..9e7098dae 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -54,7 +54,7 @@ foreach( COMMAND ${TEST_COMMAND} $) endforeach() -foreach(BACKEND IN ITEMS "eigen" "naive") +foreach(BACKEND IN ITEMS "eigen" "lazy" "naive") foreach( TEST "linalg_addition.cpp" @@ -114,3 +114,17 @@ foreach(BACKEND IN ITEMS "eigen") $) endforeach() endforeach() + +foreach(BACKEND IN ITEMS "lazy") + foreach(TEST "linalg_constructor_initializer_lists_deduction.cpp") + get_filename_component(NAME ${TEST} NAME_WE) + add_executable(kalman_test_${BACKEND}_${NAME}_driver ${TEST}) + target_link_libraries( + kalman_test_${BACKEND}_${NAME}_driver + PRIVATE kalman kalman_main kalman_linalg_${BACKEND} kalman_options) + separate_arguments(TEST_COMMAND UNIX_COMMAND $ENV{COMMAND}) + add_test(NAME kalman_test_${BACKEND}_${NAME} + COMMAND ${TEST_COMMAND} + $) + endforeach() +endforeach() diff --git a/test/linalg_constructor_initializer_lists_deduction.cpp b/test/linalg_constructor_initializer_lists_deduction.cpp new file mode 100644 index 000000000..3ece94f2e --- /dev/null +++ b/test/linalg_constructor_initializer_lists_deduction.cpp @@ -0,0 +1,71 @@ +/* __ _ __ __ _ _ +| |/ / /\ | | | \/ | /\ | \ | | +| ' / / \ | | | \ / | / \ | \| | +| < / /\ \ | | | |\/| | / /\ \ | . ` | +| . \ / ____ \| |____| | | |/ ____ \| |\ | +|_|\_\/_/ \_\______|_| |_/_/ \_\_| \_| + +Kalman Filter +Version 0.4.0 +https://github.com/FrancoisCarouge/Kalman + +SPDX-License-Identifier: Unlicense + +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to */ + +#include "fcarouge/linalg.hpp" + +#include + +#include +#include + +namespace fcarouge::test { +namespace { +//! @test Verifies the initializer lists constructor. +//! +//! @todo Rewrite this test as a property-based test. +//! @todo Static assert the sizes and value type? +[[maybe_unused]] auto test{[] { + matrix m{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {1, 2, 3}}; + + assert(m(0, 0) == 1); + assert(m(0, 1) == 2); + assert(m(0, 2) == 3); + assert(m(1, 0) == 4); + assert(m(1, 1) == 5); + assert(m(1, 2) == 6); + assert(m(2, 0) == 7); + assert(m(2, 1) == 8); + assert(m(2, 2) == 9); + assert(m(3, 0) == 1); + assert(m(3, 1) == 2); + assert(m(3, 2) == 3); + + return 0; +}()}; +} // namespace +} // namespace fcarouge::test