| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "spichek_d_simpson_integral/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | |||
| 5 | // Explicitly include common.hpp to satisfy clang-tidy misc-include-cleaner for InType/OutType | ||
| 6 | #include "spichek_d_simpson_integral/common/include/common.hpp" | ||
| 7 | |||
| 8 | namespace spichek_d_simpson_integral { | ||
| 9 | |||
| 10 | namespace { | ||
| 11 | // Helper to reduce cognitive complexity and avoid nested ternary operators | ||
| 12 | int GetSimpsonWeight(int index, int n) { | ||
| 13 | 18528 | if (index == 0 || index == n) { | |
| 14 | return 1; | ||
| 15 | } | ||
| 16 |
4/4✓ Branch 0 taken 280 times.
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 8680 times.
✓ Branch 3 taken 8096 times.
|
17312 | return (index % 2 == 0) ? 2 : 4; |
| 17 | } | ||
| 18 | } // namespace | ||
| 19 | |||
| 20 | 24 | SpichekDSimpsonIntegralSEQ::SpichekDSimpsonIntegralSEQ(const InType &in) { | |
| 21 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 22 | 24 | GetInput() = in; | |
| 23 | GetOutput() = 0; | ||
| 24 | 24 | } | |
| 25 | |||
| 26 | 24 | bool SpichekDSimpsonIntegralSEQ::ValidationImpl() { | |
| 27 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
|
24 | return (GetInput() > 0) && (GetInput() % 2 == 0); |
| 28 | } | ||
| 29 | |||
| 30 | 24 | bool SpichekDSimpsonIntegralSEQ::PreProcessingImpl() { | |
| 31 | 24 | GetOutput() = 0; | |
| 32 | 24 | return true; | |
| 33 | } | ||
| 34 | |||
| 35 | 24 | bool SpichekDSimpsonIntegralSEQ::RunImpl() { | |
| 36 | 24 | int n = GetInput(); | |
| 37 | 24 | double h = 1.0 / n; | |
| 38 | double sum = 0.0; | ||
| 39 | |||
| 40 |
2/2✓ Branch 0 taken 584 times.
✓ Branch 1 taken 24 times.
|
608 | for (int i = 0; i <= n; i++) { |
| 41 |
2/2✓ Branch 0 taken 536 times.
✓ Branch 1 taken 48 times.
|
584 | const double x = i * h; |
| 42 | const int wx = GetSimpsonWeight(i, n); | ||
| 43 | |||
| 44 |
2/2✓ Branch 0 taken 17944 times.
✓ Branch 1 taken 584 times.
|
18528 | for (int j = 0; j <= n; j++) { |
| 45 |
2/2✓ Branch 0 taken 16776 times.
✓ Branch 1 taken 1168 times.
|
17944 | const double y = j * h; |
| 46 | const int wy = GetSimpsonWeight(j, n); | ||
| 47 | |||
| 48 | 17944 | sum += wx * wy * (x * x + y * y); | |
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | 24 | double result = sum * h * h / 9.0; | |
| 53 | 24 | GetOutput() = static_cast<OutType>(std::round(result)); | |
| 54 | 24 | return true; | |
| 55 | } | ||
| 56 | |||
| 57 | 24 | bool SpichekDSimpsonIntegralSEQ::PostProcessingImpl() { | |
| 58 | 24 | return true; | |
| 59 | } | ||
| 60 | |||
| 61 | } // namespace spichek_d_simpson_integral | ||
| 62 |