GCC Code Coverage Report


Directory: ./
File: tasks/kiselev_i_trapezoidal_method_for_multidimensional_integrals/seq/src/ops_seq.cpp
Date: 2026-05-11 08:26:31
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 144 times.
✗ Branch 2 not taken.
144 KiselevITestTaskSEQ::KiselevITestTaskSEQ(const InType &in) {
11 SetTypeOfTask(GetStaticTypeOfTask());
12
1/2
✓ Branch 1 taken 144 times.
✗ Branch 2 not taken.
144 GetInput() = in;
13 144 GetOutput() = 0;
14 144 }
15
16 144 bool KiselevITestTaskSEQ::ValidationImpl() {
17 144 return true;
18 }
19
20 144 bool KiselevITestTaskSEQ::PreProcessingImpl() {
21 144 GetOutput() = 0.0;
22 144 return true;
23 }
24
25 18142312 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 2334424 times.
✓ Branch 3 taken 3223728 times.
✓ Branch 4 taken 4331264 times.
18142312 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 2334424 case 2:
32 2334424 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 232 double KiselevITestTaskSEQ::ComputeIntegral(const std::vector<int> &steps) {
41 double result = 0.0;
42
43 232 double hx = (GetInput().right_bounds[0] - GetInput().left_bounds[0]) / steps[0];
44 232 double hy = (GetInput().right_bounds[1] - GetInput().left_bounds[1]) / steps[1];
45
46
2/2
✓ Branch 0 taken 59272 times.
✓ Branch 1 taken 232 times.
59504 for (int i = 0; i <= steps[0]; i++) {
47 59272 double x = GetInput().left_bounds[0] + (i * hx);
48
4/4
✓ Branch 0 taken 59040 times.
✓ Branch 1 taken 232 times.
✓ Branch 2 taken 232 times.
✓ Branch 3 taken 58808 times.
59272 double wx = (i == 0 || i == steps[0]) ? 0.5 : 1.0;
49
50
2/2
✓ Branch 0 taken 18142312 times.
✓ Branch 1 taken 59272 times.
18201584 for (int j = 0; j <= steps[1]; j++) {
51 18142312 double y = GetInput().left_bounds[1] + (j * hy);
52
4/4
✓ Branch 0 taken 18083040 times.
✓ Branch 1 taken 59272 times.
✓ Branch 2 taken 59272 times.
✓ Branch 3 taken 18023768 times.
18142312 double wy = (j == 0 || j == steps[1]) ? 0.5 : 1.0;
53
54 18142312 result += wx * wy * FunctionTypeChoose(GetInput().type_function, x, y);
55 }
56 }
57
58 232 return result * hx * hy;
59 }
60
61 144 bool KiselevITestTaskSEQ::RunImpl() {
62 144 std::vector<int> steps = GetInput().step_n_size;
63
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 8 times.
144 double epsilon = GetInput().epsilon;
64
65 const auto &in = GetInput();
66
6/6
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 128 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 5 taken 120 times.
144 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 112 times.
120 if (epsilon <= 0.0) {
71 8 GetOutput() = ComputeIntegral(steps);
72 8 return true;
73 }
74
75 112 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 112 times.
✗ Branch 1 not taken.
112 while (iter < max_iter) {
82
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 112 times.
336 for (auto &s : steps) {
83 224 s *= 2;
84 }
85
86 112 current = ComputeIntegral(steps);
87
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (std::abs(current - prev) < epsilon) {
89 break;
90 }
91
92 prev = current;
93 iter++;
94 }
95
96 112 GetOutput() = current;
97 112 return true;
98 }
99
100 144 bool KiselevITestTaskSEQ::PostProcessingImpl() {
101 144 return true;
102 }
103
104 } // namespace kiselev_i_trapezoidal_method_for_multidimensional_integrals
105