GCC Code Coverage Report


Directory: ./
File: tasks/alekseev_a_global_opt_chars/common/include/common.hpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 1 1 100.0%
Branches: 12 19 63.2%

Line Branch Exec Source
1 #pragma once
2
3 #include <cmath>
4 #include <functional>
5 #include <string>
6 #include <tuple>
7
8 #include "task/include/task.hpp"
9
10 namespace alekseev_a_global_opt_chars {
11
12
3/5
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 60 times.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
180 struct OptInput {
13 std::function<double(double, double)> func;
14
15 double x_min{0.0};
16 double x_max{1.0};
17 double y_min{0.0};
18 double y_max{1.0};
19
20 double epsilon{0.01};
21 double r_param{2.0};
22 int max_iterations{1000};
23
24
1/2
✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
120 OptInput() : func(nullptr) {}
25 };
26
27 struct OptResult {
28 double x_opt{0.0};
29 double y_opt{0.0};
30 double func_min{0.0};
31 int iterations{0};
32 bool converged{false};
33
34 OptResult() = default;
35
36 bool operator==(const OptResult &other) const {
37 constexpr double kTol = 1e-3;
38 return std::abs(x_opt - other.x_opt) < kTol && std::abs(y_opt - other.y_opt) < kTol &&
39 std::abs(func_min - other.func_min) < kTol;
40 }
41 };
42
43 struct TrialPoint {
44 double x{0.0};
45 double y{0.0};
46 double z{0.0};
47
48 TrialPoint() = default;
49 696 TrialPoint(double px, double py, double pz) : x(px), y(py), z(pz) {}
50
51 bool operator<(const TrialPoint &other) const {
52 if (x != other.x) {
53 return x < other.x;
54 }
55 return y < other.y;
56 }
57 };
58
59 struct Interval {
60 int left_idx{0};
61 int right_idx{0};
62 double characteristic{0.0};
63
64 Interval() = default;
65 Interval(int l, int r, double c) : left_idx(l), right_idx(r), characteristic(c) {}
66 };
67
68 using InType = OptInput;
69 using OutType = OptResult;
70 using TestType = std::tuple<int, std::string>;
71 using BaseTask = ppc::task::Task<InType, OutType>;
72
73 inline double PeanoToX(double t, double x_min, double x_max, double y_min, double y_max, int level);
74
75 inline double PeanoToY(double t, double x_min, double x_max, double y_min, double y_max, int level);
76
77 namespace detail {
78
79 2520 inline void PeanoMapUnitSquare(double t, int level, double &x, double &y) {
80 2520 x = 0.0;
81 2520 y = 0.0;
82
83 double scale = 0.5;
84
85
2/2
✓ Branch 0 taken 25200 times.
✓ Branch 1 taken 2520 times.
27720 for (int i = 0; i < level; ++i) {
86 25200 int quadrant = static_cast<int>(t * 4.0);
87 25200 t = (t * 4.0) - quadrant;
88
89 double dx = 0.0;
90 double dy = 0.0;
91
92
2/2
✓ Branch 0 taken 17496 times.
✓ Branch 1 taken 7704 times.
25200 switch (quadrant) {
93 case 0:
94 dx = 0.0;
95 dy = 0.0;
96 break;
97 case 1:
98 dx = 0.0;
99 dy = 1.0;
100 break;
101 case 2:
102 dx = 1.0;
103 dy = 1.0;
104 break;
105 case 3:
106 dx = 1.0;
107 dy = 0.0;
108 break;
109 default:
110 dx = 0.0;
111 dy = 0.0;
112 break;
113 }
114
115 25200 x += dx * scale;
116 25200 y += dy * scale;
117 25200 scale *= 0.5;
118 }
119 2520 }
120
121 } // namespace detail
122
123 inline double PeanoToX(double t, double x_min, double x_max, int level) {
124 1260 double ux = 0.0;
125 1260 double uy = 0.0;
126 1260 detail::PeanoMapUnitSquare(t, level, ux, uy);
127 1260 return x_min + (ux * (x_max - x_min));
128 }
129
130 inline double PeanoToY(double t, double y_min, double y_max, int level) {
131 1260 double ux = 0.0;
132 1260 double uy = 0.0;
133 1260 detail::PeanoMapUnitSquare(t, level, ux, uy);
134
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 576 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 518 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 54 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 112 times.
1260 return y_min + (uy * (y_max - y_min));
135 }
136
137 } // namespace alekseev_a_global_opt_chars
138