GCC Code Coverage Report


Directory: ./
File: tasks/chernykh_s_trapezoidal_integration/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 30 30 100.0%
Functions: 6 6 100.0%
Branches: 20 30 66.7%

Line Branch Exec Source
1 #include "chernykh_s_trapezoidal_integration/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <utility>
7 #include <vector>
8
9 #include "chernykh_s_trapezoidal_integration/common/include/common.hpp"
10
11 namespace chernykh_s_trapezoidal_integration {
12
13
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 ChernykhSTrapezoidalIntegrationSEQ::ChernykhSTrapezoidalIntegrationSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 GetInput() = in;
16 48 GetOutput() = 0.0;
17 48 }
18
19
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 bool ChernykhSTrapezoidalIntegrationSEQ::ValidationImpl() {
20 const auto &input = this->GetInput();
21
2/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
48 if (input.limits.empty() || input.limits.size() != input.steps.size()) {
22 return false;
23 }
24 return std::ranges::all_of(input.steps, [](int s) { return s > 0; });
25 }
26
27 48 bool ChernykhSTrapezoidalIntegrationSEQ::PreProcessingImpl() {
28 48 return true;
29 }
30
31 117088 double ChernykhSTrapezoidalIntegrationSEQ::CalculatePointAndWeight(const IntegrationInType &input,
32 const std::vector<std::size_t> &counters,
33 std::vector<double> &point) {
34 double weight = 1.0;
35
2/2
✓ Branch 0 taken 219992 times.
✓ Branch 1 taken 117088 times.
337080 for (std::size_t i = 0; i < input.limits.size(); ++i) {
36 219992 const double h = (input.limits[i].second - input.limits[i].first) / static_cast<double>(input.steps[i]);
37
2/2
✓ Branch 0 taken 215440 times.
✓ Branch 1 taken 4552 times.
219992 point[i] = input.limits[i].first + (static_cast<double>(counters[i]) * h);
38 if (std::cmp_equal(counters[i], 0) || std::cmp_equal(counters[i], input.steps[i])) {
39 9104 weight *= 0.5;
40 }
41 }
42 117088 return weight;
43 }
44
45 48 bool ChernykhSTrapezoidalIntegrationSEQ::RunImpl() {
46 const auto &input = this->GetInput();
47 const std::size_t dims = input.limits.size();
48 48 std::vector<std::size_t> counters(dims, 0);
49
1/4
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
48 std::vector<double> current_point(dims);
50 double total_sum = 0.0;
51 bool done = false;
52
53
2/2
✓ Branch 0 taken 117088 times.
✓ Branch 1 taken 48 times.
117136 while (!done) {
54 117088 double weight = CalculatePointAndWeight(input, counters, current_point);
55 117088 total_sum += input.func(current_point) * weight;
56
57
2/2
✓ Branch 0 taken 118952 times.
✓ Branch 1 taken 48 times.
119000 for (std::size_t i = 0; i < dims; ++i) {
58
1/2
✓ Branch 0 taken 118952 times.
✗ Branch 1 not taken.
118952 if (std::cmp_less(++counters[i], input.steps[i] + 1)) {
59 break;
60 }
61
2/2
✓ Branch 0 taken 1864 times.
✓ Branch 1 taken 48 times.
1912 if (std::cmp_equal(i, dims - 1)) {
62 done = true;
63 } else {
64 1864 counters[i] = 0;
65 }
66 }
67 }
68
69 double h_prod = 1.0;
70
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 48 times.
120 for (std::size_t i = 0; i < dims; ++i) {
71 72 h_prod *= (input.limits[i].second - input.limits[i].first) / static_cast<double>(input.steps[i]);
72 }
73
74
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 GetOutput() = total_sum * h_prod;
75 48 return true;
76 }
77
78 48 bool ChernykhSTrapezoidalIntegrationSEQ::PostProcessingImpl() {
79 48 return true;
80 }
81
82 } // namespace chernykh_s_trapezoidal_integration
83