GCC Code Coverage Report


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

Line Branch Exec Source
1 #include "yakimov_i_max_values_in_matrix_rows/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
10 // #include "util/include/util.hpp"
11 #include "yakimov_i_max_values_in_matrix_rows/common/include/common.hpp"
12
13 namespace yakimov_i_max_values_in_matrix_rows {
14
15 YakimovIMaxValuesInMatrixRowsSEQ::YakimovIMaxValuesInMatrixRowsSEQ(const InType &in) {
16 SetTypeOfTask(GetStaticTypeOfTask());
17 GetInput() = in;
18 GetOutput() = 0;
19 std::filesystem::path base_path = std::filesystem::current_path();
20 while (base_path.filename() != "ppc-2025-processes-engineers") {
21 base_path = base_path.parent_path();
22 }
23 matrix_Filename_ =
24 base_path.string() + "/tasks/yakimov_i_max_values_in_matrix_rows/data/" + std::to_string(GetInput()) + ".txt";
25 }
26
27 bool YakimovIMaxValuesInMatrixRowsSEQ::ValidationImpl() {
28 return (GetInput() > 0) && (GetOutput() == 0);
29 }
30
31 bool YakimovIMaxValuesInMatrixRowsSEQ::PreProcessingImpl() {
32 if (!ReadMatrixFromFile(matrix_Filename_)) {
33 return false;
34 }
35
36 matrix_.resize(rows_);
37 max_Values_.resize(rows_);
38 return true;
39 }
40
41 bool YakimovIMaxValuesInMatrixRowsSEQ::ReadMatrixFromFile(const std::string &filename) {
42 std::ifstream file(filename);
43 if (!file.is_open()) {
44 return false;
45 }
46
47 file >> rows_ >> cols_;
48
49 if (rows_ == 0 || cols_ == 0) {
50 return false;
51 }
52
53 matrix_.resize(rows_);
54 for (size_t i = 0; i < rows_; i++) {
55 matrix_[i].resize(cols_);
56 }
57
58 for (size_t i = 0; i < rows_; i++) {
59 for (size_t j = 0; j < cols_; j++) {
60 if (!(file >> matrix_[i][j])) {
61 return false;
62 }
63 }
64 }
65
66 file.close();
67 return true;
68 }
69
70 bool YakimovIMaxValuesInMatrixRowsSEQ::RunImpl() {
71 for (size_t i = 0; i < rows_; i++) {
72 max_Values_[i] = matrix_[i][0];
73 for (size_t j = 1; j < cols_; j++) {
74 max_Values_[i] = std::max(matrix_[i][j], max_Values_[i]);
75 }
76 }
77 return true;
78 }
79
80 bool YakimovIMaxValuesInMatrixRowsSEQ::PostProcessingImpl() {
81 if (!max_Values_.empty()) {
82 OutType result = 0;
83 for (const auto &max_val : max_Values_) {
84 result += max_val;
85 }
86 GetOutput() = result;
87 return true;
88 }
89 return false;
90 }
91
92 } // namespace yakimov_i_max_values_in_matrix_rows
93