GCC Code Coverage Report


Directory: ./
File: tasks/zyazeva_s_gauss_jordan_elimination/seq/src/ops_seq.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 37 37 100.0%
Functions: 7 7 100.0%
Branches: 19 26 73.1%

Line Branch Exec Source
1 #include "zyazeva_s_gauss_jordan_elimination/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cfloat>
5 #include <cmath>
6 #include <cstddef>
7 #include <utility>
8 #include <vector>
9
10 #include "zyazeva_s_gauss_jordan_elimination/common/include/common.hpp"
11
12 namespace zyazeva_s_gauss_jordan_elimination {
13
14
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 ZyazevaSGaussJordanElSEQ::ZyazevaSGaussJordanElSEQ(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 InType temp = in;
17 56 GetInput() = std::move(temp);
18 56 GetOutput() = std::vector<float>();
19 56 }
20
21
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 bool ZyazevaSGaussJordanElSEQ::ValidationImpl() {
22 const auto &matrix = GetInput();
23
24
1/2
✓ Branch 0 taken 56 times.
✗ Branch 1 not taken.
56 if (matrix.empty()) {
25 return false;
26 }
27
28 std::size_t n = matrix.size();
29
30
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 return std::ranges::all_of(matrix, [n](const auto &row) { return row.size() == n + 1; });
31 }
32
33 56 bool ZyazevaSGaussJordanElSEQ::PreProcessingImpl() {
34 56 GetOutput() = std::vector<float>();
35 56 return true;
36 }
37
38 namespace {
39
40 void KNormalizeCurrentRow(std::vector<std::vector<float>> &a, int i, int n) {
41 128 float pivot = a[i][i];
42
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 128 times.
488 for (int k = i; k <= n; k++) {
43 360 a[i][k] /= pivot;
44 }
45 }
46
47 128 void KEliminateColumn(std::vector<std::vector<float>> &a, int i, int n) {
48
2/2
✓ Branch 0 taken 336 times.
✓ Branch 1 taken 128 times.
464 for (int j = 0; j < n; j++) {
49
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 128 times.
336 if (j != i) {
50 208 float factor = a[j][i];
51
2/2
✓ Branch 0 taken 616 times.
✓ Branch 1 taken 208 times.
824 for (int k = i; k <= n; k++) {
52 616 a[j][k] -= factor * a[i][k];
53 }
54 }
55 }
56 128 }
57
58 56 std::vector<float> ExtractSolutions(const std::vector<std::vector<float>> &a, int n) {
59 56 std::vector<float> solutions(n);
60
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 56 times.
184 for (int i = 0; i < n; i++) {
61 128 solutions[i] = a[i][n];
62 }
63 56 return solutions;
64 }
65
66 } // namespace
67
68 56 bool ZyazevaSGaussJordanElSEQ::RunImpl() {
69 56 std::vector<std::vector<float>> a = GetInput();
70 56 int n = static_cast<int>(a.size());
71
72
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 56 times.
184 for (int i = 0; i < n; i++) {
73 KNormalizeCurrentRow(a, i, n);
74 128 KEliminateColumn(a, i, n);
75 }
76
77
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 std::vector<float> solutions = ExtractSolutions(a, n);
78
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 GetOutput() = solutions;
79
80 56 return true;
81 56 }
82
83 56 bool ZyazevaSGaussJordanElSEQ::PostProcessingImpl() {
84 const auto &solutions = GetOutput();
85 56 return !solutions.empty();
86 }
87
88 } // namespace zyazeva_s_gauss_jordan_elimination
89