GCC Code Coverage Report


Directory: ./
File: tasks/chyokotov_a_seidel_method/seq/src/ops_seq.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 42 42 100.0%
Functions: 6 6 100.0%
Branches: 42 50 84.0%

Line Branch Exec Source
1 #include "chyokotov_a_seidel_method/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <climits>
5 #include <cmath>
6 #include <cstddef>
7 #include <vector>
8
9 #include "chyokotov_a_seidel_method/common/include/common.hpp"
10
11 namespace chyokotov_a_seidel_method {
12
13
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 ChyokotovASeidelMethodSEQ::ChyokotovASeidelMethodSEQ(const InType &in) {
14 SetTypeOfTask(GetStaticTypeOfTask());
15 GetInput().first.clear();
16
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 GetInput().first.reserve(in.first.size());
17
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 40 times.
120 for (const auto &row : in.first) {
18
1/2
✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
80 GetInput().first.push_back(row);
19 }
20
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 GetInput().second = in.second;
21 GetOutput().clear();
22 40 }
23
24
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 32 times.
40 bool ChyokotovASeidelMethodSEQ::ValidationImpl() {
25 const auto &matrix = GetInput().first;
26
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 32 times.
40 if (matrix.empty()) {
27 return true;
28 }
29
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 if (GetInput().second.size() != matrix.size()) {
30 return false;
31 }
32
33 size_t n = matrix[0].size();
34
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 32 times.
112 for (const auto &row : matrix) {
35
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 if (row.size() != n) {
36 return false;
37 }
38 }
39
40
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 80 times.
112 for (size_t i = 0; i < n; ++i) {
41 double sum = 0.0;
42
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 80 times.
320 for (size_t j = 0; j < n; j++) {
43
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 80 times.
240 if (i != j) {
44 160 sum += std::abs(matrix[i][j]);
45 }
46 }
47
1/2
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
80 if (std::abs(matrix[i][i]) <= sum) {
48 return false;
49 }
50 }
51
52 return true;
53 }
54
55
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
40 bool ChyokotovASeidelMethodSEQ::PreProcessingImpl() {
56
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
40 if (GetInput().first.empty()) {
57 return true;
58 }
59 32 GetOutput().resize(GetInput().second.size(), 0.0);
60 32 return true;
61 }
62
63 168 bool ChyokotovASeidelMethodSEQ::Convergence() {
64 const auto &matrix = GetInput().first;
65 const auto &vec = GetInput().second;
66 auto &output = GetOutput();
67 168 const int n = static_cast<int>(vec.size());
68
69 168 double max_error = 0.0;
70
2/2
✓ Branch 0 taken 464 times.
✓ Branch 1 taken 168 times.
632 for (int i = 0; i < n; i++) {
71 464 double error = vec[i];
72
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 464 times.
1856 for (int j = 0; j < n; j++) {
73 1392 error -= matrix[i][j] * output[j];
74 }
75 464 max_error = std::max(std::abs(error), max_error);
76 }
77
78 168 return (max_error < 0.000001);
79 }
80
81
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
40 bool ChyokotovASeidelMethodSEQ::RunImpl() {
82 const auto &matrix = GetInput().first;
83
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
40 if (matrix.empty()) {
84 return true;
85 }
86 const auto &vec = GetInput().second;
87 auto &output = GetOutput();
88 32 int n = static_cast<int>(matrix.size());
89
90
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 for (int it = 0; it < 1000; it++) {
91
2/2
✓ Branch 0 taken 464 times.
✓ Branch 1 taken 168 times.
632 for (int i = 0; i < n; i++) {
92 464 double new_x = vec[i];
93
94
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 464 times.
1856 for (int j = 0; j < n; j++) {
95
2/2
✓ Branch 0 taken 928 times.
✓ Branch 1 taken 464 times.
1392 if (i != j) {
96 928 new_x -= matrix[i][j] * output[j];
97 }
98 }
99
100 464 output[i] = new_x / matrix[i][i];
101 }
102
103
2/2
✓ Branch 0 taken 136 times.
✓ Branch 1 taken 32 times.
168 if (Convergence()) {
104 break;
105 }
106 }
107
108 return true;
109 }
110
111 40 bool ChyokotovASeidelMethodSEQ::PostProcessingImpl() {
112 40 return true;
113 }
114
115 } // namespace chyokotov_a_seidel_method
116