// ---------------------------------------------------------------------------- // - Open3D: www.open3d.org - // ---------------------------------------------------------------------------- // The MIT License (MIT) // // Copyright (c) 2018 www.open3d.org // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // 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 OR COPYRIGHT HOLDERS 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. // ---------------------------------------------------------------------------- #pragma once // TEST_DATA_DIR defined in CMakeLists.txt // Put it here to avoid editor warnings #ifndef TEST_DATA_DIR #define TEST_DATA_DIR #endif #include #include #include #include "Open3D/Macro.h" #include "UnitTest/TestUtility/Print.h" #include "UnitTest/TestUtility/Rand.h" #include "UnitTest/TestUtility/Sort.h" // GPU_CONDITIONAL_COMPILE_STR is "" if gpu is available, otherwise "DISABLED_" // The GPU_CONDITIONAL_COMPILE_STR value is configured in CMake #define CUDA_CONDITIONAL_TEST(test_name) \ OPEN3D_CONCATENATE(GPU_CONDITIONAL_TEST_STR, test_name) namespace open3d { namespace unit_test { // thresholds for comparing floating point values const double THRESHOLD_1E_6 = 1e-6; // Eigen Zero() const Eigen::Vector2d Zero2d = Eigen::Vector2d::Zero(); const Eigen::Vector3d Zero3d = Eigen::Vector3d::Zero(); const Eigen::Matrix Zero6d = Eigen::Matrix::Zero(); const Eigen::Vector2i Zero2i = Eigen::Vector2i::Zero(); // Mechanism for reporting unit tests for which there is no implementation yet. void NotImplemented(); // Equal test. template void ExpectEQ(const Eigen::Matrix& v0, const Eigen::Matrix& v1, double threshold = THRESHOLD_1E_6) { EXPECT_EQ(v0.size(), v1.size()); for (int i = 0; i < v0.size(); i++) EXPECT_NEAR(v0.coeff(i), v1.coeff(i), threshold); } template void ExpectEQ(const std::vector>& v0, const std::vector>& v1, double threshold = THRESHOLD_1E_6) { EXPECT_EQ(v0.size(), v1.size()); for (size_t i = 0; i < v0.size(); i++) ExpectEQ(v0[i], v1[i], threshold); } template void ExpectEQ( const std::vector, Eigen::aligned_allocator>>& v0, const std::vector, Eigen::aligned_allocator>>& v1, double threshold = THRESHOLD_1E_6) { EXPECT_EQ(v0.size(), v1.size()); for (size_t i = 0; i < v0.size(); i++) ExpectEQ(v0[i], v1[i], threshold); } // Less than or Equal test. template void ExpectLE(const Eigen::Matrix& v0, const Eigen::Matrix& v1) { EXPECT_EQ(v0.size(), v1.size()); for (int i = 0; i < v0.size(); i++) EXPECT_LE(v0.coeff(i), v1.coeff(i)); } template void ExpectLE(const Eigen::Matrix& v0, const std::vector>& v1) { for (size_t i = 0; i < v1.size(); i++) ExpectLE(v0, v1[i]); } template void ExpectLE(const std::vector>& v0, const std::vector>& v1) { EXPECT_EQ(v0.size(), v1.size()); for (size_t i = 0; i < v0.size(); i++) ExpectLE(v0[i], v1[i]); } // Greater than or Equal test. template void ExpectGE(const Eigen::Matrix& v0, const Eigen::Matrix& v1) { EXPECT_EQ(v0.size(), v1.size()); for (int i = 0; i < v0.size(); i++) EXPECT_GE(v0.coeff(i), v1.coeff(i)); } template void ExpectGE(const Eigen::Matrix& v0, const std::vector>& v1) { for (size_t i = 0; i < v1.size(); i++) ExpectGE(v0, v1[i]); } template void ExpectGE(const std::vector>& v0, const std::vector>& v1) { EXPECT_EQ(v0.size(), v1.size()); for (size_t i = 0; i < v0.size(); i++) ExpectGE(v0[i], v1[i]); } // Test equality of two arrays of uint8_t. void ExpectEQ(const uint8_t* const v0, const uint8_t* const v1, const size_t& size); // Test equality of two vectors of uint8_t. void ExpectEQ(const std::vector& v0, const std::vector& v1); // Test equality of two arrays of int. void ExpectEQ(const int* const v0, const int* const v1, const size_t& size); // Test equality of two vectors of int. void ExpectEQ(const std::vector& v0, const std::vector& v1); // Test equality of two arrays of float. void ExpectEQ(const float* const v0, const float* const v1, const size_t& size, float threshold = THRESHOLD_1E_6); // Test equality of two vectors of float. void ExpectEQ(const std::vector& v0, const std::vector& v1, float threshold = THRESHOLD_1E_6); // Test equality of two arrays of double. void ExpectEQ(const double* const v0, const double* const v1, const size_t& size, double threshold = THRESHOLD_1E_6); // Test equality of two vectors of double. void ExpectEQ(const std::vector& v0, const std::vector& v1, double threshold = THRESHOLD_1E_6); // Reinterpret cast from uint8_t* to float*. template T* const Cast(uint8_t* data) { return reinterpret_cast(data); } } // namespace unit_test } // namespace open3d