GCC Code Coverage Report


Directory: ./
File: tasks/krykov_e_simple_iterations/seq/src/ops_seq.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 5 5 100.0%
Branches: 18 28 64.3%

Line Branch Exec Source
1 #include "krykov_e_simple_iterations/seq/include/ops_seq.hpp"
2
3 #include <cctype>
4 #include <cmath>
5 #include <cstddef>
6 #include <ranges>
7 #include <vector>
8
9 #include "krykov_e_simple_iterations/common/include/common.hpp"
10
11 namespace krykov_e_simple_iterations {
12
13 constexpr double kEps = 1e-5;
14 constexpr int kMaxIter = 10000;
15
16
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 KrykovESimpleIterationsSEQ::KrykovESimpleIterationsSEQ(const InType &in) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18 GetInput() = in;
19 40 }
20
21 40 bool KrykovESimpleIterationsSEQ::ValidationImpl() {
22 const auto &[n, A, b] = GetInput();
23
3/6
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
40 return n > 0 && A.size() == n * n && b.size() == n;
24 }
25
26 40 bool KrykovESimpleIterationsSEQ::PreProcessingImpl() {
27 40 return true;
28 }
29
30 40 bool KrykovESimpleIterationsSEQ::RunImpl() {
31 const auto &[n, A, b] = GetInput();
32
33 40 std::vector<double> x(n, 0.0);
34
1/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
40 std::vector<double> x_new(n, 0.0);
35
36
1/2
✓ Branch 0 taken 368 times.
✗ Branch 1 not taken.
368 for (int iter = 0; iter < kMaxIter; ++iter) {
37
2/2
✓ Branch 0 taken 984 times.
✓ Branch 1 taken 368 times.
1352 for (size_t i = 0; i < n; ++i) {
38 double sum = 0.0;
39
2/2
✓ Branch 0 taken 2936 times.
✓ Branch 1 taken 984 times.
3920 for (size_t j = 0; j < n; ++j) {
40
2/2
✓ Branch 0 taken 1952 times.
✓ Branch 1 taken 984 times.
2936 if (j != i) {
41 1952 sum += A[(i * n) + j] * x[j];
42 }
43 }
44 984 x_new[i] = (b[i] - sum) / A[(i * n) + i];
45 }
46
47 double norm = 0.0;
48
2/2
✓ Branch 0 taken 984 times.
✓ Branch 1 taken 368 times.
1352 for (size_t i = 0; i < n; ++i) {
49 984 double diff = x_new[i] - x[i];
50 984 norm += diff * diff;
51 }
52
53
1/2
✓ Branch 1 taken 368 times.
✗ Branch 2 not taken.
368 x = x_new;
54
55
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 40 times.
368 if (std::sqrt(norm) < kEps) {
56 break;
57 }
58 }
59
60
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 GetOutput() = x;
61 40 return true;
62 }
63
64 40 bool KrykovESimpleIterationsSEQ::PostProcessingImpl() {
65 40 return !GetOutput().empty();
66 }
67
68 } // namespace krykov_e_simple_iterations
69