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