| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <algorithm> | ||
| 4 | #include <limits> | ||
| 5 | #include <random> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "ivanova_p_max_matrix/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace ivanova_p_max_matrix::data { // Объединенные namespace | ||
| 11 | |||
| 12 | class MatrixGenerator { | ||
| 13 | public: | ||
| 14 | static InType GenerateMatrixWithKnownMax(int rows, int cols) { | ||
| 15 | InType matrix(rows, std::vector<int>(cols)); | ||
| 16 | std::random_device rd; | ||
| 17 | std::mt19937 gen(rd()); | ||
| 18 | |||
| 19 | // Максимум = большее из измерений | ||
| 20 | int max_val = std::max(rows, cols); | ||
| 21 | |||
| 22 | // Генерируем значения от -max_val+1 до max_val-1 | ||
| 23 | // (гарантированно меньше max_val) | ||
| 24 | std::uniform_int_distribution<int> dist(-max_val + 1, max_val - 1); | ||
| 25 | |||
| 26 | for (int i = 0; i < rows; ++i) { | ||
| 27 | for (int j = 0; j < cols; ++j) { | ||
| 28 | matrix[i][j] = dist(gen); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | // Устанавливаем гарантированный максимум = max_val | ||
| 33 | // Выбираем случайную позицию для максимума | ||
| 34 | std::uniform_int_distribution<int> row_dist(0, rows - 1); | ||
| 35 | std::uniform_int_distribution<int> col_dist(0, cols - 1); | ||
| 36 | int max_i = row_dist(gen); | ||
| 37 | int max_j = col_dist(gen); | ||
| 38 | matrix[max_i][max_j] = max_val; | ||
| 39 | |||
| 40 | return matrix; | ||
| 41 | } | ||
| 42 | |||
| 43 | 50 | static InType GenerateSquareMatrixWithKnownMax(int size) { | |
| 44 |
1/2✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
|
50 | InType matrix(size, std::vector<int>(size)); |
| 45 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
50 | std::random_device rd; |
| 46 | 50 | std::mt19937 gen(rd()); | |
| 47 | |||
| 48 | // Максимум = size | ||
| 49 | int max_val = size; | ||
| 50 | |||
| 51 | // Генерируем значения от -max_val+1 до max_val-1 | ||
| 52 | 50 | std::uniform_int_distribution<int> dist(-max_val + 1, max_val - 1); | |
| 53 | |||
| 54 |
2/2✓ Branch 0 taken 17380 times.
✓ Branch 1 taken 50 times.
|
17430 | for (int i = 0; i < size; ++i) { |
| 55 |
2/2✓ Branch 0 taken 12764840 times.
✓ Branch 1 taken 17380 times.
|
12782220 | for (int j = 0; j < size; ++j) { |
| 56 | 12764840 | matrix[i][j] = dist(gen); | |
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | // Устанавливаем гарантированный максимум = max_val | ||
| 61 | std::uniform_int_distribution<int> pos_dist(0, size - 1); | ||
| 62 | int max_i = pos_dist(gen); | ||
| 63 | int max_j = pos_dist(gen); | ||
| 64 | 50 | matrix[max_i][max_j] = max_val; | |
| 65 | |||
| 66 | 50 | return matrix; | |
| 67 | ✗ | } | |
| 68 | |||
| 69 | // Для отрицательных тестов - все значения отрицательные | ||
| 70 | 10 | static InType GenerateAllNegativeMatrix(int rows, int cols) { | |
| 71 |
1/2✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
10 | InType matrix(rows, std::vector<int>(cols)); |
| 72 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | std::random_device rd; |
| 73 | 10 | std::mt19937 gen(rd()); | |
| 74 | |||
| 75 | // Генерируем значения от -1000 до -1 | ||
| 76 | std::uniform_int_distribution<int> dist(-1000, -1); | ||
| 77 | |||
| 78 |
2/2✓ Branch 0 taken 500 times.
✓ Branch 1 taken 10 times.
|
510 | for (int i = 0; i < rows; ++i) { |
| 79 |
2/2✓ Branch 0 taken 25000 times.
✓ Branch 1 taken 500 times.
|
25500 | for (int j = 0; j < cols; ++j) { |
| 80 | 25000 | matrix[i][j] = dist(gen); | |
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | // Максимум = -1 (самое большое отрицательное) | ||
| 85 | 10 | std::uniform_int_distribution<int> row_dist(0, rows - 1); | |
| 86 | 10 | std::uniform_int_distribution<int> col_dist(0, cols - 1); | |
| 87 | 10 | matrix[row_dist(gen)][col_dist(gen)] = -1; | |
| 88 | |||
| 89 | 10 | return matrix; | |
| 90 | ✗ | } | |
| 91 | |||
| 92 | static int GetExpectedMax(const InType &matrix) { | ||
| 93 | if (matrix.empty() || matrix[0].empty()) { | ||
| 94 | return std::numeric_limits<int>::min(); | ||
| 95 | } | ||
| 96 | |||
| 97 | // Для наших сгенерированных матриц максимум = большее из измерений | ||
| 98 | return static_cast<int>(std::max(matrix.size(), matrix[0].size())); // Исправлено: явное приведение типа | ||
| 99 | } | ||
| 100 | |||
| 101 | static int GetExpectedMaxForNegative([[maybe_unused]] const InType &matrix) { | ||
| 102 | return -1; // Для отрицательных матриц максимум всегда -1 | ||
| 103 | } | ||
| 104 | }; | ||
| 105 | |||
| 106 | } // namespace ivanova_p_max_matrix::data | ||
| 107 |