| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cstdint> | ||
| 4 | #include <functional> | ||
| 5 | #include <string> | ||
| 6 | #include <tuple> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "task/include/task.hpp" | ||
| 10 | |||
| 11 | namespace tsibareva_e_integral_calculate_trapezoid_method { | ||
| 12 | |||
| 13 | enum class IntegralTestType : std::uint8_t { | ||
| 14 | kSuccessSimple2D, | ||
| 15 | kSuccessConstant2D, | ||
| 16 | kSuccessSimple3D, | ||
| 17 | kSuccessConstant3D, | ||
| 18 | kInvalidLowerBoundEqual, | ||
| 19 | kInvalidStepsNegative, | ||
| 20 | kInvalidEmptyBounds, | ||
| 21 | }; | ||
| 22 | |||
| 23 | 56 | struct Integral { | |
| 24 | std::vector<double> lo; | ||
| 25 | std::vector<double> hi; | ||
| 26 | std::vector<int> steps; | ||
| 27 | std::function<double(const std::vector<double> &)> f; | ||
| 28 | int dim{0}; | ||
| 29 | }; | ||
| 30 | |||
| 31 | using InType = Integral; | ||
| 32 | using OutType = double; | ||
| 33 | using TestType = std::tuple<IntegralTestType, std::string>; | ||
| 34 | using BaseTask = ppc::task::Task<InType, OutType>; | ||
| 35 | |||
| 36 |
7/8✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
|
56 | inline Integral GenerateIntegralInput(IntegralTestType type) { |
| 37 | Integral input; | ||
| 38 | |||
| 39 |
7/8✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 8 times.
✗ Branch 7 not taken.
|
56 | switch (type) { |
| 40 | 8 | case IntegralTestType::kSuccessSimple2D: { | |
| 41 | 8 | input.dim = 2; | |
| 42 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.lo = {0.0, 0.0}; |
| 43 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.hi = {1.0, 1.0}; |
| 44 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.steps = {100, 100}; |
| 45 | 8 | input.f = [](const std::vector<double> &x) { return (x[0] * x[0]) + (x[1] * x[1]); }; // x^2 + y^2 | |
| 46 | 8 | break; | |
| 47 | } | ||
| 48 | 8 | case IntegralTestType::kSuccessConstant2D: { | |
| 49 | 8 | input.dim = 2; | |
| 50 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.lo = {0.0, 0.0}; |
| 51 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.hi = {2.0, 3.0}; |
| 52 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.steps = {50, 50}; |
| 53 | 8 | input.f = [](const std::vector<double> &) { return 5.0; }; // const | |
| 54 | 8 | break; | |
| 55 | } | ||
| 56 | 8 | case IntegralTestType::kSuccessSimple3D: { | |
| 57 | 8 | input.dim = 3; | |
| 58 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.lo = {0.0, 0.0, 0.0}; |
| 59 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.hi = {1.0, 1.0, 1.0}; |
| 60 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.steps = {50, 50, 50}; |
| 61 | 8 | input.f = [](const std::vector<double> &x) { return x[0] + x[1] + x[2]; }; // x + y + z | |
| 62 | 8 | break; | |
| 63 | } | ||
| 64 | 8 | case IntegralTestType::kSuccessConstant3D: { | |
| 65 | 8 | input.dim = 3; | |
| 66 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.lo = {0.0, 0.0, 0.0}; |
| 67 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.hi = {2.0, 2.0, 2.0}; |
| 68 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.steps = {40, 40, 40}; |
| 69 | 8 | input.f = [](const std::vector<double> &) { return 3.0; }; | |
| 70 | 8 | break; | |
| 71 | } | ||
| 72 | 8 | case IntegralTestType::kInvalidLowerBoundEqual: { | |
| 73 | 8 | input.dim = 2; | |
| 74 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.lo = {1.0, 0.0}; |
| 75 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.hi = {1.0, 1.0}; |
| 76 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.steps = {10, 10}; |
| 77 | 8 | input.f = [](const std::vector<double> &x) { return x[0]; }; | |
| 78 | 8 | break; | |
| 79 | } | ||
| 80 | 8 | case IntegralTestType::kInvalidStepsNegative: { | |
| 81 | 8 | input.dim = 2; | |
| 82 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.lo = {0.0, 0.0}; |
| 83 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.hi = {1.0, 1.0}; |
| 84 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.steps = {-5, 10}; |
| 85 | 8 | input.f = [](const std::vector<double> &x) { return x[0]; }; | |
| 86 | 8 | break; | |
| 87 | } | ||
| 88 | 8 | case IntegralTestType::kInvalidEmptyBounds: { | |
| 89 | input.dim = 0; | ||
| 90 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.lo = {}; |
| 91 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.hi = {}; |
| 92 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | input.steps = {}; |
| 93 | 8 | input.f = [](const std::vector<double> &) { return 0.0; }; | |
| 94 | 8 | break; | |
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | 56 | return input; | |
| 99 | ✗ | } | |
| 100 | |||
| 101 | inline double GenerateExpectedOutput(IntegralTestType type) { | ||
| 102 | switch (type) { | ||
| 103 | case IntegralTestType::kSuccessSimple2D: | ||
| 104 | return 2.0 / 3.0; | ||
| 105 | case IntegralTestType::kSuccessConstant2D: | ||
| 106 | return 30.0; | ||
| 107 | case IntegralTestType::kSuccessSimple3D: | ||
| 108 | return 1.5; | ||
| 109 | case IntegralTestType::kSuccessConstant3D: | ||
| 110 | return 24.0; | ||
| 111 | case IntegralTestType::kInvalidLowerBoundEqual: | ||
| 112 | case IntegralTestType::kInvalidStepsNegative: | ||
| 113 | case IntegralTestType::kInvalidEmptyBounds: | ||
| 114 | return 0.0; | ||
| 115 | } | ||
| 116 | return 0.0; | ||
| 117 | } | ||
| 118 | |||
| 119 | } // namespace tsibareva_e_integral_calculate_trapezoid_method | ||
| 120 |