GCC Code Coverage Report


Directory: ./
File: tasks/dolov_v_monte_carlo_integration/seq/src/ops_seq.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 32 32 100.0%
Functions: 5 5 100.0%
Branches: 21 32 65.6%

Line Branch Exec Source
1 #include "dolov_v_monte_carlo_integration/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <random>
6 #include <vector>
7
8 #include "dolov_v_monte_carlo_integration/common/include/common.hpp"
9
10 namespace dolov_v_monte_carlo_integration {
11
12
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 DolovVMonteCarloIntegrationSEQ::DolovVMonteCarloIntegrationSEQ(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 GetInput() = in;
15 48 GetOutput() = 0.0;
16 48 }
17
18
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 bool DolovVMonteCarloIntegrationSEQ::ValidationImpl() {
19 const auto &in = GetInput();
20
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
48 return in.func && (in.samples_count > 0) && (in.dimension > 0) &&
21
3/6
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 48 times.
96 (in.center.size() == static_cast<size_t>(in.dimension)) && (in.radius > 0.0);
22 }
23
24 48 bool DolovVMonteCarloIntegrationSEQ::PreProcessingImpl() {
25 48 GetOutput() = 0.0;
26 48 return true;
27 }
28
29 48 bool DolovVMonteCarloIntegrationSEQ::RunImpl() {
30 const auto &in = GetInput();
31 48 const int n_samples = in.samples_count;
32 48 const int dim_count = in.dimension;
33 48 const double radius = in.radius;
34 48 const double r_sq = radius * radius;
35
36 48 std::random_device rd;
37 48 std::mt19937 generator(rd());
38 std::uniform_real_distribution<double> distribution(-radius, radius);
39
40 double sum_val = 0.0;
41
1/2
✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
48 std::vector<double> point(dim_count);
42
43
2/2
✓ Branch 0 taken 4160000 times.
✓ Branch 1 taken 48 times.
4160048 for (int sample = 0; sample < n_samples; ++sample) {
44
2/2
✓ Branch 0 taken 8320000 times.
✓ Branch 1 taken 4160000 times.
12480000 for (int dim_idx = 0; dim_idx < dim_count; ++dim_idx) {
45 8320000 point[dim_idx] = in.center[dim_idx] + distribution(generator);
46 }
47
48 bool is_in_domain = true;
49
2/2
✓ Branch 0 taken 2080000 times.
✓ Branch 1 taken 2080000 times.
4160000 if (in.domain_type == IntegrationDomain::kHyperSphere) {
50 double d_sq = 0.0;
51
2/2
✓ Branch 0 taken 4160000 times.
✓ Branch 1 taken 2080000 times.
6240000 for (int dim_idx = 0; dim_idx < dim_count; ++dim_idx) {
52 4160000 double diff = point[dim_idx] - in.center[dim_idx];
53 4160000 d_sq += diff * diff;
54 }
55 is_in_domain = (d_sq <= r_sq);
56 }
57
58
2/2
✓ Branch 0 taken 1633836 times.
✓ Branch 1 taken 446164 times.
2080000 if (is_in_domain) {
59 3713836 sum_val += in.func(point);
60 }
61 }
62
63
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 const double v_cube = std::pow(2.0 * radius, dim_count);
64
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 GetOutput() = v_cube * (sum_val / n_samples);
65 48 return std::isfinite(GetOutput());
66 }
67
68 48 bool DolovVMonteCarloIntegrationSEQ::PostProcessingImpl() {
69 48 return true;
70 }
71
72 } // namespace dolov_v_monte_carlo_integration
73