GCC Code Coverage Report


Directory: ./
File: tasks/popova_e_integr_monte_carlo/common/include/common.hpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 2 2 100.0%
Branches: 10 12 83.3%

Line Branch Exec Source
1 #pragma once
2
3 #include <cmath>
4 #include <cstdint>
5 #include <string>
6 #include <tuple>
7
8 #include "task/include/task.hpp"
9
10 namespace popova_e_integr_monte_carlo {
11
12 enum class FuncType : std::uint8_t {
13 kLinearFunc = 0, // 2x + 7
14 kQuadraticFunc = 1, // 5x - 3x^2 + 7
15 kCubicFunc = 2, // x^3 - 4x
16 kCosFunc = 3, // cos(2x)
17 kExpFunc = 4 // 2x * exp(-2x) + 4
18 };
19
20 class FunctionPair {
21 public:
22 1967400 static double Function(FuncType func_id, double x) {
23
5/6
✓ Branch 0 taken 729000 times.
✓ Branch 1 taken 414000 times.
✓ Branch 2 taken 5400 times.
✓ Branch 3 taken 90000 times.
✓ Branch 4 taken 729000 times.
✗ Branch 5 not taken.
1967400 switch (func_id) {
24 729000 case FuncType::kLinearFunc:
25 729000 return ((2.0 * x) + 7.0);
26 414000 case FuncType::kQuadraticFunc:
27 414000 return ((5.0 * x) - (3.0 * x * x) + 7.0);
28 5400 case FuncType::kCubicFunc:
29 5400 return ((x * x * x) - (4.0 * x));
30 90000 case FuncType::kCosFunc:
31 90000 return (std::cos(2.0 * x));
32 729000 case FuncType::kExpFunc:
33 729000 return ((2.0 * x * std::exp(-2.0 * x)) + 4.0);
34 default:
35 return 0.0;
36 }
37 }
38
39 200 static double Integral(FuncType func_id, double x) {
40
5/6
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 40 times.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
200 switch (func_id) {
41 40 case FuncType::kLinearFunc:
42 40 return ((x * x) + (7.0 * x));
43 40 case FuncType::kQuadraticFunc:
44 40 return ((2.5 * x * x) - (x * x * x) + (7.0 * x));
45 40 case FuncType::kCubicFunc:
46 40 return ((0.25 * x * x * x * x) - (2.0 * x * x));
47 40 case FuncType::kCosFunc:
48 40 return (0.5 * std::sin(2.0 * x));
49 40 case FuncType::kExpFunc:
50 40 return ((-(x + 0.5) * std::exp(-2.0 * x)) + (4.0 * x));
51 default:
52 return 0.0;
53 }
54 }
55 };
56
57 using InType = std::tuple<double, double, int, FuncType>;
58 using OutType = double;
59 using TestType = std::tuple<std::tuple<double, double, int, FuncType>, std::string>;
60 using BaseTask = ppc::task::Task<InType, OutType>;
61
62 } // namespace popova_e_integr_monte_carlo
63