GCC Code Coverage Report


Directory: ./
File: tasks/gasenin_l_djstra/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 36 36 100.0%
Functions: 7 7 100.0%
Branches: 22 30 73.3%

Line Branch Exec Source
1 #include "gasenin_l_djstra/seq/include/ops_seq.hpp"
2
3 #include <limits>
4 #include <vector>
5
6 #include "gasenin_l_djstra/common/include/common.hpp"
7
8 namespace gasenin_l_djstra {
9
10 24 GaseninLDjstraSEQ::GaseninLDjstraSEQ(const InType &in) {
11 SetTypeOfTask(GetStaticTypeOfTask());
12 24 GetInput() = in;
13 GetOutput() = 0;
14 24 }
15
16 24 bool GaseninLDjstraSEQ::ValidationImpl() {
17 24 return GetInput() > 0;
18 }
19
20 24 bool GaseninLDjstraSEQ::PreProcessingImpl() {
21 24 return true;
22 }
23
24 // static
25 120 InType GaseninLDjstraSEQ::FindMinDist(const std::vector<InType> &dist, const std::vector<bool> &visited) {
26 120 auto n = static_cast<InType>(dist.size());
27 InType min_dist = std::numeric_limits<InType>::max();
28 InType u = -1;
29
2/2
✓ Branch 0 taken 664 times.
✓ Branch 1 taken 120 times.
784 for (InType i = 0; i < n; ++i) {
30
4/4
✓ Branch 0 taken 392 times.
✓ Branch 1 taken 272 times.
✓ Branch 2 taken 272 times.
✓ Branch 3 taken 120 times.
664 if (!visited[i] && dist[i] < min_dist) {
31 min_dist = dist[i];
32 u = i;
33 }
34 }
35 120 return u;
36 }
37
38 // static
39 120 void GaseninLDjstraSEQ::RelaxEdges(InType u, std::vector<InType> &dist, const std::vector<bool> &visited) {
40 120 auto n = static_cast<InType>(dist.size());
41
2/2
✓ Branch 0 taken 664 times.
✓ Branch 1 taken 120 times.
784 for (InType vert = 0; vert < n; ++vert) {
42
3/4
✓ Branch 0 taken 272 times.
✓ Branch 1 taken 392 times.
✓ Branch 2 taken 272 times.
✗ Branch 3 not taken.
664 if (!visited[vert] && u != vert) {
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 272 times.
272 InType weight = (u > vert) ? (u - vert) : (vert - u);
44
3/4
✓ Branch 0 taken 272 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 176 times.
272 if (dist[u] != std::numeric_limits<InType>::max() && dist[u] + weight < dist[vert]) {
45 96 dist[vert] = dist[u] + weight;
46 }
47 }
48 }
49 120 }
50
51 24 bool GaseninLDjstraSEQ::RunImpl() {
52 24 InType n = GetInput();
53
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (n == 0) {
54 return false;
55 }
56
57 24 const InType k_inf = std::numeric_limits<InType>::max();
58 24 std::vector<InType> dist(n, k_inf);
59
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 std::vector<bool> visited(n, false);
60 24 dist[0] = 0;
61
62
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 24 times.
144 for (int count = 0; count < n; ++count) {
63 120 InType u = FindMinDist(dist, visited);
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
120 if (u == -1) {
65 break;
66 }
67 visited[u] = true;
68 120 RelaxEdges(u, dist, visited);
69 }
70
71 InType sum = 0;
72
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 24 times.
144 for (InType i = 0; i < n; ++i) {
73 120 sum += dist[i];
74 }
75 24 GetOutput() = sum;
76 return true;
77 }
78
79 24 bool GaseninLDjstraSEQ::PostProcessingImpl() {
80 24 return true;
81 }
82
83 } // namespace gasenin_l_djstra
84