GCC Code Coverage Report


Directory: ./
File: tasks/kutergin_a_multidim_trapezoid/seq/src/ops_seq.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 37 37 100.0%
Functions: 5 5 100.0%
Branches: 29 44 65.9%

Line Branch Exec Source
1 #include "kutergin_a_multidim_trapezoid/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <utility>
6 #include <vector>
7
8 #include "kutergin_a_multidim_trapezoid/common/include/common.hpp"
9
10 namespace kutergin_a_multidim_trapezoid {
11 namespace {
12
13 bool ValidateBorders(const std::vector<std::pair<double, double>> &borders) {
14 return std::ranges::all_of(
15
3/6
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 160 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 160 times.
✗ Branch 5 not taken.
160 borders, [](const auto &p) { return std::isfinite(p.first) && std::isfinite(p.second) && (p.first < p.second); });
16 }
17
18 bool NextIndex(std::vector<int> &idx, int dim, int max_index) {
19
2/2
✓ Branch 0 taken 2909200 times.
✓ Branch 1 taken 96 times.
2909296 for (int pos = 0; pos < dim; ++pos) {
20
2/2
✓ Branch 0 taken 37200 times.
✓ Branch 1 taken 2872000 times.
2909200 ++idx[pos];
21
2/2
✓ Branch 0 taken 37200 times.
✓ Branch 1 taken 2872000 times.
2909200 if (idx[pos] <= max_index) {
22 return true;
23 }
24 37200 idx[pos] = 0;
25 }
26 return false;
27 }
28
29 } // namespace
30
31
1/2
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
96 KuterginAMultidimTrapezoidSEQ::KuterginAMultidimTrapezoidSEQ(const InType &in) {
32 SetTypeOfTask(GetStaticTypeOfTask());
33 GetInput() = in;
34 96 GetOutput() = 0.0;
35 96 }
36
37
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 bool KuterginAMultidimTrapezoidSEQ::ValidationImpl() {
38 const auto &[func, borders, n] = GetInput();
39
40
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if (!func) {
41 return false;
42 }
43
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if (n <= 0) {
44 return false;
45 }
46
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if (borders.empty()) {
47 return false;
48 }
49
50 return ValidateBorders(borders);
51 }
52
53 96 bool KuterginAMultidimTrapezoidSEQ::PreProcessingImpl() {
54 96 GetOutput() = 0.0;
55 96 return true;
56 }
57
58 96 bool KuterginAMultidimTrapezoidSEQ::RunImpl() {
59 const auto &[func, borders, n] = GetInput();
60 96 const int dim = static_cast<int>(borders.size());
61
62 96 std::vector<double> h(dim);
63 double cell_volume = 1.0;
64
65
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 96 times.
256 for (int i = 0; i < dim; ++i) {
66 160 const double left = borders[i].first;
67 160 const double right = borders[i].second;
68 160 h[i] = (right - left) / n;
69 160 cell_volume *= h[i];
70 }
71
72 96 const int max_index = n;
73
74
1/4
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
96 std::vector<int> idx(dim, 0);
75
1/4
✓ Branch 1 taken 96 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
96 std::vector<double> point(dim);
76
77 double sum = 0.0;
78
79 while (true) {
80 double weight = 1.0;
81
82
2/2
✓ Branch 0 taken 7551840 times.
✓ Branch 1 taken 2872096 times.
10423936 for (int i = 0; i < dim; ++i) {
83
2/2
✓ Branch 0 taken 7448800 times.
✓ Branch 1 taken 103040 times.
7551840 point[i] = (borders[i].first + (idx[i] * h[i]));
84
85
4/4
✓ Branch 0 taken 7448800 times.
✓ Branch 1 taken 103040 times.
✓ Branch 2 taken 103040 times.
✓ Branch 3 taken 7345760 times.
7551840 if ((idx[i] == 0) || (idx[i] == n)) {
86 206080 weight *= 0.5;
87 }
88 }
89
90 double f_val = func(point);
91
1/2
✓ Branch 0 taken 2872096 times.
✗ Branch 1 not taken.
2872096 if (!std::isfinite(f_val)) {
92 return false;
93 }
94
95 2872096 sum += weight * f_val;
96
97
2/2
✓ Branch 0 taken 2872000 times.
✓ Branch 1 taken 96 times.
2872096 if (!NextIndex(idx, dim, max_index)) {
98 break;
99 }
100 }
101
102 96 GetOutput() = sum * cell_volume;
103 96 return std::isfinite(GetOutput());
104 }
105
106 96 bool KuterginAMultidimTrapezoidSEQ::PostProcessingImpl() {
107 96 return std::isfinite(GetOutput());
108 }
109
110 } // namespace kutergin_a_multidim_trapezoid
111