GCC Code Coverage Report


Directory: ./
File: tasks/samoylenko_i_integral_trapezoid/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 48 48 100.0%
Functions: 6 6 100.0%
Branches: 45 65 69.2%

Line Branch Exec Source
1 #include "samoylenko_i_integral_trapezoid/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <cstdint>
6 #include <functional>
7 #include <vector>
8
9 #include "samoylenko_i_integral_trapezoid/common/include/common.hpp"
10
11 namespace samoylenko_i_integral_trapezoid {
12
13 namespace {
14 40 std::function<double(const std::vector<double> &)> GetIntegrationFunction(int64_t choice) {
15
4/5
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
40 switch (choice) {
16 case 0: // x + y + ...
17 return [](const std::vector<double> &values) {
18 double sum = 0.0;
19
2/2
✓ Branch 0 taken 171224 times.
✓ Branch 1 taken 89616 times.
260840 for (double val : values) {
20 171224 sum += val;
21 }
22 return sum;
23 };
24 case 1: // x * y * ...
25 return [](const std::vector<double> &values) {
26 double mult = 1.0;
27
2/2
✓ Branch 0 taken 163216 times.
✓ Branch 1 taken 81608 times.
244824 for (double val : values) {
28 163216 mult *= val;
29 }
30 return mult;
31 };
32 case 2: // x^2 + y^2 + ...
33 return [](const std::vector<double> &values) {
34 double sum = 0.0;
35
2/2
✓ Branch 0 taken 3183624 times.
✓ Branch 1 taken 1061208 times.
4244832 for (double val : values) {
36 3183624 sum += val * val;
37 }
38 return sum;
39 };
40 case 3: // sin(x + y + ...)
41 return [](const std::vector<double> &values) {
42 double sum = 0.0;
43
2/2
✓ Branch 0 taken 8008 times.
✓ Branch 1 taken 8008 times.
16016 for (double val : values) {
44 8008 sum += val;
45 }
46 8008 return std::sin(sum);
47 };
48 default:
49 return [](const std::vector<double> &) { return 0.0; };
50 }
51 }
52 } // namespace
53
54
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 SamoylenkoIIntegralTrapezoidSEQ::SamoylenkoIIntegralTrapezoidSEQ(const InType &in) {
55 SetTypeOfTask(GetStaticTypeOfTask());
56
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 GetInput() = in;
57 40 GetOutput() = 0.0;
58 40 }
59
60
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 bool SamoylenkoIIntegralTrapezoidSEQ::ValidationImpl() {
61 const auto &in = GetInput();
62
63
3/6
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
40 if (in.a.empty() || in.a.size() != in.b.size() || in.a.size() != in.n.size()) {
64 return false;
65 }
66
67
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 40 times.
112 for (size_t i = 0; i < in.a.size(); ++i) {
68
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 72 times.
72 if (in.n[i] <= 0 || in.a[i] >= in.b[i]) {
69 return false;
70 }
71 }
72
73 40 return in.function_choice >= 0 && in.function_choice <= 3;
74 }
75
76 40 bool SamoylenkoIIntegralTrapezoidSEQ::PreProcessingImpl() {
77 40 GetOutput() = 0.0;
78 40 return true;
79 }
80
81
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 bool SamoylenkoIIntegralTrapezoidSEQ::RunImpl() {
82 const auto &in = GetInput();
83 40 const int dimensions = static_cast<int>(in.a.size());
84 40 auto integral_function = GetIntegrationFunction(in.function_choice);
85 double sum = 0.0;
86
87
1/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
40 std::vector<double> h(dimensions);
88
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 40 times.
112 for (int i = 0; i < dimensions; i++) {
89 72 h[i] = (in.b[i] - in.a[i]) / in.n[i];
90 }
91
92
1/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
40 std::vector<int64_t> dim_sizes(dimensions);
93 int64_t points = 1;
94
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 40 times.
112 for (int i = 0; i < dimensions; i++) {
95 72 dim_sizes[i] = in.n[i] + 1;
96 72 points *= dim_sizes[i];
97 }
98
99
1/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
40 std::vector<double> current_point(dimensions);
100
101
2/2
✓ Branch 0 taken 1240440 times.
✓ Branch 1 taken 40 times.
1240480 for (int64_t pnt = 0; pnt < points; pnt++) {
102 int64_t rem_index = pnt;
103 int weight = 1;
104
105
2/2
✓ Branch 0 taken 3526072 times.
✓ Branch 1 taken 1240440 times.
4766512 for (int dim = 0; dim < dimensions; dim++) {
106 // convert point index to its coordinate in dimension "dim"
107
2/2
✓ Branch 0 taken 3460400 times.
✓ Branch 1 taken 65672 times.
3526072 int dim_coord = static_cast<int>(rem_index % dim_sizes[dim]);
108
2/2
✓ Branch 0 taken 3460400 times.
✓ Branch 1 taken 65672 times.
3526072 rem_index /= dim_sizes[dim];
109
110 3526072 current_point[dim] = in.a[dim] + (dim_coord * h[dim]);
111
112
4/4
✓ Branch 0 taken 3460400 times.
✓ Branch 1 taken 65672 times.
✓ Branch 2 taken 3394728 times.
✓ Branch 3 taken 65672 times.
3526072 if (dim_coord > 0 && dim_coord < in.n[dim]) {
113 3394728 weight *= 2;
114 }
115 }
116
117 1240440 sum += integral_function(current_point) * weight;
118 }
119
120 double h_mult = 1.0;
121
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 40 times.
112 for (int i = 0; i < dimensions; i++) {
122 72 h_mult *= h[i];
123 }
124
125
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 GetOutput() = sum * (h_mult / std::pow(2.0, dimensions)); // h1 * h2 * ... * hn / 2^n
126
127 40 return true;
128 }
129
130 40 bool SamoylenkoIIntegralTrapezoidSEQ::PostProcessingImpl() {
131 40 return true;
132 }
133
134 } // namespace samoylenko_i_integral_trapezoid
135