GCC Code Coverage Report


Directory: ./
File: tasks/nazyrov_a_multidim_integral_rectangle/seq/src/ops_seq.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 31 31 100.0%
Functions: 5 5 100.0%
Branches: 18 30 60.0%

Line Branch Exec Source
1 #include "nazyrov_a_multidim_integral_rectangle/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <cstdint>
7 #include <vector>
8
9 #include "nazyrov_a_multidim_integral_rectangle/common/include/common.hpp"
10
11 namespace nazyrov_a_multidim_integral_rectangle {
12
13
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 NazyrovAMultidimIntegralRectangleSeq::NazyrovAMultidimIntegralRectangleSeq(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 GetInput() = in;
16 80 GetOutput() = 0.0;
17 80 }
18
19 80 bool NazyrovAMultidimIntegralRectangleSeq::ValidationImpl() {
20 const auto &func = std::get<0>(GetInput());
21 const auto &bounds = std::get<1>(GetInput());
22
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 const int n = std::get<2>(GetInput());
23
3/6
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
80 return func && n > 0 && !bounds.empty() && std::ranges::all_of(bounds, [](const auto &bd) {
24
3/6
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 168 times.
✗ Branch 5 not taken.
168 return std::isfinite(bd.first) && std::isfinite(bd.second) && bd.first < bd.second;
25 80 });
26 }
27
28 80 bool NazyrovAMultidimIntegralRectangleSeq::PreProcessingImpl() {
29 80 return true;
30 }
31
32 80 bool NazyrovAMultidimIntegralRectangleSeq::RunImpl() {
33 const auto &func = std::get<0>(GetInput());
34 const auto &bounds = std::get<1>(GetInput());
35 80 const int n = std::get<2>(GetInput());
36
37 80 const int dim = static_cast<int>(bounds.size());
38
39 80 std::vector<double> h(static_cast<std::size_t>(dim));
40 double cell_vol = 1.0;
41
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 80 times.
248 for (int i = 0; i < dim; ++i) {
42 168 h[i] = (bounds[i].second - bounds[i].first) / n;
43 168 cell_vol *= h[i];
44 }
45
46 std::int64_t total = 1;
47
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 80 times.
248 for (int i = 0; i < dim; ++i) {
48 168 total *= n;
49 }
50
51 double sum = 0.0;
52
1/4
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
80 std::vector<double> point(static_cast<std::size_t>(dim));
53
54
2/2
✓ Branch 0 taken 11483200 times.
✓ Branch 1 taken 80 times.
11483280 for (std::int64_t cell = 0; cell < total; ++cell) {
55 std::int64_t tmp = cell;
56
2/2
✓ Branch 0 taken 33963200 times.
✓ Branch 1 taken 11483200 times.
45446400 for (int i = dim - 1; i >= 0; --i) {
57 33963200 const int ki = static_cast<int>(tmp % n);
58 33963200 tmp /= n;
59 33963200 const double coordinate = bounds[i].first + ((ki + 0.5) * h[i]);
60 33963200 point[i] = coordinate;
61 }
62 11483200 sum += func(point);
63 }
64
65
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 GetOutput() = sum * cell_vol;
66 80 return true;
67 }
68
69 80 bool NazyrovAMultidimIntegralRectangleSeq::PostProcessingImpl() {
70 80 return true;
71 }
72
73 } // namespace nazyrov_a_multidim_integral_rectangle
74