GCC Code Coverage Report


Directory: ./
File: tasks/eremin_v_integrals_monte_carlo/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 29 29 100.0%
Functions: 5 5 100.0%
Branches: 20 34 58.8%

Line Branch Exec Source
1 #include "eremin_v_integrals_monte_carlo/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <random>
7 #include <vector>
8
9 #include "eremin_v_integrals_monte_carlo/common/include/common.hpp"
10
11 namespace eremin_v_integrals_monte_carlo {
12
13
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 EreminVIntegralsMonteCarloSEQ::EreminVIntegralsMonteCarloSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 GetInput() = in;
16 24 GetOutput() = 0.0;
17 24 }
18
19 24 bool EreminVIntegralsMonteCarloSEQ::ValidationImpl() {
20 const auto &input = GetInput();
21
22
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (input.samples <= 0) {
23 return false;
24 }
25
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (input.bounds.empty()) {
26 return false;
27 }
28
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (input.func == nullptr) {
29 return false;
30 }
31
32 return std::ranges::all_of(input.bounds, [](const auto &p) {
33 const auto &[a, b] = p;
34
3/6
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
48 return (a < b) && (std::abs(a) <= 1e9) && (std::abs(b) <= 1e9);
35 });
36 }
37
38 24 bool EreminVIntegralsMonteCarloSEQ::PreProcessingImpl() {
39 24 GetOutput() = 0.0;
40 24 return true;
41 }
42
43 24 bool EreminVIntegralsMonteCarloSEQ::RunImpl() {
44 const auto &input = GetInput();
45 const auto &bounds = input.bounds;
46 24 int samples = input.samples;
47 const auto &func = input.func;
48
49 const std::size_t dimension = bounds.size();
50
51 double volume = 1.0;
52
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (const auto &[a, b] : bounds) {
53 48 volume *= (b - a);
54 }
55
56 48 std::mt19937 gen(std::random_device{}());
57
58 24 std::vector<std::uniform_real_distribution<double>> distributions;
59
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 distributions.reserve(dimension);
60
61
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (const auto &[a, b] : bounds) {
62
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 distributions.emplace_back(a, b);
63 }
64
65 double sum = 0.0;
66
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 std::vector<double> point(dimension);
67
68
2/2
✓ Branch 0 taken 24000000 times.
✓ Branch 1 taken 24 times.
24000024 for (int i = 0; i < samples; ++i) {
69
2/2
✓ Branch 0 taken 48000000 times.
✓ Branch 1 taken 24000000 times.
72000000 for (std::size_t dim = 0; dim < dimension; ++dim) {
70 48000000 point[dim] = distributions[dim](gen);
71 }
72
73
1/2
✓ Branch 1 taken 24000000 times.
✗ Branch 2 not taken.
24000000 sum += func(point);
74 }
75
76
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 GetOutput() = volume * (sum / static_cast<double>(samples));
77 24 return true;
78 }
79
80 24 bool EreminVIntegralsMonteCarloSEQ::PostProcessingImpl() {
81 24 return true;
82 }
83
84 } // namespace eremin_v_integrals_monte_carlo
85