GCC Code Coverage Report


Directory: ./
File: tasks/kosolapov_v_calc_mult_integrals_m_rectangles/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 48 54 88.9%
Functions: 8 12 66.7%
Branches: 14 18 77.8%

Line Branch Exec Source
1 #include "kosolapov_v_calc_mult_integrals_m_rectangles/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <tuple>
5
6 #include "kosolapov_v_calc_mult_integrals_m_rectangles/common/include/common.hpp"
7
8 namespace kosolapov_v_calc_mult_integrals_m_rectangles {
9
10 64 KosolapovVCalcMultIntegralsMRectanglesSEQ::KosolapovVCalcMultIntegralsMRectanglesSEQ(const InType &in) {
11 SetTypeOfTask(GetStaticTypeOfTask());
12 64 GetInput() = InType(in);
13 GetOutput() = 0.0;
14 64 }
15
16 64 bool KosolapovVCalcMultIntegralsMRectanglesSEQ::ValidationImpl() {
17 64 int steps = std::get<0>(GetInput());
18 64 int func_id = std::get<1>(GetInput());
19
2/4
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 64 times.
64 return steps > 0 && func_id >= 1 && func_id <= 4;
20 }
21
22 64 bool KosolapovVCalcMultIntegralsMRectanglesSEQ::PreProcessingImpl() {
23 64 return true;
24 }
25
26 64 bool KosolapovVCalcMultIntegralsMRectanglesSEQ::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 = RectanglesIntegral(func_id, steps, a, b, c, d);
35 64 GetOutput() = integral;
36 64 return true;
37 }
38
39 64 bool KosolapovVCalcMultIntegralsMRectanglesSEQ::PostProcessingImpl() {
40 64 return true;
41 }
42
43 double KosolapovVCalcMultIntegralsMRectanglesSEQ::Function1(double x, double y) {
44 // f(x,y) = x^2 + y^2
45 16000 return (x * x) + (y * y);
46 }
47 double KosolapovVCalcMultIntegralsMRectanglesSEQ::Function2(double x, double y) {
48 // f(x,y) = sin(x) * cos(y)
49 16000 return std::sin(x) * std::cos(y);
50 }
51 double KosolapovVCalcMultIntegralsMRectanglesSEQ::Function3(double x, double y) {
52 // f(x,y) = exp(-(x^2 + y^2))
53 16000 return std::exp(-((x * x) + (y * y)));
54 }
55 double KosolapovVCalcMultIntegralsMRectanglesSEQ::Function4(double x, double y) {
56 // f(x,y) = sin(x + y)
57 16000 return std::sin(x + y);
58 }
59 64000 double KosolapovVCalcMultIntegralsMRectanglesSEQ::CallFunction(int func_id, double x, double y) {
60
4/5
✓ Branch 0 taken 16000 times.
✓ Branch 1 taken 16000 times.
✓ Branch 2 taken 16000 times.
✓ Branch 3 taken 16000 times.
✗ Branch 4 not taken.
64000 switch (func_id) {
61 case 1:
62 16000 return Function1(x, y);
63 case 2:
64 16000 return Function2(x, y);
65 case 3:
66 16000 return Function3(x, y);
67 case 4:
68 16000 return Function4(x, y);
69 default:
70 return Function1(x, y);
71 }
72 }
73 64 std::tuple<double, double, double, double> KosolapovVCalcMultIntegralsMRectanglesSEQ::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 KosolapovVCalcMultIntegralsMRectanglesSEQ::RectanglesIntegral(int func_id, int steps, double a, double b,
88 double c, 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 1920 times.
✓ Branch 1 taken 64 times.
1984 for (int i = 0; i < steps; i++) {
93 1920 double x = a + ((i + 0.5) * hx);
94
2/2
✓ Branch 0 taken 64000 times.
✓ Branch 1 taken 1920 times.
65920 for (int j = 0; j < steps; j++) {
95 64000 double y = c + ((j + 0.5) * hy);
96 64000 result += CallFunction(func_id, x, y);
97 }
98 }
99 64 result *= (hx * hy);
100 64 return result;
101 }
102
103 } // namespace kosolapov_v_calc_mult_integrals_m_rectangles
104