GCC Code Coverage Report


Directory: ./
File: tasks/gutyansky_a_monte_carlo_multi_dimension/common/include/integration_task.hpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 14 15 93.3%
Functions: 2 2 100.0%
Branches: 15 28 53.6%

Line Branch Exec Source
1 #pragma once
2
3 #include <cmath>
4 #include <cstddef>
5 #include <stdexcept>
6 #include <vector>
7
8 #include "gutyansky_a_monte_carlo_multi_dimension/common/include/function_registry.hpp"
9
10 namespace gutyansky_a_monte_carlo_multi_dimension {
11
12 80 struct IntegrationTask {
13 size_t func_id = 0;
14 size_t n_dims = 0;
15 std::vector<double> lower_bounds;
16 std::vector<double> upper_bounds;
17 size_t n_points = 0;
18
19 72 [[nodiscard]] bool IsValid() const {
20
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if (n_dims == 0) {
21 return false;
22 }
23
24
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if (n_points == 0) {
25 return false;
26 }
27
28
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 72 times.
72 if (lower_bounds.size() != n_dims || upper_bounds.size() != n_dims) {
29 return false;
30 }
31
32
2/2
✓ Branch 0 taken 207 times.
✓ Branch 1 taken 72 times.
279 for (size_t i = 0; i < n_dims; i++) {
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 207 times.
207 if (lower_bounds[i] >= upper_bounds[i]) {
34 return false;
35 }
36 }
37
38
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 auto func = FunctionRegistry::GetIntegralFunction(func_id);
39
40
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if (!func.has_value()) {
41 return false;
42 }
43
44 const auto &descr = func.value();
45
46
3/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
72 return descr.n_dims == 0 || descr.n_dims == n_dims;
47 }
48
49 80 [[nodiscard]] FunctionRegistry::IntegralFunction GetFunction() const {
50
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 auto func = FunctionRegistry::GetIntegralFunction(func_id);
51
52
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 if (func.has_value()) {
53
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
160 return func->func;
54 }
55
56 throw std::runtime_error("Invalid func_id.");
57 }
58
59 friend bool operator==(const IntegrationTask &t_left, const IntegrationTask &t_right) {
60 return t_left.n_dims == t_right.n_dims && t_left.func_id == t_right.func_id &&
61 t_left.lower_bounds == t_right.lower_bounds && t_left.upper_bounds == t_right.upper_bounds &&
62 t_left.n_points == t_right.n_points;
63 }
64 };
65
66 } // namespace gutyansky_a_monte_carlo_multi_dimension
67