//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== #include "unit/tests.hpp" #include void test_value(auto const& matrix, std::size_t rows, std::size_t cols, auto constant) { TTS_EXPECT(verify_rotgen_reentrance(matrix)); for (std::size_t r = 0; r < rows; ++r) for (std::size_t c = 0; c < cols; ++c) TTS_EQUAL(matrix(r, c), constant); } void test_random(auto const& matrix, std::size_t rows, std::size_t cols) { TTS_EXPECT(verify_rotgen_reentrance(matrix)); for (std::size_t r = 0; r < rows; ++r) for (std::size_t c = 0; c < cols; ++c) { TTS_GREATER_EQUAL(matrix(r, c), -1.0); TTS_LESS_EQUAL(matrix(r, c), 1.0); } } void test_identity(auto const& matrix, std::size_t rows, std::size_t cols) { TTS_EXPECT(verify_rotgen_reentrance(matrix)); for (std::size_t r = 0; r < rows; ++r) for (std::size_t c = 0; c < cols; ++c) TTS_EQUAL(matrix(r, c), r == c ? 1 : 0); } TTS_CASE_TPL("Test zero", rotgen::tests::types)( tts::type>) { using namespace rotgen; test_value(setZero>(), 3, 4, 0); test_value(setZero>(), 1, 1, 0); test_value(setZero>(), 10, 10, 0); test_value(setZero>(3, 4), 3, 4, 0); test_value(setZero>(7, 5), 7, 5, 0); test_value(setZero>(9, 3), 9, 3, 0); test_value(setZero>(2, 3), 2, 3, 0); test_value(setZero(matrix{}), 3, 4, 0); test_value(setZero(matrix{}), 1, 1, 0); test_value(setZero(matrix{}), 10, 10, 0); test_value(setZero(matrix{3, 4}), 3, 4, 0); test_value(setZero(matrix{}), 7, 5, 0); test_value(setZero(matrix{9, 3}), 9, 3, 0); test_value(setZero(matrix{2, 3}), 2, 3, 0); }; TTS_CASE_TPL("Test ones", rotgen::tests::types)( tts::type>) { using namespace rotgen; test_value(setOnes>(), 3, 4, 1); test_value(setOnes>(), 1, 1, 1); test_value(setOnes>(), 10, 10, 1); test_value(setOnes>(3, 4), 3, 4, 1); test_value(setOnes>(7, 5), 7, 5, 1); test_value(setOnes>(9, 3), 9, 3, 1); test_value(setOnes>(2, 3), 2, 3, 1); test_value(setOnes(matrix{}), 3, 4, 1); test_value(setOnes(matrix{}), 1, 1, 1); test_value(setOnes(matrix{}), 10, 10, 1); test_value(setOnes(matrix{3, 4}), 3, 4, 1); test_value(setOnes(matrix{}), 7, 5, 1); test_value(setOnes(matrix{9, 3}), 9, 3, 1); test_value(setOnes(matrix{2, 3}), 2, 3, 1); }; TTS_CASE_TPL("Test constant", rotgen::tests::types)( tts::type>) { using namespace rotgen; test_value(setConstant>(T(5.12)), 3, 4, T(5.12)); test_value(setConstant>(T(5.12)), 1, 1, T(5.12)); test_value(setConstant>(T(5.12)), 10, 10, T(5.12)); test_value(setConstant>(3, 4, T(5.12)), 3, 4, T(5.12)); test_value(setConstant>(7, 5, T(5.12)), 7, 5, T(5.12)); test_value(setConstant>(9, 3, T(5.12)), 9, 3, T(5.12)); test_value(setConstant>(2, 3, T(5.12)), 2, 3, T(5.12)); test_value(setConstant(matrix{}, T(5.12)), 3, 4, T(5.12)); test_value(setConstant(matrix{}, T(5.12)), 1, 1, T(5.12)); test_value(setConstant(matrix{}, T(5.12)), 10, 10, T(5.12)); test_value(setConstant(matrix{3, 4}, T(5.12)), 3, 4, T(5.12)); test_value(setConstant(matrix{}, T(5.12)), 7, 5, T(5.12)); test_value(setConstant(matrix{9, 3}, T(5.12)), 9, 3, T(5.12)); test_value(setConstant(matrix{2, 3}, T(5.12)), 2, 3, T(5.12)); }; TTS_CASE_TPL("Test random", rotgen::tests::types)( tts::type>) { using namespace rotgen; test_random(setRandom>(), 3, 4); test_random(setRandom>(), 1, 1); test_random(setRandom>(), 10, 10); test_random(setRandom>(3, 4), 3, 4); test_random(setRandom>(7, 5), 7, 5); test_random(setRandom>(9, 3), 9, 3); test_random(setRandom>(2, 3), 2, 3); test_random(setRandom(matrix{}), 3, 4); test_random(setRandom(matrix{}), 1, 1); test_random(setRandom(matrix{}), 10, 10); test_random(setRandom(matrix{3, 4}), 3, 4); test_random(setRandom(matrix{}), 7, 5); test_random(setRandom(matrix{9, 3}), 9, 3); test_random(setRandom(matrix{2, 3}), 2, 3); }; TTS_CASE_TPL("Test identity", rotgen::tests::types)( tts::type>) { using namespace rotgen; test_identity(setIdentity>(), 3, 4); test_identity(setIdentity>(), 1, 1); test_identity(setIdentity>(), 10, 10); test_identity(setIdentity>(3, 4), 3, 4); test_identity(setIdentity>(7, 5), 7, 5); test_identity(setIdentity>(9, 3), 9, 3); test_identity(setIdentity>(2, 3), 2, 3); test_identity(setIdentity(matrix{}), 3, 4); test_identity(setIdentity(matrix{}), 1, 1); test_identity(setIdentity(matrix{}), 10, 10); test_identity(setIdentity(matrix{3, 4}), 3, 4); test_identity(setIdentity(matrix{}), 7, 5); test_identity(setIdentity(matrix{9, 3}), 9, 3); test_identity(setIdentity(matrix{2, 3}), 2, 3); };