Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:25:21

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/tools/old/interface.hpp>
0010 #include <boost/test/unit_test.hpp>
0011 #include <boost/test/unit_test_suite.hpp>
0012 
0013 #include "Acts/Utilities/detail/TransformComparator.hpp"
0014 
0015 using namespace Acts;
0016 
0017 namespace ActsTests {
0018 
0019 BOOST_AUTO_TEST_SUITE(UtilitiesSuite)
0020 
0021 BOOST_AUTO_TEST_CASE(Vector3Sorting) {
0022   ///
0023   detail::TransformComparator sorter{};
0024   detail::TransformComparator sorterWithTol{0.5, 0.5};
0025 
0026   for (unsigned dimA = 0; dimA < 3; ++dimA) {
0027     const Vector3 aPlus = Vector3::Unit(dimA);
0028     const Vector3 aMinus = -aPlus;
0029     BOOST_CHECK_EQUAL(sorter.compare<3>(aPlus, aPlus), 0);
0030     BOOST_CHECK_EQUAL(sorter.compare<3>(aPlus, aMinus), 1);
0031     BOOST_CHECK_EQUAL(sorter.compare<3>(aMinus, aPlus), -1);
0032     BOOST_CHECK_NE(sorter(aPlus, aMinus), sorter(aMinus, aPlus));
0033 
0034     const Vector3 halfPlus =
0035         (0.5 + std::numeric_limits<double>::epsilon()) * aPlus;
0036     const Vector3 halfMinus =
0037         (0.5 - std::numeric_limits<double>::epsilon()) * aPlus;
0038 
0039     BOOST_CHECK_EQUAL(sorterWithTol.compare<3>(aPlus, halfPlus), 0);
0040     BOOST_CHECK_NE(sorterWithTol.compare<3>(aPlus, halfMinus), 0);
0041     for (unsigned dimB = 0; dimB < 3; ++dimB) {
0042       const Vector3 bPlus = Vector3::Unit(dimB);
0043       const int expectSign = (dimA == dimB) ? 0 : dimA > dimB ? -1 : 1;
0044       BOOST_CHECK_EQUAL(sorter.compare<3>(aPlus, bPlus), expectSign);
0045     }
0046   }
0047 }
0048 
0049 BOOST_AUTO_TEST_CASE(Vector2Sorting) {
0050   detail::TransformComparator sorter{};
0051   detail::TransformComparator sorterWithTol{0.5, 0.5};
0052 
0053   for (unsigned dimA = 0; dimA < 2; ++dimA) {
0054     const Vector2 aPlus = Vector2::Unit(dimA);
0055     const Vector2 aMinus = -aPlus;
0056     BOOST_CHECK_EQUAL(sorter.compare<2>(aPlus, aPlus), 0);
0057     BOOST_CHECK_EQUAL(sorter.compare<2>(aPlus, aMinus), 1);
0058     BOOST_CHECK_EQUAL(sorter.compare<2>(aMinus, aPlus), -1);
0059     BOOST_CHECK_NE(sorter(aPlus, aMinus), sorter(aMinus, aPlus));
0060 
0061     const Vector2 halfPlus =
0062         (0.5 + std::numeric_limits<double>::epsilon()) * aPlus;
0063     const Vector2 halfMinus =
0064         (0.5 - std::numeric_limits<double>::epsilon()) * aPlus;
0065 
0066     BOOST_CHECK_EQUAL(sorterWithTol.compare<2>(aPlus, halfPlus), 0);
0067     BOOST_CHECK_NE(sorterWithTol.compare<2>(aPlus, halfMinus), 0);
0068     for (unsigned dimB = 0; dimB < 2; ++dimB) {
0069       const Vector2 bPlus = Vector2::Unit(dimB);
0070       const int expectSign = (dimA == dimB) ? 0 : dimA > dimB ? -1 : 1;
0071       BOOST_CHECK_EQUAL(sorter.compare<2>(aPlus, bPlus), expectSign);
0072     }
0073   }
0074 }
0075 
0076 BOOST_AUTO_TEST_SUITE_END()
0077 
0078 }  // namespace ActsTests