GCC Code Coverage Report


Directory: ./
File: tasks/vlasova_a_simpson_method_seq/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 55 56 98.2%
Functions: 7 8 87.5%
Branches: 34 48 70.8%

Line Branch Exec Source
1 #include "vlasova_a_simpson_method_seq/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <functional>
6 #include <utility>
7 #include <vector>
8
9 #include "vlasova_a_simpson_method_seq/common/include/common.hpp"
10
11 namespace vlasova_a_simpson_method_seq {
12
13 64 VlasovaASimpsonMethodSEQ::VlasovaASimpsonMethodSEQ(InType in) : task_data_(std::move(in)) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 64 GetOutput() = 0.0;
16 64 }
17
18
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 bool VlasovaASimpsonMethodSEQ::ValidationImpl() {
19 size_t dim = task_data_.a.size();
20
21
3/6
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 64 times.
64 if (dim == 0 || dim != task_data_.b.size() || dim != task_data_.n.size()) {
22 return false;
23 }
24
25
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 64 times.
184 for (size_t i = 0; i < dim; ++i) {
26
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
120 if (task_data_.a[i] >= task_data_.b[i]) {
27 return false;
28 }
29
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 120 times.
120 if (task_data_.n[i] <= 0 || task_data_.n[i] % 2 != 0) {
30 return false;
31 }
32 }
33
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (!task_data_.func) {
35 return false;
36 }
37
38 64 return GetOutput() == 0.0;
39 }
40
41 64 bool VlasovaASimpsonMethodSEQ::PreProcessingImpl() {
42 64 result_ = 0.0;
43 64 GetOutput() = 0.0;
44
45 size_t dim = task_data_.a.size();
46 64 h_.resize(dim);
47 64 dimensions_.resize(dim);
48
49
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 64 times.
184 for (size_t i = 0; i < dim; ++i) {
50 120 h_[i] = (task_data_.b[i] - task_data_.a[i]) / task_data_.n[i];
51 120 dimensions_[i] = task_data_.n[i] + 1;
52 }
53
54 64 return true;
55 }
56
57 void VlasovaASimpsonMethodSEQ::Nextindex(std::vector<int> &index) {
58 size_t dim = index.size();
59
2/4
✓ Branch 0 taken 16536 times.
✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
16600 for (size_t i = 0; i < dim; ++i) {
60 16536 index[i]++;
61
2/4
✓ Branch 0 taken 1768 times.
✓ Branch 1 taken 14768 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
16536 if (index[i] < dimensions_[i]) {
62 return;
63 }
64 1768 index[i] = 0;
65 }
66 }
67
68 14832 void VlasovaASimpsonMethodSEQ::ComputeWeight(const std::vector<int> &index, double &weight) const {
69 14832 weight = 1.0;
70 size_t dim = index.size();
71
72
2/2
✓ Branch 0 taken 41064 times.
✓ Branch 1 taken 14832 times.
55896 for (size_t i = 0; i < dim; ++i) {
73 41064 int idx = index[i];
74 41064 int steps = task_data_.n[i];
75
76
2/2
✓ Branch 0 taken 32184 times.
✓ Branch 1 taken 8880 times.
41064 if (idx == 0 || idx == steps) {
77 weight *= 1.0;
78
2/2
✓ Branch 0 taken 13872 times.
✓ Branch 1 taken 18312 times.
32184 } else if (idx % 2 == 0) {
79 13872 weight *= 2.0;
80 } else {
81 18312 weight *= 4.0;
82 }
83 }
84 14832 }
85
86 14832 void VlasovaASimpsonMethodSEQ::ComputePoint(const std::vector<int> &index, std::vector<double> &point) const {
87 size_t dim = index.size();
88 14832 point.resize(dim);
89
90
2/2
✓ Branch 0 taken 41064 times.
✓ Branch 1 taken 14832 times.
55896 for (size_t i = 0; i < dim; ++i) {
91 41064 point[i] = task_data_.a[i] + (index[i] * h_[i]);
92 }
93 14832 }
94
95 64 bool VlasovaASimpsonMethodSEQ::RunImpl() {
96 size_t dim = task_data_.a.size();
97
98 64 std::vector<int> cur_index(dim, 0);
99 64 std::vector<double> cur_point;
100 double sum = 0.0;
101 bool has_more = true;
102
103
2/2
✓ Branch 0 taken 14832 times.
✓ Branch 1 taken 64 times.
14896 while (has_more) {
104 14832 double weight = 0.0;
105
106 14832 ComputeWeight(cur_index, weight);
107
1/2
✓ Branch 1 taken 14832 times.
✗ Branch 2 not taken.
14832 ComputePoint(cur_index, cur_point);
108
109 14832 sum += weight * task_data_.func(cur_point);
110 Nextindex(cur_index);
111 has_more = false;
112
2/2
✓ Branch 0 taken 16536 times.
✓ Branch 1 taken 64 times.
16600 for (size_t i = 0; i < dim; ++i) {
113
2/2
✓ Branch 0 taken 1768 times.
✓ Branch 1 taken 14768 times.
16536 if (cur_index[i] != 0) {
114 has_more = true;
115 break;
116 }
117 }
118 }
119
120 // Множитель: (h1 * h2 * ... * hd) / 3^d
121 double factor = 1.0;
122
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 64 times.
184 for (size_t i = 0; i < dim; ++i) {
123 120 factor *= h_[i] / 3.0;
124 }
125
126 64 result_ = sum * factor;
127
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 GetOutput() = result_;
128
129 64 return true;
130 }
131
132 64 bool VlasovaASimpsonMethodSEQ::PostProcessingImpl() {
133 64 return std::isfinite(GetOutput());
134 }
135
136 } // namespace vlasova_a_simpson_method_seq
137