GCC Code Coverage Report


Directory: ./
File: tasks/pankov_a_path_dejikstra/seq/src/ops_seq.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 31 31 100.0%
Functions: 6 6 100.0%
Branches: 23 38 60.5%

Line Branch Exec Source
1 #include "pankov_a_path_dejikstra/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <functional>
5 #include <queue>
6 #include <utility>
7 #include <vector>
8
9 #include "pankov_a_path_dejikstra/common/include/common.hpp"
10
11 namespace pankov_a_path_dejikstra {
12 namespace {
13
14 using AdjList = std::vector<std::vector<std::pair<Vertex, Weight>>>;
15
16 24 OutType DijkstraSeq(Vertex source, const AdjList &adjacency) {
17
1/2
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 OutType distance(adjacency.size(), kInfinity);
18 using QueueNode = std::pair<Weight, Vertex>;
19 std::priority_queue<QueueNode, std::vector<QueueNode>, std::greater<>> min_queue;
20
21
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 distance[source] = 0;
22
1/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
24 min_queue.emplace(0, source);
23
24
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 24 times.
168 while (!min_queue.empty()) {
25 144 const auto [current_dist, u] = min_queue.top();
26 144 min_queue.pop();
27
28
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 120 times.
144 if (current_dist != distance[u]) {
29 24 continue;
30 }
31
32
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 120 times.
248 for (const auto &[v, weight] : adjacency[u]) {
33
3/4
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 8 times.
128 if (current_dist <= kInfinity - weight && current_dist + weight < distance[v]) {
34 120 distance[v] = current_dist + weight;
35
1/2
✓ Branch 1 taken 120 times.
✗ Branch 2 not taken.
120 min_queue.emplace(distance[v], v);
36 }
37 }
38 }
39
40 24 return distance;
41 }
42
43 } // namespace
44
45
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 PankovAPathDejikstraSEQ::PankovAPathDejikstraSEQ(const InType &in) {
46 SetTypeOfTask(GetStaticTypeOfTask());
47 GetInput() = in;
48 GetOutput().clear();
49 24 }
50
51 24 bool PankovAPathDejikstraSEQ::ValidationImpl() {
52 const InType &input = GetInput();
53
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 if (input.n == 0 || input.source >= input.n) {
54 return false;
55 }
56
57 const auto edge_valid = [&input](const Edge &e) {
58 128 const auto [from, to, weight] = e;
59
3/6
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 128 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 128 times.
✗ Branch 5 not taken.
128 return from < input.n && to < input.n && weight >= 0;
60 };
61 return std::ranges::all_of(input.edges, edge_valid);
62 }
63
64 24 bool PankovAPathDejikstraSEQ::PreProcessingImpl() {
65 const InType &input = GetInput();
66 24 adjacency_.assign(input.n, {});
67
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 24 times.
152 for (const auto &[from, to, weight] : input.edges) {
68 128 adjacency_[from].emplace_back(to, weight);
69 }
70 GetOutput().clear();
71 24 return true;
72 }
73
74
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 bool PankovAPathDejikstraSEQ::RunImpl() {
75 const InType &input = GetInput();
76
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (adjacency_.size() != input.n) {
77 return false;
78 }
79 48 GetOutput() = DijkstraSeq(input.source, adjacency_);
80 24 return GetOutput().size() == input.n;
81 }
82
83 24 bool PankovAPathDejikstraSEQ::PostProcessingImpl() {
84 24 return GetOutput().size() == GetInput().n;
85 }
86
87 } // namespace pankov_a_path_dejikstra
88