Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:24

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 // Project include(s).
0010 #include "detray/utils/find_bound.hpp"
0011 
0012 // Google Test include(s).
0013 #include <gtest/gtest.h>
0014 
0015 // Test upper bound function
0016 GTEST_TEST(detray_utils, upper_bound) {
0017   std::vector<float> vec = {2.f, 3.f, 5.f, 8.f, 8.f, 8.f, 9.f, 12.f, 12.f};
0018 
0019   auto pos = detray::detail::upper_bound(vec.begin(), vec.end(), 8.f);
0020 
0021   ASSERT_EQ(pos - vec.begin(), 6);
0022   ASSERT_EQ(*pos, 9.f);
0023 
0024   pos = detray::detail::upper_bound(vec.begin(), vec.end(), 3.f);
0025 
0026   ASSERT_EQ(pos - vec.begin(), 2);
0027   ASSERT_EQ(*pos, 5.f);
0028 
0029   pos = detray::detail::upper_bound(vec.begin(), vec.end(), 10.f);
0030 
0031   ASSERT_EQ(pos - vec.begin(), 7);
0032   ASSERT_EQ(*pos, 12.f);
0033 }
0034 
0035 // Test lower bound function
0036 GTEST_TEST(detray_utils, lower_bound) {
0037   std::vector<float> vec = {2.f, 3.f, 5.f, 8.f, 8.f, 8.f, 9.f, 12.f, 12.f};
0038 
0039   auto pos = detray::detail::lower_bound(vec.begin(), vec.end(), 8.f);
0040 
0041   ASSERT_EQ(pos - vec.begin(), 3);
0042   ASSERT_EQ(*pos, 8.f);
0043 
0044   pos = detray::detail::lower_bound(vec.begin(), vec.end(), 3.f);
0045 
0046   ASSERT_EQ(pos - vec.begin(), 1);
0047   ASSERT_EQ(*pos, 3.f);
0048 
0049   pos = detray::detail::lower_bound(vec.begin(), vec.end(), 10.f);
0050 
0051   ASSERT_EQ(pos - vec.begin(), 7);
0052   ASSERT_EQ(*pos, 12.f);
0053 }