File indexing completed on 2026-04-19 07:48:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Utilities/FunctionComposition.hpp"
0012
0013 #include <memory>
0014 #include <string>
0015
0016 namespace ActsTests {
0017
0018 BOOST_AUTO_TEST_SUITE(UtilitiesSuite)
0019
0020 BOOST_AUTO_TEST_CASE(ComposeTwoFunctions) {
0021 auto addOne = [](int x) { return x + 1; };
0022 auto doubleValue = [](int x) { return 2 * x; };
0023
0024 auto composed = Acts::compose(doubleValue, addOne);
0025
0026 BOOST_CHECK_EQUAL(composed(3), 8);
0027 }
0028
0029 BOOST_AUTO_TEST_CASE(ComposeMultipleFunctions) {
0030 auto decorate = [](const std::string& s) { return "[" + s + "]"; };
0031 auto appendB = [](const std::string& s) { return s + "b"; };
0032 auto appendA = [](const std::string& s) { return s + "a"; };
0033
0034 auto composed = Acts::compose(decorate, appendB, appendA);
0035
0036 BOOST_CHECK_EQUAL(composed(std::string{"x"}), "[xab]");
0037 }
0038
0039 BOOST_AUTO_TEST_CASE(ComposeForwardsMoveOnlyInput) {
0040 auto timesTwo = [](int x) { return x * 2; };
0041 auto takeOwnership = [](std::unique_ptr<int> ptr) { return *ptr + 1; };
0042
0043 auto composed = Acts::compose(timesTwo, takeOwnership);
0044
0045 BOOST_CHECK_EQUAL(composed(std::make_unique<int>(4)), 10);
0046 }
0047
0048 BOOST_AUTO_TEST_SUITE_END()
0049
0050 }