GCC Code Coverage Report


Directory: ./
File: tasks/kiselev_i_trapezoidal_method_for_multidimensional_integrals/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 51 51 100.0%
Functions: 7 7 100.0%
Branches: 33 37 89.2%

Line Branch Exec Source
1 #include "kiselev_i_trapezoidal_method_for_multidimensional_integrals/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <vector>
5
6 #include "kiselev_i_trapezoidal_method_for_multidimensional_integrals/common/include/common.hpp"
7
8 namespace kiselev_i_trapezoidal_method_for_multidimensional_integrals {
9
10
1/2
✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
160 KiselevITestTaskSEQ::KiselevITestTaskSEQ(const InType &in) {
11 SetTypeOfTask(GetStaticTypeOfTask());
12
1/2
✓ Branch 1 taken 160 times.
✗ Branch 2 not taken.
160 GetInput() = in;
13 160 GetOutput() = 0;
14 160 }
15
16 160 bool KiselevITestTaskSEQ::ValidationImpl() {
17 160 return true;
18 }
19
20 160 bool KiselevITestTaskSEQ::PreProcessingImpl() {
21 160 GetOutput() = 0.0;
22 160 return true;
23 }
24
25 25371144 double KiselevITestTaskSEQ::FunctionTypeChoose(int type_x, double x, double y) {
26
5/5
✓ Branch 0 taken 6643280 times.
✓ Branch 1 taken 1609616 times.
✓ Branch 2 taken 9563256 times.
✓ Branch 3 taken 3223728 times.
✓ Branch 4 taken 4331264 times.
25371144 switch (type_x) {
27 6643280 case 0:
28 6643280 return (x * x) + (y * y);
29 1609616 case 1:
30 1609616 return std::sin(x) * std::cos(y);
31 9563256 case 2:
32 9563256 return std::sin(x) + std::cos(y);
33 3223728 case 3:
34 3223728 return std::exp(x + y);
35 4331264 default:
36 4331264 return x + y;
37 }
38 }
39
40 264 double KiselevITestTaskSEQ::ComputeIntegral(const std::vector<int> &steps) {
41 double result = 0.0;
42
43 264 double hx = (GetInput().right_bounds[0] - GetInput().left_bounds[0]) / steps[0];
44 264 double hy = (GetInput().right_bounds[1] - GetInput().left_bounds[1]) / steps[1];
45
46
2/2
✓ Branch 0 taken 73704 times.
✓ Branch 1 taken 264 times.
73968 for (int i = 0; i <= steps[0]; i++) {
47 73704 double x = GetInput().left_bounds[0] + (i * hx);
48
4/4
✓ Branch 0 taken 73440 times.
✓ Branch 1 taken 264 times.
✓ Branch 2 taken 264 times.
✓ Branch 3 taken 73176 times.
73704 double wx = (i == 0 || i == steps[0]) ? 0.5 : 1.0;
49
50
2/2
✓ Branch 0 taken 25371144 times.
✓ Branch 1 taken 73704 times.
25444848 for (int j = 0; j <= steps[1]; j++) {
51 25371144 double y = GetInput().left_bounds[1] + (j * hy);
52
4/4
✓ Branch 0 taken 25297440 times.
✓ Branch 1 taken 73704 times.
✓ Branch 2 taken 73704 times.
✓ Branch 3 taken 25223736 times.
25371144 double wy = (j == 0 || j == steps[1]) ? 0.5 : 1.0;
53
54 25371144 result += wx * wy * FunctionTypeChoose(GetInput().type_function, x, y);
55 }
56 }
57
58 264 return result * hx * hy;
59 }
60
61 160 bool KiselevITestTaskSEQ::RunImpl() {
62 160 std::vector<int> steps = GetInput().step_n_size;
63
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 8 times.
160 double epsilon = GetInput().epsilon;
64
65 const auto &in = GetInput();
66
6/6
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 144 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 136 times.
160 if (in.left_bounds.size() != 2 || in.right_bounds.size() != 2 || in.step_n_size.size() != 2) {
67 24 GetOutput() = 0.0;
68 24 return true;
69 }
70
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 128 times.
136 if (epsilon <= 0.0) {
71 8 GetOutput() = ComputeIntegral(steps);
72 8 return true;
73 }
74
75 128 double prev = ComputeIntegral(steps);
76 double current = prev;
77
78 int iter = 0;
79 const int max_iter = 1; // for time_limit
80
81
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 while (iter < max_iter) {
82
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 128 times.
384 for (auto &s : steps) {
83 256 s *= 2;
84 }
85
86 128 current = ComputeIntegral(steps);
87
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 128 times.
128 if (std::abs(current - prev) < epsilon) {
89 break;
90 }
91
92 prev = current;
93 iter++;
94 }
95
96 128 GetOutput() = current;
97 128 return true;
98 }
99
100 160 bool KiselevITestTaskSEQ::PostProcessingImpl() {
101 160 return true;
102 }
103
104 } // namespace kiselev_i_trapezoidal_method_for_multidimensional_integrals
105