File indexing completed on 2025-01-18 09:12:59
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Utilities/RangeXD.hpp"
0012
0013 #include <limits>
0014 #include <utility>
0015 #include <vector>
0016
0017 namespace {
0018 std::vector<int> v = {-100, -90, -80, -70, -60, -50, -40, -30, -20, 10, 0,
0019 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
0020 }
0021
0022 namespace Acts::Test {
0023
0024 BOOST_AUTO_TEST_SUITE(Utilities)
0025
0026 BOOST_AUTO_TEST_SUITE(Range1D)
0027
0028 BOOST_AUTO_TEST_CASE(infinite_range_int) {
0029 Acts::Range1D<int> r;
0030
0031 BOOST_CHECK_EQUAL(r.min(), std::numeric_limits<int>::lowest());
0032 BOOST_CHECK_EQUAL(r.max(), std::numeric_limits<int>::max());
0033 }
0034
0035 BOOST_AUTO_TEST_CASE(infinite_range_double) {
0036 Acts::Range1D<double> r;
0037
0038 BOOST_CHECK_EQUAL(r.min(), std::numeric_limits<double>::lowest());
0039 BOOST_CHECK_EQUAL(r.max(), std::numeric_limits<double>::max());
0040 }
0041
0042 BOOST_AUTO_TEST_CASE(constructor_range_int) {
0043 Acts::Range1D<int> r(-11, 2);
0044
0045 BOOST_CHECK_EQUAL(r.min(), -11);
0046 BOOST_CHECK_EQUAL(r.max(), 2);
0047 }
0048
0049 BOOST_AUTO_TEST_CASE(constructor_range_double) {
0050 Acts::Range1D<double> r(-11.0, 2.0);
0051
0052 BOOST_CHECK_EQUAL(r.min(), -11.0);
0053 BOOST_CHECK_EQUAL(r.max(), 2.0);
0054 }
0055
0056 BOOST_AUTO_TEST_CASE(constructor_copy_double) {
0057 Acts::Range1D<double> q(-11.0, 2.0);
0058 Acts::Range1D<double> r(q);
0059
0060 BOOST_CHECK_EQUAL(r.min(), -11.0);
0061 BOOST_CHECK_EQUAL(r.max(), 2.0);
0062 }
0063
0064 BOOST_AUTO_TEST_CASE(constructor_tuple_double) {
0065 Acts::Range1D<double> r(std::pair<double, double>(-11.0, 2.0));
0066
0067 BOOST_CHECK_EQUAL(r.min(), -11.0);
0068 BOOST_CHECK_EQUAL(r.max(), 2.0);
0069 }
0070
0071 BOOST_AUTO_TEST_CASE(assign_double) {
0072 Acts::Range1D<double> q(-11.0, 2.0);
0073 Acts::Range1D<double> r = q;
0074
0075 BOOST_CHECK_EQUAL(r.min(), -11.0);
0076 BOOST_CHECK_EQUAL(r.max(), 2.0);
0077 }
0078
0079 BOOST_AUTO_TEST_CASE(shrinkMin_double) {
0080 Acts::Range1D<double> r;
0081
0082 r.shrinkMin(-11.0);
0083
0084 BOOST_CHECK_EQUAL(r.min(), -11.0);
0085 BOOST_CHECK_EQUAL(r.max(), std::numeric_limits<double>::max());
0086 }
0087
0088 BOOST_AUTO_TEST_CASE(shrinkMax_double) {
0089 Acts::Range1D<double> r;
0090
0091 r.shrinkMax(2.0);
0092
0093 BOOST_CHECK_EQUAL(r.min(), std::numeric_limits<double>::lowest());
0094 BOOST_CHECK_EQUAL(r.max(), 2.0);
0095 }
0096
0097 BOOST_AUTO_TEST_CASE(shrink_both_double) {
0098 Acts::Range1D<double> r;
0099
0100 r.shrinkMin(-11.0);
0101 r.shrinkMax(2.0);
0102
0103 BOOST_CHECK_EQUAL(r.min(), -11.0);
0104 BOOST_CHECK_EQUAL(r.max(), 2.0);
0105 }
0106
0107 BOOST_AUTO_TEST_CASE(shrink_double) {
0108 Acts::Range1D<double> r;
0109
0110 r.shrink(-11.0, 2.0);
0111
0112 BOOST_CHECK_EQUAL(r.min(), -11.0);
0113 BOOST_CHECK_EQUAL(r.max(), 2.0);
0114 }
0115
0116 BOOST_AUTO_TEST_CASE(shrink_twice_double) {
0117 Acts::Range1D<double> r;
0118
0119 r.shrink(-100.0, 20.0);
0120 r.shrink(-11.0, 2.0);
0121
0122 BOOST_CHECK_EQUAL(r.min(), -11.0);
0123 BOOST_CHECK_EQUAL(r.max(), 2.0);
0124 }
0125
0126 BOOST_AUTO_TEST_CASE(shrink_noop_double) {
0127 Acts::Range1D<double> r;
0128
0129 r.shrink(-11.0, 2.0);
0130 r.shrink(-100.0, 20.0);
0131
0132 BOOST_CHECK_EQUAL(r.min(), -11.0);
0133 BOOST_CHECK_EQUAL(r.max(), 2.0);
0134 }
0135
0136 BOOST_AUTO_TEST_CASE(shrink_noop_min_double) {
0137 Acts::Range1D<double> r;
0138
0139 r.shrink(-11.0, 2.0);
0140 r.shrink(-100.0, 1.0);
0141
0142 BOOST_CHECK_EQUAL(r.min(), -11.0);
0143 BOOST_CHECK_EQUAL(r.max(), 1.0);
0144 }
0145
0146 BOOST_AUTO_TEST_CASE(shrink_noop_max_double) {
0147 Acts::Range1D<double> r;
0148
0149 r.shrink(-11.0, 2.0);
0150 r.shrink(-10.0, 20.0);
0151
0152 BOOST_CHECK_EQUAL(r.min(), -10.0);
0153 BOOST_CHECK_EQUAL(r.max(), 2.0);
0154 }
0155
0156 BOOST_AUTO_TEST_CASE(shrinkMin_noop_double) {
0157 Acts::Range1D<double> r;
0158
0159 r.shrinkMin(-11.0);
0160 r.shrinkMin(-100.0);
0161
0162 BOOST_CHECK_EQUAL(r.min(), -11.0);
0163 BOOST_CHECK_EQUAL(r.max(), std::numeric_limits<double>::max());
0164 }
0165
0166 BOOST_AUTO_TEST_CASE(shrinkMax_noop_double) {
0167 Acts::Range1D<double> r;
0168
0169 r.shrinkMax(2.0);
0170 r.shrinkMax(4.0);
0171
0172 BOOST_CHECK_EQUAL(r.min(), std::numeric_limits<double>::lowest());
0173 BOOST_CHECK_EQUAL(r.max(), 2.0);
0174 }
0175
0176 BOOST_AUTO_TEST_CASE(setMin_double) {
0177 Acts::Range1D<double> r;
0178
0179 r.setMin(2.0);
0180
0181 BOOST_CHECK_EQUAL(r.min(), 2.0);
0182 BOOST_CHECK_EQUAL(r.max(), std::numeric_limits<double>::max());
0183 }
0184
0185 BOOST_AUTO_TEST_CASE(setMin_twice_double) {
0186 Acts::Range1D<double> r;
0187
0188 r.setMin(-2.0);
0189 r.setMin(-4.0);
0190
0191 BOOST_CHECK_EQUAL(r.min(), -4.0);
0192 BOOST_CHECK_EQUAL(r.max(), std::numeric_limits<double>::max());
0193 }
0194
0195 BOOST_AUTO_TEST_CASE(setMax_double) {
0196 Acts::Range1D<double> r;
0197
0198 r.setMax(2.0);
0199
0200 BOOST_CHECK_EQUAL(r.min(), std::numeric_limits<double>::lowest());
0201 BOOST_CHECK_EQUAL(r.max(), 2.0);
0202 }
0203
0204 BOOST_AUTO_TEST_CASE(setMax_twice_double) {
0205 Acts::Range1D<double> r;
0206
0207 r.setMax(2.0);
0208 r.setMax(4.0);
0209
0210 BOOST_CHECK_EQUAL(r.min(), std::numeric_limits<double>::lowest());
0211 BOOST_CHECK_EQUAL(r.max(), 4.0);
0212 }
0213
0214 BOOST_AUTO_TEST_CASE(expandMin_double) {
0215 Acts::Range1D<double> r(0.0, 0.0);
0216
0217 r.expandMin(-11.0);
0218
0219 BOOST_CHECK_EQUAL(r.min(), -11.0);
0220 BOOST_CHECK_EQUAL(r.max(), 0.0);
0221 }
0222
0223 BOOST_AUTO_TEST_CASE(expandMax_double) {
0224 Acts::Range1D<double> r(0.0, 0.0);
0225
0226 r.expandMax(2.0);
0227
0228 BOOST_CHECK_EQUAL(r.min(), 0.0);
0229 BOOST_CHECK_EQUAL(r.max(), 2.0);
0230 }
0231
0232 BOOST_AUTO_TEST_CASE(expand_both_double) {
0233 Acts::Range1D<double> r(0.0, 0.0);
0234
0235 r.expandMin(-11.0);
0236 r.expandMax(2.0);
0237
0238 BOOST_CHECK_EQUAL(r.min(), -11.0);
0239 BOOST_CHECK_EQUAL(r.max(), 2.0);
0240 }
0241
0242 BOOST_AUTO_TEST_CASE(expand_double) {
0243 Acts::Range1D<double> r(0.0, 0.0);
0244
0245 r.expand(-11.0, 2.0);
0246
0247 BOOST_CHECK_EQUAL(r.min(), -11.0);
0248 BOOST_CHECK_EQUAL(r.max(), 2.0);
0249 }
0250
0251 BOOST_AUTO_TEST_CASE(expand_twice_double) {
0252 Acts::Range1D<double> r(0.0, 0.0);
0253
0254 r.expand(-11.0, 2.0);
0255 r.expand(-100.0, 20.0);
0256
0257 BOOST_CHECK_EQUAL(r.min(), -100.0);
0258 BOOST_CHECK_EQUAL(r.max(), 20.0);
0259 }
0260
0261 BOOST_AUTO_TEST_CASE(expand_noop_double) {
0262 Acts::Range1D<double> r(0.0, 0.0);
0263
0264 r.expand(-100.0, 20.0);
0265 r.expand(-11.0, 2.0);
0266
0267 BOOST_CHECK_EQUAL(r.min(), -100.0);
0268 BOOST_CHECK_EQUAL(r.max(), 20.0);
0269 }
0270
0271 BOOST_AUTO_TEST_CASE(expand_noop_min_double) {
0272 Acts::Range1D<double> r(0.0, 0.0);
0273
0274 r.expand(-100.0, 1.0);
0275 r.expand(-11.0, 2.0);
0276
0277 BOOST_CHECK_EQUAL(r.min(), -100.0);
0278 BOOST_CHECK_EQUAL(r.max(), 2.0);
0279 }
0280
0281 BOOST_AUTO_TEST_CASE(expand_noop_max_double) {
0282 Acts::Range1D<double> r(0.0, 0.0);
0283
0284 r.expand(-10.0, 20.0);
0285 r.expand(-11.0, 2.0);
0286
0287 BOOST_CHECK_EQUAL(r.min(), -11.0);
0288 BOOST_CHECK_EQUAL(r.max(), 20.0);
0289 }
0290
0291 BOOST_AUTO_TEST_CASE(expandMin_noop_double) {
0292 Acts::Range1D<double> r(0.0, 0.0);
0293
0294 r.expandMin(-100.0);
0295 r.expandMin(-11.0);
0296
0297 BOOST_CHECK_EQUAL(r.min(), -100.0);
0298 BOOST_CHECK_EQUAL(r.max(), 0.0);
0299 }
0300
0301 BOOST_AUTO_TEST_CASE(expandMax_noop_double) {
0302 Acts::Range1D<double> r(0.0, 0.0);
0303
0304 r.expandMax(4.0);
0305 r.expandMax(2.0);
0306
0307 BOOST_CHECK_EQUAL(r.min(), 0.0);
0308 BOOST_CHECK_EQUAL(r.max(), 4.0);
0309 }
0310
0311 BOOST_AUTO_TEST_CASE(size_double) {
0312 Acts::Range1D<double> r(-10.0, 25.0);
0313
0314 BOOST_CHECK_EQUAL(r.size(), 35.0);
0315 }
0316
0317 BOOST_AUTO_TEST_CASE(size_zero_double) {
0318 Acts::Range1D<double> r(-10.0, -10.0);
0319
0320 BOOST_CHECK_EQUAL(r.size(), 0.0);
0321 }
0322
0323 BOOST_AUTO_TEST_CASE(size_zero2_double) {
0324 Acts::Range1D<double> r(-10.0, -50.0);
0325
0326 BOOST_CHECK_EQUAL(r.size(), 0.0);
0327 }
0328
0329 BOOST_AUTO_TEST_CASE(degenerate_false_double) {
0330 Acts::Range1D<double> r(-10.0, 25.0);
0331
0332 BOOST_CHECK(!r.degenerate());
0333 }
0334
0335 BOOST_AUTO_TEST_CASE(degenerate_true_double) {
0336 Acts::Range1D<double> r(-10.0, -25.0);
0337
0338 BOOST_CHECK(r.degenerate());
0339 }
0340
0341 BOOST_AUTO_TEST_CASE(contains_double) {
0342 Acts::Range1D<double> r(-10.0, 25.0);
0343
0344 BOOST_CHECK(!r.contains(-11.0));
0345 BOOST_CHECK(!r.contains(-30.0));
0346 BOOST_CHECK(r.contains(-5.0));
0347 BOOST_CHECK(r.contains(0.0));
0348 BOOST_CHECK(r.contains(10.0));
0349 }
0350
0351 BOOST_AUTO_TEST_CASE(contains_degenerate_double) {
0352 Acts::Range1D<double> r(-10.0, -25.0);
0353
0354 BOOST_CHECK(!r.contains(-11.0));
0355 BOOST_CHECK(!r.contains(-30.0));
0356 BOOST_CHECK(!r.contains(-5.0));
0357 BOOST_CHECK(!r.contains(0.0));
0358 BOOST_CHECK(!r.contains(10.0));
0359 }
0360
0361 BOOST_AUTO_TEST_CASE(intersect_true1_double) {
0362 Acts::Range1D<double> r(-10.0, 25.0);
0363 Acts::Range1D<double> q(5.0, 50.0);
0364
0365 BOOST_CHECK((r && q));
0366 }
0367
0368 BOOST_AUTO_TEST_CASE(intersect_true2_double) {
0369 Acts::Range1D<double> r(-10.0, 25.0);
0370 Acts::Range1D<double> q(-100.0, 50.0);
0371
0372 BOOST_CHECK((r && q));
0373 }
0374
0375 BOOST_AUTO_TEST_CASE(intersect_true3_double) {
0376 Acts::Range1D<double> r(-10.0, 25.0);
0377 Acts::Range1D<double> q(-5.0, 5.0);
0378
0379 BOOST_CHECK((r && q));
0380 }
0381
0382 BOOST_AUTO_TEST_CASE(intersect_false1_double) {
0383 Acts::Range1D<double> r(-10.0, 25.0);
0384 Acts::Range1D<double> q(-50.0, -15.0);
0385
0386 BOOST_CHECK(!(r && q));
0387 }
0388
0389 BOOST_AUTO_TEST_CASE(intersect_false2_double) {
0390 Acts::Range1D<double> r(-10.0, 25.0);
0391 Acts::Range1D<double> q(50.0, 55.0);
0392
0393 BOOST_CHECK(!(r && q));
0394 }
0395
0396 BOOST_AUTO_TEST_CASE(equals_true_int) {
0397 Acts::Range1D<int> r(-5, 5);
0398 Acts::Range1D<int> q(-5, 5);
0399
0400 BOOST_CHECK((r == q));
0401 }
0402
0403 BOOST_AUTO_TEST_CASE(equals_false_int) {
0404 Acts::Range1D<int> r(-5, 5);
0405 Acts::Range1D<int> q(-6, 4);
0406
0407 BOOST_CHECK(!(r == q));
0408 }
0409
0410 BOOST_AUTO_TEST_CASE(subset1_double) {
0411 Acts::Range1D<double> r(-10.0, 25.0);
0412 Acts::Range1D<double> q(5.0, 50.0);
0413
0414 BOOST_CHECK(!(r <= q));
0415 BOOST_CHECK(!(q <= r));
0416 }
0417
0418 BOOST_AUTO_TEST_CASE(subset2_double) {
0419 Acts::Range1D<double> r(-10.0, 25.0);
0420 Acts::Range1D<double> q(-100.0, 50.0);
0421
0422 BOOST_CHECK((r <= q));
0423 BOOST_CHECK(!(q <= r));
0424 }
0425
0426 BOOST_AUTO_TEST_CASE(subset3_double) {
0427 Acts::Range1D<double> r(-10.0, 25.0);
0428 Acts::Range1D<double> q(-5.0, 5.0);
0429
0430 BOOST_CHECK(!(r <= q));
0431 BOOST_CHECK((q <= r));
0432 }
0433
0434 BOOST_AUTO_TEST_CASE(subset4_double) {
0435 Acts::Range1D<double> r(-10.0, 25.0);
0436 Acts::Range1D<double> q(-50.0, -15.0);
0437
0438 BOOST_CHECK(!(r <= q));
0439 BOOST_CHECK(!(q <= r));
0440 }
0441
0442 BOOST_AUTO_TEST_CASE(subset5_double) {
0443 Acts::Range1D<double> r(-10.0, 25.0);
0444 Acts::Range1D<double> q(50.0, 55.0);
0445
0446 BOOST_CHECK(!(r <= q));
0447 BOOST_CHECK(!(q <= r));
0448 }
0449
0450 BOOST_AUTO_TEST_CASE(superset1_double) {
0451 Acts::Range1D<double> r(-10.0, 25.0);
0452 Acts::Range1D<double> q(5.0, 50.0);
0453
0454 BOOST_CHECK(!(r >= q));
0455 BOOST_CHECK(!(q >= r));
0456 }
0457
0458 BOOST_AUTO_TEST_CASE(superset2_double) {
0459 Acts::Range1D<double> r(-10.0, 25.0);
0460 Acts::Range1D<double> q(-100.0, 50.0);
0461
0462 BOOST_CHECK(!(r >= q));
0463 BOOST_CHECK((q >= r));
0464 }
0465
0466 BOOST_AUTO_TEST_CASE(superset3_double) {
0467 Acts::Range1D<double> r(-10.0, 25.0);
0468 Acts::Range1D<double> q(-5.0, 5.0);
0469
0470 BOOST_CHECK((r >= q));
0471 BOOST_CHECK(!(q >= r));
0472 }
0473
0474 BOOST_AUTO_TEST_CASE(superset4_double) {
0475 Acts::Range1D<double> r(-10.0, 25.0);
0476 Acts::Range1D<double> q(-50.0, -15.0);
0477
0478 BOOST_CHECK(!(r >= q));
0479 BOOST_CHECK(!(q >= r));
0480 }
0481
0482 BOOST_AUTO_TEST_CASE(superset5_double) {
0483 Acts::Range1D<double> r(-10.0, 25.0);
0484 Acts::Range1D<double> q(50.0, 55.0);
0485
0486 BOOST_CHECK(!(r >= q));
0487 BOOST_CHECK(!(q >= r));
0488 }
0489
0490 BOOST_AUTO_TEST_CASE(intersection1_double) {
0491 Acts::Range1D<double> r(-10.0, 25.0);
0492 Acts::Range1D<double> q(5.0, 50.0);
0493 Acts::Range1D<double> i = r & q;
0494
0495 BOOST_CHECK_EQUAL(i.min(), 5.0);
0496 BOOST_CHECK_EQUAL(i.max(), 25.0);
0497 }
0498
0499 BOOST_AUTO_TEST_CASE(intersection2_double) {
0500 Acts::Range1D<double> r(-10.0, 25.0);
0501 Acts::Range1D<double> q(-100.0, 50.0);
0502 Acts::Range1D<double> i = r & q;
0503
0504 BOOST_CHECK_EQUAL(i.min(), -10.0);
0505 BOOST_CHECK_EQUAL(i.max(), 25.0);
0506 }
0507
0508 BOOST_AUTO_TEST_CASE(intersection3_double) {
0509 Acts::Range1D<double> r(-10.0, 25.0);
0510 Acts::Range1D<double> q(-5.0, 5.0);
0511 Acts::Range1D<double> i = r & q;
0512
0513 BOOST_CHECK_EQUAL(i.min(), -5.0);
0514 BOOST_CHECK_EQUAL(i.max(), 5.0);
0515 }
0516
0517 BOOST_AUTO_TEST_CASE(intersection4_double) {
0518 Acts::Range1D<double> r(-10.0, 25.0);
0519 Acts::Range1D<double> q(-50.0, -15.0);
0520 Acts::Range1D<double> i = r & q;
0521
0522 BOOST_CHECK(i.degenerate());
0523 }
0524
0525 BOOST_AUTO_TEST_CASE(intersection5_double) {
0526 Acts::Range1D<double> r(-10.0, 25.0);
0527 Acts::Range1D<double> q(50.0, 55.0);
0528 Acts::Range1D<double> i = r & q;
0529
0530 BOOST_CHECK(i.degenerate());
0531 }
0532
0533 BOOST_AUTO_TEST_CASE(intersects_edge_int_positive) {
0534 Acts::Range1D<int> r(-10, 11);
0535 Acts::Range1D<int> q(10, 20);
0536
0537 BOOST_CHECK((r && q));
0538 }
0539
0540 BOOST_AUTO_TEST_CASE(intersects_edge_int_negative) {
0541 Acts::Range1D<int> r(-10, 10);
0542 Acts::Range1D<int> q(10, 20);
0543
0544 BOOST_CHECK(!(r && q));
0545 }
0546
0547 BOOST_AUTO_TEST_CASE(single_value_not_degenerate_int_positive) {
0548 Acts::Range1D<int> r(10, 10);
0549
0550 BOOST_CHECK(r.degenerate());
0551 }
0552
0553 BOOST_AUTO_TEST_CASE(single_value_not_degenerate_int_negative) {
0554 Acts::Range1D<int> r(10, 11);
0555
0556 BOOST_CHECK(!r.degenerate());
0557 }
0558
0559 BOOST_AUTO_TEST_CASE(intersects_implies_non_degenerate_intersection) {
0560 for (int i1 : v) {
0561 for (int i2 : v) {
0562 for (int j1 : v) {
0563 for (int j2 : v) {
0564 Acts::Range1D<int> r(i1, i2);
0565 Acts::Range1D<int> q(j1, j2);
0566
0567 if (r.degenerate() || q.degenerate()) {
0568 continue;
0569 }
0570
0571 if (r && q) {
0572 BOOST_CHECK(!((r & q).degenerate()));
0573 } else {
0574 BOOST_CHECK(((r & q).degenerate()));
0575 }
0576 }
0577 }
0578 }
0579 }
0580 }
0581
0582 BOOST_AUTO_TEST_CASE(degeneracy_implies_size_zero_intersection) {
0583 for (int i1 : v) {
0584 for (int i2 : v) {
0585 Acts::Range1D<int> r(i1, i2);
0586
0587 if (r.degenerate()) {
0588 BOOST_CHECK_EQUAL(r.size(), 0);
0589 } else {
0590 BOOST_CHECK_GE(r.size(), 0);
0591 }
0592 }
0593 }
0594 }
0595
0596 BOOST_AUTO_TEST_CASE(range_inclusive_left) {
0597 Acts::Range1D<int> r(10, 20);
0598
0599 BOOST_CHECK(!r.contains(9));
0600 BOOST_CHECK(r.contains(10));
0601 BOOST_CHECK(r.contains(11));
0602 }
0603
0604 BOOST_AUTO_TEST_CASE(range_exclusive_right) {
0605 Acts::Range1D<int> r(10, 20);
0606
0607 BOOST_CHECK(r.contains(19));
0608 BOOST_CHECK(!r.contains(20));
0609 BOOST_CHECK(!r.contains(21));
0610 }
0611
0612 BOOST_AUTO_TEST_SUITE_END()
0613
0614 BOOST_AUTO_TEST_SUITE_END()
0615
0616 }