GCC Code Coverage Report


Directory: ./
File: tasks/shkrebko_m_calc_of_integral_rect/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 39 39 100.0%
Functions: 5 5 100.0%
Branches: 23 38 60.5%

Line Branch Exec Source
1 #include "shkrebko_m_calc_of_integral_rect/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <vector>
7
8 #include "shkrebko_m_calc_of_integral_rect/common/include/common.hpp"
9
10 namespace shkrebko_m_calc_of_integral_rect {
11
12
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 ShkrebkoMCalcOfIntegralRectSEQ::ShkrebkoMCalcOfIntegralRectSEQ(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 GetInput() = in;
15 80 GetOutput() = 0.0;
16 80 }
17
18
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 bool ShkrebkoMCalcOfIntegralRectSEQ::ValidationImpl() {
19 const auto &input = GetInput();
20
21
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 if (!input.func) {
22 return false;
23 }
24
2/4
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
80 if (input.limits.size() != input.n_steps.size() || input.limits.empty()) {
25 return false;
26 }
27
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 if (!std::ranges::all_of(input.n_steps, [](int n) { return n > 0; })) {
28 return false;
29 }
30
31
1/2
✓ Branch 0 taken 120 times.
✗ Branch 1 not taken.
120 if (!std::ranges::all_of(input.limits, [](const auto &lim) { return lim.first < lim.second; })) {
32 return false;
33 }
34
35 return true;
36 }
37
38 80 bool ShkrebkoMCalcOfIntegralRectSEQ::PreProcessingImpl() {
39 80 local_input_ = GetInput();
40 80 res_ = 0.0;
41 80 return true;
42 }
43
44 80 bool ShkrebkoMCalcOfIntegralRectSEQ::RunImpl() {
45 const std::size_t dim = local_input_.limits.size();
46 80 std::vector<double> h(dim);
47 double cell_volume = 1.0;
48
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 80 times.
200 for (std::size_t i = 0; i < dim; ++i) {
49 120 const double left = local_input_.limits[i].first;
50 120 const double right = local_input_.limits[i].second;
51 120 const int steps = local_input_.n_steps[i];
52 120 h[i] = (right - left) / static_cast<double>(steps);
53 120 cell_volume *= h[i];
54 }
55
56
1/4
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
80 std::vector<int> idx(dim, 0);
57
1/4
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
80 std::vector<double> point(dim);
58 double sum = 0.0;
59
60 while (true) {
61
2/2
✓ Branch 0 taken 1908800 times.
✓ Branch 1 taken 702400 times.
2611200 for (std::size_t i = 0; i < dim; ++i) {
62 1908800 point[i] = local_input_.limits[i].first + ((static_cast<double>(idx[i]) + 0.5) * h[i]);
63 }
64
65 double f_val = local_input_.func(point);
66
1/2
✓ Branch 0 taken 702400 times.
✗ Branch 1 not taken.
702400 if (!std::isfinite(f_val)) {
67 return false;
68 }
69 702400 sum += f_val;
70
71 702400 int level = static_cast<int>(dim) - 1;
72
2/2
✓ Branch 0 taken 717600 times.
✓ Branch 1 taken 80 times.
717680 while (level >= 0) {
73
2/2
✓ Branch 0 taken 15280 times.
✓ Branch 1 taken 702320 times.
717600 idx[level]++;
74
2/2
✓ Branch 0 taken 15280 times.
✓ Branch 1 taken 702320 times.
717600 if (idx[level] < local_input_.n_steps[level]) {
75 break;
76 }
77 15280 idx[level] = 0;
78 15280 level--;
79 }
80
2/2
✓ Branch 0 taken 702320 times.
✓ Branch 1 taken 80 times.
702400 if (level < 0) {
81 break;
82 }
83 }
84
85 80 res_ = sum * cell_volume;
86 80 return true;
87 }
88
89 80 bool ShkrebkoMCalcOfIntegralRectSEQ::PostProcessingImpl() {
90 80 GetOutput() = res_;
91 80 return true;
92 }
93
94 } // namespace shkrebko_m_calc_of_integral_rect
95