Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds compare method for the LineStrings. #28

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// BSD 3-Clause License
//
// Copyright (c) 2022, Woven Planet.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once

#include <gtest/gtest.h>

#include "maliput_sparse/geometry/line_string.h"

namespace maliput_sparse {
namespace test {

/// Compares two maliput_sparse::geometry::LineString3d objects.
/// @param lhs The left-hand side of the comparison.
/// @param rhs The right-hand side of the comparison.
/// @param tolerance The tolerance to use when comparing floating point values.
/// @returns A Google Test assertion result.
::testing::AssertionResult CompareLineString3d(const maliput_sparse::geometry::LineString3d& lhs,
const maliput_sparse::geometry::LineString3d& rhs, double tolerance);

} // namespace test
} // namespace maliput_sparse
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_subdirectory(base)
add_subdirectory(builder)
add_subdirectory(geometry)
add_subdirectory(test_utilities)
37 changes: 37 additions & 0 deletions src/test_utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
##############################################################################
# osm
##############################################################################

if(BUILD_TESTING)

add_library(test_utilities
maliput_sparse_types_compare.cc
)
add_library(maliput_sparse::test_utilities ALIAS test_utilities)
set_target_properties(test_utilities
PROPERTIES
OUTPUT_NAME maliput_sparse_test_utilities
)

target_include_directories(
test_utilities
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_link_libraries(test_utilities
PRIVATE
maliput::test_utilities
maliput_sparse::geometry
)

install(TARGETS test_utilities
EXPORT ${PROJECT_NAME}-targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

endif()
52 changes: 52 additions & 0 deletions src/test_utilities/maliput_sparse_types_compare.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// BSD 3-Clause License
//
// Copyright (c) 2022, Woven Planet.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "maliput_sparse/test_utilties/maliput_sparse_types_compare.h"

#include <maliput/test_utilities/maliput_math_compare.h>

namespace maliput_sparse {
namespace test {

::testing::AssertionResult CompareLineString3d(const maliput_sparse::geometry::LineString3d& lhs,
const maliput_sparse::geometry::LineString3d& rhs, double tolerance) {
if (lhs.size() != rhs.size()) {
return ::testing::AssertionFailure() << "LineString3d size mismatch: " << lhs.size() << " != " << rhs.size();
}
for (size_t i = 0; i < lhs.size(); ++i) {
if (!maliput::math::test::CompareVectors(lhs[i], rhs[i], tolerance)) {
return ::testing::AssertionFailure()
<< "LineString3d point mismatch at index " << i << ": " << lhs[i] << " != " << rhs[i];
}
}
return ::testing::AssertionSuccess();
}

} // namespace test
} // namespace maliput_sparse