GCC Code Coverage Report


Directory: ./
File: tasks/kosolapov_v_calc_mult_integrals_m_simpson/seq/src/ops_seq.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 50 57 87.7%
Functions: 8 13 61.5%
Branches: 23 32 71.9%

Line Branch Exec Source
1 #include "kosolapov_v_calc_mult_integrals_m_simpson/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <tuple>
5
6 #include "kosolapov_v_calc_mult_integrals_m_simpson/common/include/common.hpp"
7
8 namespace kosolapov_v_calc_mult_integrals_m_simpson {
9
10 64 KosolapovVCalcMultIntegralsMSimpsonSEQ::KosolapovVCalcMultIntegralsMSimpsonSEQ(const InType &in) {
11 SetTypeOfTask(GetStaticTypeOfTask());
12 64 GetInput() = InType(in);
13 GetOutput() = 0.0;
14 64 }
15
16 64 bool KosolapovVCalcMultIntegralsMSimpsonSEQ::ValidationImpl() {
17 64 int steps = std::get<0>(GetInput());
18 64 int func_id = std::get<1>(GetInput());
19
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 return steps > 0 && (steps % 2 == 0) && func_id >= 1 && func_id <= 4;
20 }
21
22 64 bool KosolapovVCalcMultIntegralsMSimpsonSEQ::PreProcessingImpl() {
23 64 return true;
24 }
25
26 64 bool KosolapovVCalcMultIntegralsMSimpsonSEQ::RunImpl() {
27 64 int steps = std::get<0>(GetInput());
28 64 int func_id = std::get<1>(GetInput());
29 64 std::tuple<double, double, double, double> temp = GetBounds(func_id);
30 64 double a = std::get<0>(temp);
31 64 double b = std::get<1>(temp);
32 64 double c = std::get<2>(temp);
33 64 double d = std::get<3>(temp);
34 64 double integral = SimpsonIntegral(func_id, steps, a, b, c, d);
35 64 GetOutput() = integral;
36 64 return true;
37 }
38
39 64 bool KosolapovVCalcMultIntegralsMSimpsonSEQ::PostProcessingImpl() {
40 64 return true;
41 }
42
43 double KosolapovVCalcMultIntegralsMSimpsonSEQ::Function1(double x, double y) {
44 // f(x,y) = x^2 + y^2
45 16976 return (x * x) + (y * y);
46 }
47 double KosolapovVCalcMultIntegralsMSimpsonSEQ::Function2(double x, double y) {
48 // f(x,y) = sin(x) * cos(y)
49 16976 return std::sin(x) * std::cos(y);
50 }
51 double KosolapovVCalcMultIntegralsMSimpsonSEQ::Function3(double x, double y) {
52 // f(x,y) = exp(-(x^2 + y^2))
53 16976 return std::exp(-((x * x) + (y * y)));
54 }
55 double KosolapovVCalcMultIntegralsMSimpsonSEQ::Function4(double x, double y) {
56 // f(x,y) = sin(x + y)
57 16976 return std::sin(x + y);
58 }
59 67904 double KosolapovVCalcMultIntegralsMSimpsonSEQ::CallFunction(int func_id, double x, double y) {
60
4/5
✓ Branch 0 taken 16976 times.
✓ Branch 1 taken 16976 times.
✓ Branch 2 taken 16976 times.
✓ Branch 3 taken 16976 times.
✗ Branch 4 not taken.
67904 switch (func_id) {
61 case 1:
62 16976 return Function1(x, y);
63 case 2:
64 16976 return Function2(x, y);
65 case 3:
66 16976 return Function3(x, y);
67 case 4:
68 16976 return Function4(x, y);
69 default:
70 return Function1(x, y);
71 }
72 }
73 64 std::tuple<double, double, double, double> KosolapovVCalcMultIntegralsMSimpsonSEQ::GetBounds(int func_id) {
74
4/5
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
64 switch (func_id) {
75 16 case 1:
76 return {0.0, 1.0, 0.0, 1.0};
77 16 case 2:
78 return {0.0, kPi, 0.0, kPi / 2.0};
79 16 case 3:
80 return {-1.0, 1.0, -1.0, 1.0};
81 16 case 4:
82 return {0.0, kPi, 0.0, kPi};
83 default:
84 return {0.0, 1.0, 0.0, 1.0};
85 }
86 }
87 64 double KosolapovVCalcMultIntegralsMSimpsonSEQ::SimpsonIntegral(int func_id, int steps, double a, double b, double c,
88 double d) {
89 64 double hx = (b - a) / steps;
90 64 double hy = (d - c) / steps;
91 double result = 0.0;
92
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 64 times.
2048 for (int i = 0; i <= steps; i++) {
93 1984 double x = a + (i * hx);
94 double wx = GetSimpsonWeight(i, steps);
95
2/2
✓ Branch 0 taken 67904 times.
✓ Branch 1 taken 1984 times.
69888 for (int j = 0; j <= steps; j++) {
96 67904 double y = c + (j * hy);
97 double wy = GetSimpsonWeight(j, steps);
98 67904 result += (wx * wy) * CallFunction(func_id, x, y);
99 }
100 }
101 64 result *= (hx * hy) / 9.0;
102 64 return result;
103 }
104 double KosolapovVCalcMultIntegralsMSimpsonSEQ::GetSimpsonWeight(int index, int steps) {
105
4/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1856 times.
✓ Branch 3 taken 128 times.
✓ Branch 4 taken 63936 times.
✓ Branch 5 taken 3968 times.
69888 if (index == 0 || index == steps) {
106 return 1.0;
107 }
108
4/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 960 times.
✓ Branch 3 taken 896 times.
✓ Branch 4 taken 32960 times.
✓ Branch 5 taken 30976 times.
65792 return (index % 2 == 0) ? 2.0 : 4.0;
109 }
110
111 } // namespace kosolapov_v_calc_mult_integrals_m_simpson
112