GCC Code Coverage Report


Directory: ./
File: tasks/afanasyev_a_integ_rect_method/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 29 29 100.0%
Functions: 6 6 100.0%
Branches: 17 22 77.3%

Line Branch Exec Source
1 #include "afanasyev_a_integ_rect_method/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <vector>
5
6 #include "afanasyev_a_integ_rect_method/common/include/common.hpp"
7
8 namespace afanasyev_a_integ_rect_method {
9 namespace {
10
11 4320000 double ExampleIntegrand(const std::vector<double> &x) {
12 double s = 0.0;
13
2/2
✓ Branch 0 taken 12960000 times.
✓ Branch 1 taken 4320000 times.
17280000 for (double xi : x) {
14 12960000 s += xi * xi;
15 }
16 4320000 return std::exp(-s);
17 }
18
19 } // namespace
20
21 24 AfanasyevAIntegRectMethodSEQ::AfanasyevAIntegRectMethodSEQ(const InType &in) {
22 SetTypeOfTask(GetStaticTypeOfTask());
23 24 GetInput() = in;
24 GetOutput() = 0.0;
25 24 }
26
27 24 bool AfanasyevAIntegRectMethodSEQ::ValidationImpl() {
28 24 return (GetInput() > 0);
29 }
30
31 24 bool AfanasyevAIntegRectMethodSEQ::PreProcessingImpl() {
32 24 return true;
33 }
34
35 24 bool AfanasyevAIntegRectMethodSEQ::RunImpl() {
36 24 const int n = GetInput();
37
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (n <= 0) {
38 return false;
39 }
40
41 const int k_dim = 3;
42
43 24 const double h = 1.0 / static_cast<double>(n);
44
45 24 std::vector<int> idx(k_dim, 0);
46
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 std::vector<double> x(k_dim, 0.0);
47
48 double sum = 0.0;
49
50 bool done = false;
51
2/2
✓ Branch 0 taken 4320000 times.
✓ Branch 1 taken 24 times.
4320024 while (!done) {
52
2/2
✓ Branch 0 taken 12960000 times.
✓ Branch 1 taken 4320000 times.
17280000 for (int dim = 0; dim < k_dim; ++dim) {
53 12960000 x[dim] = (static_cast<double>(idx[dim]) + 0.5) * h;
54 }
55
56 4320000 sum += ExampleIntegrand(x);
57
58
2/2
✓ Branch 0 taken 4380160 times.
✓ Branch 1 taken 24 times.
4380184 for (int dim = 0; dim < k_dim; ++dim) {
59
2/2
✓ Branch 0 taken 60184 times.
✓ Branch 1 taken 4319976 times.
4380160 idx[dim]++;
60
2/2
✓ Branch 0 taken 60184 times.
✓ Branch 1 taken 4319976 times.
4380160 if (idx[dim] < n) {
61 break;
62 }
63 60184 idx[dim] = 0;
64
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 60160 times.
60184 if (dim == k_dim - 1) {
65 done = true;
66 }
67 }
68 }
69
70 const double volume = std::pow(h, k_dim);
71
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 GetOutput() = sum * volume;
72
73 return true;
74 }
75
76 24 bool AfanasyevAIntegRectMethodSEQ::PostProcessingImpl() {
77 24 return true;
78 }
79
80 } // namespace afanasyev_a_integ_rect_method
81