GCC Code Coverage Report


Directory: ./
File: tasks/ashihmin_d_calculate_integrals_by_simpson/seq/src/ops_seq.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 44 48 91.7%
Functions: 6 7 85.7%
Branches: 34 50 68.0%

Line Branch Exec Source
1 #include "ashihmin_d_calculate_integrals_by_simpson/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <vector>
6
7 #include "ashihmin_d_calculate_integrals_by_simpson/common/include/common.hpp"
8
9 namespace ashihmin_d_calculate_integrals_by_simpson {
10
11 namespace {
12
13 double Function(const std::vector<double> &coordinates) {
14 double total = 0.0;
15
2/4
✓ Branch 0 taken 5808 times.
✓ Branch 1 taken 2904 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8712 for (double value : coordinates) {
16 5808 total += value * value;
17 }
18 return total;
19 }
20
21 double CalculateWeightCoefficient(const std::vector<int> &indices, int partitions) {
22 double weight_coefficient = 1.0;
23
2/2
✓ Branch 0 taken 5808 times.
✓ Branch 1 taken 2904 times.
8712 for (int node_index : indices) {
24
2/2
✓ Branch 0 taken 4752 times.
✓ Branch 1 taken 1056 times.
5808 if (node_index == 0 || node_index == partitions) {
25 weight_coefficient *= 1.0;
26
2/2
✓ Branch 0 taken 2112 times.
✓ Branch 1 taken 2640 times.
4752 } else if (node_index % 2 == 0) {
27 2112 weight_coefficient *= 2.0;
28 } else {
29 2640 weight_coefficient *= 4.0;
30 }
31 }
32 return weight_coefficient;
33 }
34
35 2904 std::vector<double> CalculatePoint(const std::vector<int> &indices, const std::vector<double> &step_sizes,
36 const std::vector<double> &left_bounds) {
37 2904 std::vector<double> point(indices.size());
38
2/2
✓ Branch 0 taken 5808 times.
✓ Branch 1 taken 2904 times.
8712 for (std::size_t dim = 0; dim < indices.size(); ++dim) {
39 5808 point[dim] = left_bounds[dim] + (indices[dim] * step_sizes[dim]);
40 }
41 2904 return point;
42 }
43
44 } // namespace
45
46
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 AshihminDCalculateIntegralsBySimpsonSEQ::AshihminDCalculateIntegralsBySimpsonSEQ(const InType &input) {
47 SetTypeOfTask(GetStaticTypeOfTask());
48 GetInput() = input;
49 24 GetOutput() = 0.0;
50 24 }
51
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 bool AshihminDCalculateIntegralsBySimpsonSEQ::ValidationImpl() {
53 const auto &input = GetInput();
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (input.left_bounds.size() != input.right_bounds.size()) {
55 return false;
56 }
57
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
24 if (input.partitions <= 0 || input.partitions % 2 != 0) {
58 return false;
59 }
60
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (std::size_t index = 0; index < input.left_bounds.size(); ++index) {
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (input.right_bounds[index] <= input.left_bounds[index]) {
62 return false;
63 }
64 }
65 return true;
66 }
67
68 24 bool AshihminDCalculateIntegralsBySimpsonSEQ::PreProcessingImpl() {
69 24 GetOutput() = 0.0;
70 24 return true;
71 }
72
73 double AshihminDCalculateIntegralsBySimpsonSEQ::IntegrandFunction(const std::vector<double> &coordinates) {
74 return Function(coordinates);
75 }
76
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 bool AshihminDCalculateIntegralsBySimpsonSEQ::RunImpl() {
78 const auto &input = GetInput();
79 24 const int dimensions = static_cast<int>(input.left_bounds.size());
80 24 const int partitions = input.partitions;
81
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (dimensions == 0) {
83 GetOutput() = 0.0;
84 return true;
85 }
86
87 24 std::vector<double> step_sizes(static_cast<std::size_t>(dimensions));
88
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (int dim = 0; dim < dimensions; ++dim) {
89 48 step_sizes[static_cast<std::size_t>(dim)] = (input.right_bounds[dim] - input.left_bounds[dim]) / partitions;
90 }
91
92
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 std::vector<int> indices(static_cast<std::size_t>(dimensions), 0);
93 int total_points = 1;
94
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (int dim = 0; dim < dimensions; ++dim) {
95 48 total_points *= (partitions + 1);
96 }
97
98 double total_sum = 0.0;
99
2/2
✓ Branch 0 taken 2904 times.
✓ Branch 1 taken 24 times.
2928 for (int point_idx = 0; point_idx < total_points; ++point_idx) {
100 int temp = point_idx;
101
2/2
✓ Branch 0 taken 5808 times.
✓ Branch 1 taken 2904 times.
8712 for (int dim = 0; dim < dimensions; ++dim) {
102 5808 indices[static_cast<std::size_t>(dim)] = temp % (partitions + 1);
103 5808 temp /= (partitions + 1);
104 }
105
106 const double weight = CalculateWeightCoefficient(indices, partitions);
107
1/2
✓ Branch 1 taken 2904 times.
✗ Branch 2 not taken.
2904 const auto point = CalculatePoint(indices, step_sizes, input.left_bounds);
108
1/2
✓ Branch 0 taken 2904 times.
✗ Branch 1 not taken.
2904 total_sum += weight * Function(point);
109 }
110
111 double volume_element = 1.0;
112
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
72 for (double step : step_sizes) {
113 48 volume_element *= step;
114 }
115
116
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 GetOutput() = total_sum * volume_element / std::pow(3.0, dimensions);
117 return true;
118 }
119
120 24 bool AshihminDCalculateIntegralsBySimpsonSEQ::PostProcessingImpl() {
121 24 return true;
122 }
123
124 } // namespace ashihmin_d_calculate_integrals_by_simpson
125