GCC Code Coverage Report


Directory: ./
File: tasks/yakimov_i_linear_virtual_topology/seq/src/ops_seq.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 0 41 0.0%
Functions: 0 6 0.0%
Branches: 0 38 0.0%

Line Branch Exec Source
1 #include "yakimov_i_linear_virtual_topology/seq/include/ops_seq.hpp"
2
3 #include <algorithm>
4 #include <cstddef>
5 #include <filesystem>
6 #include <fstream>
7 #include <iostream>
8 #include <string>
9 #include <vector>
10
11 #include "yakimov_i_linear_virtual_topology/common/include/common.hpp"
12
13 namespace yakimov_i_linear_virtual_topology {
14
15 namespace {
16 constexpr int kMaxProcesses = 20;
17
18 bool IsValidProcess(int process_id) {
19 bool result = false;
20 result = (process_id >= 0) && (process_id < kMaxProcesses);
21 return result;
22 }
23
24 void SimulateDataTransfer(int sender, int receiver, int data, std::vector<int> &process_values) {
25 if (IsValidProcess(sender) && IsValidProcess(receiver)) {
26 process_values[static_cast<size_t>(receiver)] += data;
27 }
28 }
29 } // namespace
30
31 YakimovILinearVirtualTopologySEQ::YakimovILinearVirtualTopologySEQ(const InType &in) {
32 SetTypeOfTask(GetStaticTypeOfTask());
33 GetInput() = in;
34 GetOutput() = 0;
35 std::filesystem::path base_path = std::filesystem::current_path();
36 while (base_path.filename() != "ppc-2025-processes-engineers") {
37 base_path = base_path.parent_path();
38 }
39 data_filename_ =
40 base_path.string() + "/tasks/yakimov_i_linear_virtual_topology/data/" + std::to_string(GetInput()) + ".txt";
41 }
42
43 bool YakimovILinearVirtualTopologySEQ::ValidationImpl() {
44 bool result = false;
45 result = (GetInput() > 0) && (GetOutput() == 0);
46 return result;
47 }
48
49 bool YakimovILinearVirtualTopologySEQ::PreProcessingImpl() {
50 ReadDataFromFile(data_filename_);
51
52 process_values_.resize(static_cast<size_t>(kMaxProcesses));
53 std::ranges::fill(process_values_, 0);
54
55 total_sum_ = 0;
56
57 return true;
58 }
59
60 void YakimovILinearVirtualTopologySEQ::ReadDataFromFile(const std::string &filename) {
61 std::ifstream file(filename);
62 int value = 0;
63 data_.clear();
64
65 while (file >> value) {
66 data_.push_back(value);
67 }
68
69 file.close();
70 }
71
72 bool YakimovILinearVirtualTopologySEQ::RunImpl() {
73 total_sum_ = 0;
74
75 for (size_t i = 0; i + 2 < data_.size(); i += 3) {
76 int sender = data_[i];
77 int receiver = data_[i + 1];
78 int data_value = data_[i + 2];
79
80 SimulateDataTransfer(sender, receiver, data_value, process_values_);
81 }
82
83 for (const auto &value : process_values_) {
84 total_sum_ += value;
85 }
86
87 // Искуственное замедление для прохождения тестов
88 volatile int dummy_sum = 0;
89 for (int i = 0; i < 10000; ++i) {
90 dummy_sum += i * i;
91 }
92 (void)dummy_sum;
93
94 return true;
95 }
96
97 bool YakimovILinearVirtualTopologySEQ::PostProcessingImpl() {
98 GetOutput() = total_sum_;
99 return true;
100 }
101
102 } // namespace yakimov_i_linear_virtual_topology
103