GCC Code Coverage Report


Directory: ./
File: tasks/tsibareva_e_integral_calculate_trapezoid_method/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 40 41 97.6%
Functions: 6 7 85.7%
Branches: 28 40 70.0%

Line Branch Exec Source
1 #include "tsibareva_e_integral_calculate_trapezoid_method/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <vector>
5
6 #include "task/include/task.hpp"
7 #include "tsibareva_e_integral_calculate_trapezoid_method/common/include/common.hpp"
8
9 namespace tsibareva_e_integral_calculate_trapezoid_method {
10
11 56 TsibarevaEIntegralCalculateTrapezoidMethodSEQ::TsibarevaEIntegralCalculateTrapezoidMethodSEQ(const Integral &in)
12
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 : ppc::task::Task<Integral, double>() {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 GetInput() = in;
15 56 GetOutput() = 0.0;
16 56 }
17
18 56 bool TsibarevaEIntegralCalculateTrapezoidMethodSEQ::ValidationImpl() {
19 56 return true;
20 }
21
22 56 bool TsibarevaEIntegralCalculateTrapezoidMethodSEQ::PreProcessingImpl() {
23 56 GetOutput() = 0.0;
24 56 return true;
25 }
26
27 1716056 std::vector<double> TsibarevaEIntegralCalculateTrapezoidMethodSEQ::ComputePoint(const std::vector<int> &indexes,
28 const std::vector<double> &h, int dim) {
29 1716056 std::vector<double> point(dim);
30
2/2
✓ Branch 0 taken 5044672 times.
✓ Branch 1 taken 1716056 times.
6760728 for (int i = 0; i < dim; ++i) {
31 5044672 point[i] = GetInput().lo[i] + (indexes[i] * h[i]);
32 }
33 1716056 return point;
34 }
35
36 bool TsibarevaEIntegralCalculateTrapezoidMethodSEQ::IterateGridPoints(std::vector<int> &indexes, int dim) {
37 1716056 int position = dim - 1;
38
2/4
✓ Branch 0 taken 1752352 times.
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1752408 while (position >= 0) {
39
2/4
✓ Branch 0 taken 36352 times.
✓ Branch 1 taken 1716000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1752352 indexes[position]++;
40
2/4
✓ Branch 0 taken 36352 times.
✓ Branch 1 taken 1716000 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1752352 if (indexes[position] <= GetInput().steps[position]) {
41 return true;
42 }
43 36352 indexes[position] = 0;
44 36352 position--;
45 }
46 return false;
47 }
48
49 56 bool TsibarevaEIntegralCalculateTrapezoidMethodSEQ::RunImpl() {
50 56 int dim = GetInput().dim;
51
52 56 std::vector<double> h(dim);
53
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 56 times.
168 for (int i = 0; i < dim; ++i) {
54 112 h[i] = (GetInput().hi[i] - GetInput().lo[i]) / GetInput().steps[i];
55 }
56
57
1/4
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
56 std::vector<int> indexes(dim, 0);
58 double sum = 0.0;
59
60 while (true) {
61
1/2
✓ Branch 1 taken 1716056 times.
✗ Branch 2 not taken.
1716056 std::vector<double> point = ComputePoint(indexes, h, dim);
62
63 int boundary_count = 0;
64
2/2
✓ Branch 0 taken 5044672 times.
✓ Branch 1 taken 1716056 times.
6760728 for (int i = 0; i < dim; ++i) {
65
4/4
✓ Branch 0 taken 4939200 times.
✓ Branch 1 taken 105472 times.
✓ Branch 2 taken 105384 times.
✓ Branch 3 taken 4833816 times.
5044672 if (indexes[i] == 0 || indexes[i] == GetInput().steps[i]) {
66 210856 boundary_count++;
67 }
68 }
69
70
2/2
✓ Branch 0 taken 202040 times.
✓ Branch 1 taken 1514016 times.
1716056 double weight = (boundary_count == 0) ? 1.0 : std::pow(0.5, boundary_count);
71 1716056 sum += weight * GetInput().f(point);
72
73
2/2
✓ Branch 0 taken 1716000 times.
✓ Branch 1 taken 56 times.
1716056 if (!IterateGridPoints(indexes, dim)) {
74 break;
75 }
76 }
77
78 double res_h = 1.0;
79
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 56 times.
168 for (int i = 0; i < dim; ++i) {
80 112 res_h *= h[i];
81 }
82
83
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 8 times.
56 GetOutput() = sum * res_h;
84
85 56 return true;
86 }
87
88 56 bool TsibarevaEIntegralCalculateTrapezoidMethodSEQ::PostProcessingImpl() {
89 56 return true;
90 }
91
92 } // namespace tsibareva_e_integral_calculate_trapezoid_method
93