GCC Code Coverage Report


Directory: ./
File: tasks/savva_d_monte_carlo/common/include/common.hpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 8 10 80.0%
Functions: 1 1 100.0%
Branches: 6 14 42.9%

Line Branch Exec Source
1 #pragma once
2
3 #include <cstddef>
4 #include <cstdint> // для uint64_t
5 #include <functional> // для std::function
6 #include <stdexcept> // для std::invalid_argument
7 #include <string>
8 #include <tuple>
9 #include <utility> // для std::move
10 #include <vector> // для std::vector
11
12 #include "task/include/task.hpp"
13
14 namespace savva_d_monte_carlo {
15
16 struct InputData {
17 std::vector<double> lower_bounds;
18 std::vector<double> upper_bounds;
19 uint64_t count_points = 0; // Количество точек для выборки
20 std::function<double(const std::vector<double> &)> f; // Функция от вектора
21
22 InputData() = default;
23
24 // Конструктор для проверки совпадения размерностей
25 306 InputData(std::vector<double> lowers, std::vector<double> uppers, uint64_t n,
26 std::function<double(const std::vector<double> &)> func)
27
1/2
✓ Branch 0 taken 306 times.
✗ Branch 1 not taken.
306 : lower_bounds(std::move(lowers)), upper_bounds(std::move(uppers)), count_points(n), f(std::move(func)) {
28 // Проверяем, что размерности совпадают
29
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 306 times.
306 if (lower_bounds.size() != upper_bounds.size()) {
30 throw std::invalid_argument("Lower and upper bounds must have the same dimension");
31 }
32
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 306 times.
306 if (n == 0) {
33 throw std::invalid_argument("Number of points must be positive");
34 }
35 306 }
36
37 // Возвращает размерность задачи
38 [[nodiscard]] size_t Dimension() const {
39 return lower_bounds.size();
40 }
41
42 // Вычисляет объем области интегрирования
43 [[nodiscard]] double Volume() const {
44
1/2
✓ Branch 0 taken 577 times.
✗ Branch 1 not taken.
577 if (lower_bounds.empty()) {
45 return 0.0;
46 }
47
48 double vol = 1.0;
49
2/2
✓ Branch 0 taken 1434 times.
✓ Branch 1 taken 577 times.
2011 for (size_t i = 0; i < lower_bounds.size(); ++i) {
50 1434 vol *= (upper_bounds[i] - lower_bounds[i]);
51 }
52 return vol;
53 }
54 };
55
56 using InType = InputData;
57 using OutType = double;
58 using TestType = std::tuple<int, std::string>;
59 using BaseTask = ppc::task::Task<InType, OutType>;
60
61 } // namespace savva_d_monte_carlo
62