GCC Code Coverage Report


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

Line Branch Exec Source
1 #include "dergynov_s_integrals_multistep_rectangle/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <utility>
6 #include <vector>
7
8 #include "dergynov_s_integrals_multistep_rectangle/common/include/common.hpp"
9
10 namespace dergynov_s_integrals_multistep_rectangle {
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 264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 264 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 264 times.
✗ Branch 5 not taken.
264 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 n) {
19
2/2
✓ Branch 0 taken 10184160 times.
✓ Branch 1 taken 152 times.
10184312 for (int pos = 0; pos < dim; ++pos) {
20
2/2
✓ Branch 0 taken 114712 times.
✓ Branch 1 taken 10069448 times.
10184160 ++idx[pos];
21
2/2
✓ Branch 0 taken 114712 times.
✓ Branch 1 taken 10069448 times.
10184160 if (idx[pos] < n) {
22 return true;
23 }
24 114712 idx[pos] = 0;
25 }
26 return false;
27 }
28
29 } // namespace
30
31
1/2
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
152 DergynovSIntegralsMultistepRectangleSEQ::DergynovSIntegralsMultistepRectangleSEQ(const InType &in) {
32 SetTypeOfTask(GetStaticTypeOfTask());
33 GetInput() = in;
34 152 GetOutput() = 0.0;
35 152 }
36
37
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 bool DergynovSIntegralsMultistepRectangleSEQ::ValidationImpl() {
38 const auto &[func, borders, n] = GetInput();
39
40
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (!func) {
41 return false;
42 }
43
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (n <= 0) {
44 return false;
45 }
46
1/2
✓ Branch 0 taken 152 times.
✗ Branch 1 not taken.
152 if (borders.empty()) {
47 return false;
48 }
49
50 return ValidateBorders(borders);
51 }
52
53 152 bool DergynovSIntegralsMultistepRectangleSEQ::PreProcessingImpl() {
54 152 GetOutput() = 0.0;
55 152 return true;
56 }
57
58 152 bool DergynovSIntegralsMultistepRectangleSEQ::RunImpl() {
59 const auto &[func, borders, n] = GetInput();
60 152 const int dim = static_cast<int>(borders.size());
61
62 152 std::vector<double> h(dim);
63 double cell_volume = 1.0;
64
65
2/2
✓ Branch 0 taken 264 times.
✓ Branch 1 taken 152 times.
416 for (int i = 0; i < dim; ++i) {
66 264 const double left = borders[i].first;
67 264 const double right = borders[i].second;
68 264 h[i] = (right - left) / n;
69 264 cell_volume *= h[i];
70 }
71
72
1/4
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
152 std::vector<int> idx(dim, 0);
73
1/4
✓ Branch 1 taken 152 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
152 std::vector<double> point(dim);
74 double sum = 0.0;
75
76 while (true) {
77
2/2
✓ Branch 0 taken 29151200 times.
✓ Branch 1 taken 10069600 times.
39220800 for (int i = 0; i < dim; ++i) {
78 29151200 point[i] = borders[i].first + ((idx[i] + 0.5) * h[i]);
79 }
80
81 double f_val = func(point);
82
1/2
✓ Branch 0 taken 10069600 times.
✗ Branch 1 not taken.
10069600 if (!std::isfinite(f_val)) {
83 return false;
84 }
85 10069600 sum += f_val;
86
87
2/2
✓ Branch 0 taken 10069448 times.
✓ Branch 1 taken 152 times.
20139200 if (!NextIndex(idx, dim, n)) {
88 break;
89 }
90 }
91
92 152 GetOutput() = sum * cell_volume;
93 152 return std::isfinite(GetOutput());
94 }
95
96 152 bool DergynovSIntegralsMultistepRectangleSEQ::PostProcessingImpl() {
97 152 return std::isfinite(GetOutput());
98 }
99
100 } // namespace dergynov_s_integrals_multistep_rectangle
101