Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:59

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/unit_test.hpp>
0010 
0011 #include "Acts/Utilities/Helpers.hpp"
0012 #include "Acts/Utilities/KDTree.hpp"
0013 #include "Acts/Utilities/RangeXD.hpp"
0014 
0015 #include <algorithm>
0016 #include <array>
0017 #include <cstddef>
0018 #include <iterator>
0019 #include <string>
0020 #include <utility>
0021 #include <vector>
0022 
0023 namespace {
0024 std::vector<std::pair<std::array<double, 3>, int>> test_vector{
0025     {{-8.5, 2.3, -1.6}, 84},   {{-9.7, -1.4, 7.6}, -56},
0026     {{6.4, 2.7, -1.0}, -94},   {{-2.2, -9.3, 3.6}, 56},
0027     {{-9.2, -2.8, -2.5}, -90}, {{3.8, 0.9, 7.2}, 43},
0028     {{7.6, 1.9, -1.0}, 83},    {{2.1, -1.6, -1.7}, -15},
0029     {{5.2, 3.2, -1.3}, 14},    {{-6.0, -7.5, 6.5}, 48},
0030     {{3.5, -7.1, -4.4}, 83},   {{5.0, 6.9, -0.7}, 1},
0031     {{8.0, 0.2, 3.8}, 69},     {{2.5, 0.8, 4.1}, -11},
0032     {{-1.5, -6.6, 8.4}, -98},  {{0.8, 6.1, 2.7}, 14},
0033     {{5.1, -5.1, 5.8}, 46},    {{-9.6, 0.7, 0.3}, 59},
0034     {{-8.8, 1.3, -9.8}, -19},  {{-7.5, -9.3, -2.2}, 6},
0035     {{-5.3, 1.9, -3.9}, 57},   {{-4.8, -9.8, -0.2}, 73},
0036     {{-6.3, -7.4, 9.2}, -94},  {{-4.8, -9.8, -2.6}, 77},
0037     {{2.4, 4.9, -8.4}, -72},   {{8.4, 6.1, -7.7}, -66},
0038     {{6.1, -8.2, 9.3}, 67},    {{9.4, 7.4, 7.5}, -99},
0039     {{9.4, 1.8, -4.4}, -87},   {{9.0, -3.7, 6.3}, -12},
0040     {{-1.8, 2.8, 6.3}, 71},    {{-7.6, 7.6, -4.5}, -77},
0041     {{-7.7, -1.2, 7.7}, -92},  {{-6.9, -0.5, -6.6}, -61},
0042     {{0.9, 5.7, 0.5}, 60},     {{-0.3, 3.7, -7.0}, 15},
0043     {{5.3, -0.6, -6.6}, 46},   {{-6.9, -3.0, 4.1}, -13},
0044     {{1.8, -6.5, 1.8}, -29},   {{1.4, -7.8, -0.3}, 100},
0045     {{8.2, 0.1, -7.6}, 69},    {{6.5, -9.1, 6.6}, -61},
0046     {{4.2, 6.6, -0.7}, 56},    {{8.6, -3.1, -6.8}, -88},
0047     {{9.7, -6.0, 2.9}, -44},   {{7.0, -3.2, 9.8}, 29},
0048     {{-6.1, 3.3, -3.0}, 54},   {{-2.6, 7.6, -4.2}, -52},
0049     {{-5.9, 7.8, 5.1}, -81},   {{0.6, 5.3, -2.5}, -69},
0050     {{-8.5, 1.8, 6.0}, 56},    {{6.4, 2.0, -6.8}, -14},
0051     {{-9.0, -2.1, 8.0}, 84},   {{7.0, 0.1, 6.3}, -17},
0052     {{8.0, 4.5, -0.8}, -85},   {{-5.5, 9.2, 7.5}, 13},
0053     {{-3.8, 2.1, 3.4}, 19},    {{-8.0, -5.2, 9.5}, -25},
0054     {{6.2, 6.0, -2.2}, 81},    {{5.1, -5.1, -9.7}, 74},
0055     {{-1.3, -9.0, 8.1}, -74},  {{5.4, -0.8, 2.4}, 32},
0056     {{-5.6, 3.8, 6.2}, 73},    {{8.9, -3.8, -7.8}, 93},
0057     {{7.7, 0.4, -2.9}, 78},    {{-6.9, -1.5, -3.3}, -75},
0058     {{-5.3, 2.5, -3.6}, 48},   {{-6.6, -9.2, -2.1}, -7},
0059     {{5.5, -7.7, 2.0}, 3},     {{4.1, -9.5, -6.9}, 82},
0060     {{-2.3, -0.2, -0.7}, -3},  {{2.3, 0.4, -5.5}, 43},
0061     {{5.0, 4.0, 9.0}, 59},     {{-8.7, -4.0, 1.0}, -17},
0062     {{7.6, -7.6, -7.9}, 18},   {{4.2, 6.3, -4.4}, 2},
0063     {{8.6, -6.3, 3.5}, -75},   {{9.8, 7.3, 0.1}, 8},
0064     {{-2.2, 9.3, -6.2}, -54},  {{-0.9, -0.4, 1.4}, 45},
0065     {{-5.3, 6.7, 7.6}, 20},    {{-2.7, 2.4, 8.8}, 42},
0066     {{9.3, -0.0, 9.1}, -84},   {{0.5, 1.5, -2.3}, -47},
0067     {{7.5, -5.7, 1.3}, 21},    {{0.4, 0.4, -2.0}, 50},
0068     {{0.8, -6.2, -7.7}, 46},   {{5.1, -7.3, -0.7}, 26},
0069     {{9.7, 2.8, 9.6}, 80},     {{7.3, -2.1, -6.7}, -91},
0070     {{-9.4, -5.3, -3.1}, -24}, {{-2.4, -1.6, -0.2}, -88},
0071     {{-9.9, -5.9, 0.0}, -90},  {{1.3, -3.0, 9.8}, 72},
0072     {{0.9, -6.8, -2.7}, 92},   {{-1.7, -3.8, 2.8}, -78},
0073     {{-6.4, -0.6, -0.6}, 95},  {{-4.7, 4.8, -8.0}, 95},
0074     {{-6.0, 3.5, -7.4}, 7},    {{3.2, -6.2, 3.9}, -25}};
0075 }
0076 
0077 namespace Acts::Test {
0078 
0079 struct TreeFixture1DDoubleInt1 {
0080   TreeFixture1DDoubleInt1()
0081       : tree(std::vector<std::pair<std::array<double, 1>, int>>{
0082             {{1.0}, 5}, {{2.0}, 6}, {{-1.2}, 2}, {{0.9}, 10}}) {}
0083 
0084   Acts::KDTree<1, int, double> tree;
0085 };
0086 
0087 struct TreeFixture1DDoubleInt2 {
0088   TreeFixture1DDoubleInt2()
0089       : tree(std::vector<std::pair<std::array<double, 1>, int>>{
0090             {{1.0}, 5},
0091             {{2.0}, 6},
0092             {{-1.2}, 2},
0093             {{0.9}, 10},
0094             {{-10.0}, 9},
0095             {{110.0}, 1},
0096             {{-1000.0}, 3}}) {}
0097 
0098   Acts::KDTree<1, int, double> tree;
0099 };
0100 
0101 struct TreeFixture2DDoubleInt1 {
0102   TreeFixture2DDoubleInt1()
0103       : tree(std::vector<std::pair<std::array<double, 2>, int>>{
0104             {{1.0, 5.0}, 5}, {{2.0, -2.5}, 6}}) {}
0105 
0106   Acts::KDTree<2, int, double> tree;
0107 };
0108 
0109 struct TreeFixture3DDoubleInt1 {
0110   TreeFixture3DDoubleInt1()
0111       : tree(std::vector<std::pair<std::array<double, 3>, int>>{
0112             {{-4.7, -2.0, -1.7}, 63}, {{8.2, -0.0, 9.5}, -82},
0113             {{7.1, -3.6, -4.0}, -49}, {{-9.9, -4.6, 2.9}, 86},
0114             {{5.0, -3.8, -2.8}, -12}, {{-4.8, -1.8, -1.6}, -60},
0115             {{8.8, 9.6, -0.2}, 60},   {{7.6, 1.9, 8.8}, 74},
0116             {{9.0, -6.9, -6.2}, 35},  {{4.3, 7.5, -2.0}, 19},
0117             {{-7.7, 3.7, 7.1}, -54},  {{3.4, 7.4, -4.0}, -8},
0118             {{8.5, 3.0, -3.2}, -48},  {{6.5, -0.3, -3.1}, -25},
0119             {{6.9, -6.6, -8.0}, -4},  {{6.8, 5.5, -2.5}, 17},
0120             {{-2.8, 8.8, -7.2}, 62},  {{-0.1, 3.5, 5.5}, -95},
0121             {{-1.3, 6.9, 5.3}, -23},  {{6.2, 6.6, 7.1}, -84}}) {}
0122 
0123   Acts::KDTree<3, int, double> tree;
0124 };
0125 
0126 struct TreeFixture3DDoubleInt2 {
0127   TreeFixture3DDoubleInt2()
0128       : tree(std::vector<std::pair<std::array<double, 3>, int>>(test_vector)) {}
0129 
0130   Acts::KDTree<3, int, double> tree;
0131 };
0132 
0133 struct TreeFixture3DDoubleInt3 {
0134   TreeFixture3DDoubleInt3()
0135       : tree(std::vector<std::pair<std::array<double, 3>, int>>{
0136             {{-100.0, -1.1, -1.7}, 0},
0137             {{100.0, -0.0, 9.5}, 4},
0138             {{-100.0, -0.6, -1.0}, 1},
0139             {{100.0, -4.6, 2.9}, 5},
0140             {{-100.0, -1.4, -2.8}, 2},
0141             {{100.0, -1.8, -1.6}, 6},
0142             {{-100.0, -1.0, -0.2}, 3},
0143             {{100.0, 1.9, 8.8}, 7}}) {}
0144 
0145   Acts::KDTree<3, int, double> tree;
0146 };
0147 
0148 struct TreeFixture10DDoubleInt1 {
0149   TreeFixture10DDoubleInt1()
0150       : tree(std::vector<std::pair<std::array<double, 10>, int>>{
0151             {{5.6, 7.5, -9.8, 9.6, 3.3, -7.3, 2.0, 4.7, -2.1, 5.9}, 32},
0152             {{1.2, -1.5, -0.2, 0.9, 1.1, -1.4, -8.9, -1.2, -9.0, 7.4}, -66},
0153             {{1.6, 6.2, 9.9, -2.5, 4.0, 8.9, 3.9, 8.4, -1.2, -4.1}, -51},
0154             {{0.7, -5.7, -3.1, 5.4, 0.6, -8.7, 0.2, -0.2, 0.3, -2.7}, -19},
0155             {{-5.0, -5.5, -7.1, 9.2, 5.5, 0.7, 9.9, -7.0, -6.8, 3.1}, 27},
0156             {{0.4, 5.5, -5.8, -3.0, 6.0, -7.3, 2.1, 7.9, -8.0, -6.9}, -13},
0157             {{-2.3, -5.9, 9.0, 1.4, 4.6, 3.4, -9.5, -6.3, 3.3, -7.0}, 97},
0158             {{8.1, 3.6, -8.6, -0.4, 7.5, 10.0, -3.9, -5.8, -2.9, 9.8}, 15},
0159             {{8.4, -4.0, 6.3, 1.1, -5.7, 8.1, -8.0, -2.5, -0.5, 3.2}, -56},
0160             {{2.3, 5.8, 1.4, 4.0, 9.0, -6.4, 1.0, -7.8, 4.3, -5.3}, -83}}) {}
0161 
0162   Acts::KDTree<10, int, double> tree;
0163 };
0164 
0165 struct TreeFixture3DDoubleString1 {
0166   TreeFixture3DDoubleString1()
0167       : tree(std::vector<std::pair<std::array<double, 3>, std::string>>{
0168             {{-0.2, -0.2, -3.8}, "string0"},
0169             {{4.9, -7.8, -10.0}, "string1"},
0170             {{3.5, -10.0, -8.1}, "string2"},
0171             {{8.2, -6.1, 2.0}, "string3"},
0172             {{-9.9, 7.7, -1.4}, "string4"},
0173             {{-2.2, 2.1, 8.6}, "string5"},
0174             {{-6.9, -5.8, 5.3}, "string6"},
0175             {{-0.7, 0.9, -6.5}, "string7"},
0176             {{-2.7, -5.9, -7.3}, "string8"},
0177             {{3.1, -9.4, -2.5}, "string9"}}) {}
0178 
0179   Acts::KDTree<3, std::string, double> tree;
0180 };
0181 
0182 struct TreeFixture1DIntInt1 {
0183   TreeFixture1DIntInt1()
0184       : tree(std::vector<std::pair<std::array<int, 1>, int>>{
0185             {{1}, 5}, {{2}, 6}, {{-1}, 2}, {{5}, 10}}) {}
0186 
0187   Acts::KDTree<1, int, int> tree;
0188 };
0189 
0190 struct TreeFixture2DIntInt1 {
0191   TreeFixture2DIntInt1()
0192       : tree(std::vector<std::pair<std::array<int, 2>, int>>{
0193             {{1, 7}, 5}, {{2, 1}, 6}, {{-1, -11}, 2}, {{5, -2}, 10}}) {}
0194 
0195   Acts::KDTree<2, int, int> tree;
0196 };
0197 
0198 BOOST_AUTO_TEST_SUITE(Utilities)
0199 
0200 BOOST_AUTO_TEST_SUITE(KDTree)
0201 
0202 BOOST_FIXTURE_TEST_CASE(size_1, TreeFixture1DDoubleInt1) {
0203   BOOST_CHECK_EQUAL(tree.size(), 4);
0204 }
0205 
0206 BOOST_FIXTURE_TEST_CASE(size_2, TreeFixture1DDoubleInt2) {
0207   BOOST_CHECK_EQUAL(tree.size(), 7);
0208 }
0209 
0210 BOOST_FIXTURE_TEST_CASE(size_3, TreeFixture2DDoubleInt1) {
0211   BOOST_CHECK_EQUAL(tree.size(), 2);
0212 }
0213 
0214 BOOST_FIXTURE_TEST_CASE(size_4, TreeFixture3DDoubleInt1) {
0215   BOOST_CHECK_EQUAL(tree.size(), 20);
0216 }
0217 
0218 BOOST_FIXTURE_TEST_CASE(size_5, TreeFixture10DDoubleInt1) {
0219   BOOST_CHECK_EQUAL(tree.size(), 10);
0220 }
0221 
0222 BOOST_FIXTURE_TEST_CASE(size_6, TreeFixture3DDoubleString1) {
0223   BOOST_CHECK_EQUAL(tree.size(), 10);
0224 }
0225 
0226 BOOST_FIXTURE_TEST_CASE(size_7, TreeFixture1DIntInt1) {
0227   BOOST_CHECK_EQUAL(tree.size(), 4);
0228 }
0229 
0230 BOOST_FIXTURE_TEST_CASE(size_8, TreeFixture3DDoubleInt2) {
0231   BOOST_CHECK_EQUAL(tree.size(), 100);
0232 }
0233 
0234 BOOST_FIXTURE_TEST_CASE(range_search_1, TreeFixture1DDoubleInt2) {
0235   RangeXD<1, double> range;
0236   range[0].shrink(0.0, 2.5);
0237 
0238   std::vector<int> result = tree.rangeSearch(range);
0239   BOOST_CHECK_EQUAL(result.size(), 3);
0240   BOOST_CHECK(rangeContainsValue(result, 5));
0241   BOOST_CHECK(rangeContainsValue(result, 6));
0242   BOOST_CHECK(rangeContainsValue(result, 10));
0243   BOOST_CHECK(!rangeContainsValue(result, 7));
0244   BOOST_CHECK(!rangeContainsValue(result, 2));
0245   BOOST_CHECK(!rangeContainsValue(result, 9));
0246 }
0247 
0248 BOOST_FIXTURE_TEST_CASE(range_search_2, TreeFixture1DDoubleInt2) {
0249   RangeXD<1, double> range;
0250   range[0].shrink(-10000.0, 10000.0);
0251 
0252   std::vector<int> result = tree.rangeSearch(range);
0253   BOOST_CHECK_EQUAL(result.size(), 7);
0254   BOOST_CHECK(rangeContainsValue(result, 1));
0255   BOOST_CHECK(rangeContainsValue(result, 2));
0256   BOOST_CHECK(rangeContainsValue(result, 3));
0257   BOOST_CHECK(rangeContainsValue(result, 5));
0258   BOOST_CHECK(rangeContainsValue(result, 6));
0259   BOOST_CHECK(rangeContainsValue(result, 9));
0260   BOOST_CHECK(rangeContainsValue(result, 10));
0261 }
0262 
0263 BOOST_FIXTURE_TEST_CASE(range_search_3, TreeFixture1DDoubleInt2) {
0264   RangeXD<1, double> range;
0265   range[0].shrink(5000.0, 10000.0);
0266 
0267   std::vector<int> result = tree.rangeSearch(range);
0268   BOOST_CHECK_EQUAL(result.size(), 0);
0269 }
0270 
0271 BOOST_FIXTURE_TEST_CASE(range_search_4, TreeFixture2DDoubleInt1) {
0272   RangeXD<2, double> range;
0273   range[0].shrink(0.0, 10.0);
0274   range[1].shrink(0.0, 10.0);
0275 
0276   std::vector<int> result = tree.rangeSearch(range);
0277   BOOST_CHECK_EQUAL(result.size(), 1);
0278   BOOST_CHECK(rangeContainsValue(result, 5));
0279 }
0280 
0281 BOOST_FIXTURE_TEST_CASE(range_search_5, TreeFixture2DDoubleInt1) {
0282   RangeXD<2, double> range;
0283   range[0].shrink(0.0, 10.0);
0284   range[1].shrink(-10.0, 10.0);
0285 
0286   std::vector<int> result = tree.rangeSearch(range);
0287   BOOST_CHECK_EQUAL(result.size(), 2);
0288   BOOST_CHECK(rangeContainsValue(result, 5));
0289   BOOST_CHECK(rangeContainsValue(result, 6));
0290 }
0291 
0292 BOOST_FIXTURE_TEST_CASE(range_search_6, TreeFixture10DDoubleInt1) {
0293   RangeXD<10, double> range;
0294   range[0].shrink(0.0, 5.0);
0295 
0296   std::vector<int> result = tree.rangeSearch(range);
0297   BOOST_CHECK_EQUAL(result.size(), 5);
0298   BOOST_CHECK(rangeContainsValue(result, -66));
0299   BOOST_CHECK(rangeContainsValue(result, -51));
0300   BOOST_CHECK(rangeContainsValue(result, -19));
0301   BOOST_CHECK(rangeContainsValue(result, -13));
0302   BOOST_CHECK(rangeContainsValue(result, -83));
0303 }
0304 
0305 BOOST_FIXTURE_TEST_CASE(range_search_7, TreeFixture10DDoubleInt1) {
0306   RangeXD<10, double> range;
0307   range[9].shrink(0.0, 5.0);
0308 
0309   std::vector<int> result = tree.rangeSearch(range);
0310   BOOST_CHECK_EQUAL(result.size(), 2);
0311   BOOST_CHECK(rangeContainsValue(result, 27));
0312   BOOST_CHECK(rangeContainsValue(result, -56));
0313 }
0314 
0315 BOOST_FIXTURE_TEST_CASE(range_search_8, TreeFixture3DDoubleString1) {
0316   RangeXD<3, double> range;
0317   range[0].shrink(-5.0, 5.0);
0318   range[1].shrink(-5.0, 5.0);
0319   range[2].shrink(-5.0, 5.0);
0320 
0321   std::vector<std::string> result = tree.rangeSearch(range);
0322   BOOST_CHECK_EQUAL(result.size(), 1);
0323   BOOST_CHECK(rangeContainsValue(result, "string0"));
0324 }
0325 
0326 BOOST_FIXTURE_TEST_CASE(range_search_9, TreeFixture3DDoubleString1) {
0327   RangeXD<3, double> range;
0328   range[0].shrink(-10.0, 10.0);
0329   range[1].shrink(-10.0, 10.0);
0330   range[2].shrink(-5.0, 5.0);
0331 
0332   std::vector<std::string> result = tree.rangeSearch(range);
0333   BOOST_CHECK_EQUAL(result.size(), 4);
0334   BOOST_CHECK(rangeContainsValue(result, "string0"));
0335   BOOST_CHECK(rangeContainsValue(result, "string3"));
0336   BOOST_CHECK(rangeContainsValue(result, "string4"));
0337   BOOST_CHECK(rangeContainsValue(result, "string9"));
0338 }
0339 
0340 BOOST_FIXTURE_TEST_CASE(range_search_10, TreeFixture1DIntInt1) {
0341   RangeXD<1, int> range;
0342   range[0].shrink(0, 3);
0343 
0344   std::vector<int> result = tree.rangeSearch(range);
0345   BOOST_CHECK_EQUAL(result.size(), 2);
0346   BOOST_CHECK(rangeContainsValue(result, 5));
0347   BOOST_CHECK(rangeContainsValue(result, 6));
0348 }
0349 
0350 BOOST_FIXTURE_TEST_CASE(range_search_11, TreeFixture2DIntInt1) {
0351   RangeXD<2, int> range;
0352   range[1].shrink(0, 10);
0353 
0354   std::vector<int> result = tree.rangeSearch(range);
0355   BOOST_CHECK_EQUAL(result.size(), 2);
0356   BOOST_CHECK(rangeContainsValue(result, 5));
0357   BOOST_CHECK(rangeContainsValue(result, 6));
0358 }
0359 
0360 BOOST_FIXTURE_TEST_CASE(range_search_inplace_1, TreeFixture10DDoubleInt1) {
0361   RangeXD<10, double> range;
0362   range[0].shrink(0.0, 5.0);
0363 
0364   std::vector<int> result;
0365   tree.rangeSearch(range, result);
0366 
0367   BOOST_CHECK_EQUAL(result.size(), 5);
0368   BOOST_CHECK(rangeContainsValue(result, -66));
0369   BOOST_CHECK(rangeContainsValue(result, -51));
0370   BOOST_CHECK(rangeContainsValue(result, -19));
0371   BOOST_CHECK(rangeContainsValue(result, -13));
0372   BOOST_CHECK(rangeContainsValue(result, -83));
0373 }
0374 
0375 BOOST_FIXTURE_TEST_CASE(range_search_inserter_1, TreeFixture10DDoubleInt1) {
0376   RangeXD<10, double> range;
0377   range[0].shrink(0.0, 5.0);
0378 
0379   std::vector<int> result;
0380   tree.rangeSearchInserter(range, std::back_inserter(result));
0381 
0382   BOOST_CHECK_EQUAL(result.size(), 5);
0383   BOOST_CHECK(rangeContainsValue(result, -66));
0384   BOOST_CHECK(rangeContainsValue(result, -51));
0385   BOOST_CHECK(rangeContainsValue(result, -19));
0386   BOOST_CHECK(rangeContainsValue(result, -13));
0387   BOOST_CHECK(rangeContainsValue(result, -83));
0388 }
0389 
0390 BOOST_FIXTURE_TEST_CASE(range_search_map_1, TreeFixture10DDoubleInt1) {
0391   RangeXD<10, double> range;
0392   range[0].shrink(0.0, 5.0);
0393 
0394   std::vector<int> result = tree.rangeSearchMap<int>(
0395       range,
0396       [](const std::array<double, 10>&, const int& i) -> int { return 2 * i; });
0397 
0398   BOOST_CHECK_EQUAL(result.size(), 5);
0399   BOOST_CHECK(rangeContainsValue(result, -132));
0400   BOOST_CHECK(rangeContainsValue(result, -102));
0401   BOOST_CHECK(rangeContainsValue(result, -38));
0402   BOOST_CHECK(rangeContainsValue(result, -26));
0403   BOOST_CHECK(rangeContainsValue(result, -166));
0404 }
0405 
0406 BOOST_FIXTURE_TEST_CASE(range_search_map_inserter_1, TreeFixture10DDoubleInt1) {
0407   RangeXD<10, double> range;
0408   range[0].shrink(0.0, 5.0);
0409 
0410   std::vector<std::string> result;
0411 
0412   tree.rangeSearchMapInserter<std::string>(
0413       range,
0414       [](const std::array<double, 10>&, const int& i) -> std::string {
0415         return std::to_string(i);
0416       },
0417       std::back_inserter(result));
0418 
0419   BOOST_CHECK_EQUAL(result.size(), 5);
0420   BOOST_CHECK(rangeContainsValue(result, "-66"));
0421   BOOST_CHECK(rangeContainsValue(result, "-51"));
0422   BOOST_CHECK(rangeContainsValue(result, "-19"));
0423   BOOST_CHECK(rangeContainsValue(result, "-13"));
0424   BOOST_CHECK(rangeContainsValue(result, "-83"));
0425 }
0426 
0427 BOOST_FIXTURE_TEST_CASE(range_search_map_inserter_2, TreeFixture2DIntInt1) {
0428   RangeXD<2, int> range;
0429   range[1].shrink(0, 10);
0430 
0431   std::vector<int> result;
0432   tree.rangeSearchMapInserter<int>(
0433       range,
0434       [](const std::array<int, 2>& c, const int& i) -> int {
0435         return i * (c[0] + c[1]);
0436       },
0437       std::back_inserter(result));
0438 
0439   BOOST_CHECK_EQUAL(result.size(), 2);
0440   BOOST_CHECK(rangeContainsValue(result, 40));
0441   BOOST_CHECK(rangeContainsValue(result, 18));
0442 }
0443 
0444 BOOST_FIXTURE_TEST_CASE(range_search_map_discard_1, TreeFixture2DIntInt1) {
0445   RangeXD<2, int> range;
0446   range[1].shrink(-100, 5);
0447 
0448   int result = 0;
0449 
0450   tree.rangeSearchMapDiscard(
0451       range, [&result](const std::array<int, 2>& c, const int& i) {
0452         result += i * (c[0] + c[1]);
0453       });
0454 
0455   BOOST_CHECK_EQUAL(result, 24);
0456 }
0457 
0458 BOOST_FIXTURE_TEST_CASE(range_search_map_discard_2, TreeFixture3DDoubleInt2) {
0459   RangeXD<3, double> range;
0460   range[0].shrinkMin(0.0);
0461 
0462   int result = 0;
0463 
0464   tree.rangeSearchMapDiscard(range, [&result](const std::array<double, 3>&,
0465                                               const int& i) { result += i; });
0466 
0467   BOOST_CHECK_EQUAL(result, 555);
0468 }
0469 
0470 BOOST_FIXTURE_TEST_CASE(range_search_combinatorial, TreeFixture3DDoubleInt2) {
0471   for (double xmin = -10.0; xmin <= 10.0; xmin += 2.0) {
0472     for (double xmax = -10.0; xmax <= 10.0; xmax += 2.0) {
0473       for (double ymin = -10.0; ymin <= 10.0; ymin += 2.0) {
0474         for (double ymax = -10.0; ymax <= 10.0; ymax += 2.0) {
0475           for (double zmin = -10.0; zmin <= 10.0; zmin += 2.0) {
0476             for (double zmax = -10.0; zmax <= 10.0; zmax += 2.0) {
0477               RangeXD<3, double> range;
0478 
0479               range[0].shrink(xmin, xmax);
0480               range[1].shrink(ymin, ymax);
0481               range[2].shrink(zmin, zmax);
0482 
0483               std::vector<int> valid;
0484 
0485               for (const auto& [c, value] : test_vector) {
0486                 if (xmin <= c[0] && c[0] < xmax && ymin <= c[1] &&
0487                     c[1] < ymax && zmin <= c[2] && c[2] < zmax) {
0488                   valid.push_back(value);
0489                 }
0490               }
0491 
0492               std::vector<int> result = tree.rangeSearch(range);
0493 
0494               BOOST_CHECK_EQUAL(result.size(), valid.size());
0495 
0496               for (int j : valid) {
0497                 BOOST_CHECK(rangeContainsValue(result, j));
0498               }
0499             }
0500           }
0501         }
0502       }
0503     }
0504   }
0505 }
0506 
0507 BOOST_FIXTURE_TEST_CASE(range_search_dominate1, TreeFixture3DDoubleInt3) {
0508   RangeXD<3, double> range1;
0509   range1[0].shrink(-200, 0);
0510 
0511   std::vector<int> result = tree.rangeSearch(range1);
0512   BOOST_CHECK_EQUAL(result.size(), 4);
0513   BOOST_CHECK(rangeContainsValue(result, 0));
0514   BOOST_CHECK(rangeContainsValue(result, 1));
0515   BOOST_CHECK(rangeContainsValue(result, 2));
0516   BOOST_CHECK(rangeContainsValue(result, 3));
0517 }
0518 
0519 BOOST_FIXTURE_TEST_CASE(range_search_dominate2, TreeFixture3DDoubleInt3) {
0520   RangeXD<3, double> range1;
0521   range1[0].shrink(0, 200);
0522 
0523   std::vector<int> result = tree.rangeSearch(range1);
0524   BOOST_CHECK_EQUAL(result.size(), 4);
0525   BOOST_CHECK(rangeContainsValue(result, 4));
0526   BOOST_CHECK(rangeContainsValue(result, 5));
0527   BOOST_CHECK(rangeContainsValue(result, 6));
0528   BOOST_CHECK(rangeContainsValue(result, 7));
0529 }
0530 
0531 BOOST_AUTO_TEST_CASE(range_search_very_big) {
0532   int q = 0;
0533 
0534   std::vector<std::pair<std::array<double, 3>, int>> points;
0535 
0536   for (double x = -10.0; x < 10.0; x += 0.5) {
0537     for (double y = -10.0; y < 10.0; y += 0.5) {
0538       for (double z = -10.0; z < 10.0; z += 0.5) {
0539         points.push_back({{x, y, z}, q++});
0540       }
0541     }
0542   }
0543 
0544   std::vector<std::pair<std::array<double, 3>, int>> copy(points);
0545 
0546   Acts::KDTree<3, int, double> tree(std::move(copy));
0547 
0548   for (double xmin = -10.0; xmin <= 10.0; xmin += 1.0) {
0549     for (double ymin = -10.0; ymin <= 10.0; ymin += 1.0) {
0550       for (double zmin = -10.0; zmin <= 10.0; zmin += 1.0) {
0551         RangeXD<3, double> range;
0552 
0553         double xmax = xmin + 1.0;
0554         double ymax = ymin + 1.0;
0555         double zmax = zmin + 1.0;
0556 
0557         range[0].shrink(xmin, xmax);
0558         range[1].shrink(ymin, ymax);
0559         range[2].shrink(zmin, zmax);
0560 
0561         std::vector<int> valid;
0562 
0563         for (const std::pair<std::array<double, 3>, int>& i : points) {
0564           const std::array<double, 3>& c = i.first;
0565           if (xmin <= c[0] && c[0] < xmax && ymin <= c[1] && c[1] < ymax &&
0566               zmin <= c[2] && c[2] < zmax) {
0567             valid.push_back(i.second);
0568           }
0569         }
0570 
0571         std::vector<int> result = tree.rangeSearch(range);
0572 
0573         BOOST_CHECK_EQUAL(result.size(), valid.size());
0574 
0575         for (int j : valid) {
0576           BOOST_CHECK(rangeContainsValue(result, j));
0577         }
0578       }
0579     }
0580   }
0581 }
0582 
0583 BOOST_AUTO_TEST_CASE(range_search_many_same) {
0584   int q = 0;
0585 
0586   std::vector<std::pair<std::array<double, 3>, int>> points;
0587 
0588   for (std::size_t i = 0; i < 50; ++i) {
0589     points.push_back({{64.0, 64.0, 64.0}, q++});
0590   }
0591 
0592   for (std::size_t i = 0; i < 50; ++i) {
0593     points.push_back({{-64.0, -64.0, -64.0}, q++});
0594   }
0595 
0596   Acts::KDTree<3, int, double> tree(std::move(points));
0597 
0598   RangeXD<3, double> range1;
0599   range1[0].shrink(50.0, 70.0);
0600   range1[1].shrink(50.0, 70.0);
0601   range1[2].shrink(50.0, 70.0);
0602 
0603   RangeXD<3, double> range2;
0604   range2[0].shrink(-70.0, -50.0);
0605   range2[1].shrink(-70.0, -50.0);
0606   range2[2].shrink(-70.0, -50.0);
0607 
0608   std::vector<int> result1 = tree.rangeSearch(range1);
0609   std::vector<int> result2 = tree.rangeSearch(range2);
0610 
0611   BOOST_CHECK_EQUAL(result1.size(), 50);
0612   BOOST_CHECK_EQUAL(result2.size(), 50);
0613 
0614   for (int i = 0; i < 50; ++i) {
0615     BOOST_CHECK(rangeContainsValue(result1, i));
0616   }
0617 
0618   for (int i = 50; i < 100; ++i) {
0619     BOOST_CHECK(rangeContainsValue(result2, i));
0620   }
0621 }
0622 
0623 BOOST_AUTO_TEST_SUITE_END()
0624 
0625 BOOST_AUTO_TEST_SUITE_END()
0626 }  // namespace Acts::Test