-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathstd_2d_arraytest.cpp
More file actions
160 lines (135 loc) · 3.95 KB
/
std_2d_arraytest.cpp
File metadata and controls
160 lines (135 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <gtest/gtest.h>
#include "adapters/std2darrayadapter.h"
#include <iostream>
#include <iomanip>
using namespace MunkresCpp;
class Adapters_std_2d_array_Test : public ::testing::Test
{
};
TEST_F (Adapters_std_2d_array_Test, convert_std_2d_array_to_munkres_matrix_Success)
{
// Arrange.
constexpr unsigned int dimension {3};
const std::array <std::array <double, dimension>, dimension> test_array {{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
}};
const Matrix <double> etalon_matrix {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
Std2dArrayAdapter<double,test_array.size(),test_array.size()> adapter;
// Act.
const auto test_matrix = adapter.convertToMatrix(test_array);
// Assert.
for (unsigned int row = 0; row < dimension; ++row) {
for (unsigned int col = 0; col < dimension; ++col) {
EXPECT_EQ (etalon_matrix (row, col), test_matrix (row, col) );
}
}
}
TEST_F (Adapters_std_2d_array_Test, convert_non_square_std_2d_array_to_munkres_matrix_Success)
{
// Arrange.
constexpr unsigned int dimension1 {2};
constexpr unsigned int dimension2 {3};
const std::array <std::array <double, dimension2>, dimension1> test_array {{
{1, 2, 3},
{4, 5, 6}
}};
const Matrix <double> etalon_matrix {
{1, 2, 3},
{4, 5, 6}
};
Std2dArrayAdapter<double,test_array.size(),test_array[0].size()> adapter;
// Act.
const auto test_matrix = adapter.convertToMatrix(test_array);
// Assert.
for (unsigned int row = 0; row < dimension1; ++row) {
for (unsigned int col = 0; col < dimension2; ++col) {
EXPECT_EQ (etalon_matrix (row, col), test_matrix (row, col) );
}
}
}
TEST_F (Adapters_std_2d_array_Test, fill_std_2d_array_from_munkres_matrix_Success)
{
// Arrange.
constexpr unsigned int dimension {3};
std::array <std::array <double, dimension>, dimension> test_array {{
{0, 0, 0},
{0, 0, 0},
{0, 0, 0}
}};
const std::array <std::array <double, dimension>, dimension> etalon_array {{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
}};
const Matrix <double> etalon_matrix {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
Std2dArrayAdapter<double,test_array.size(),test_array.size()> adapter;
// Act.
adapter.convertFromMatrix(test_array, etalon_matrix);
// Assert.
for (unsigned int row = 0; row < dimension; ++row) {
for (unsigned int col = 0; col < dimension; ++col) {
EXPECT_EQ (etalon_array [row][col], test_array [row][col]);
}
}
}
TEST_F (Adapters_std_2d_array_Test, fill_non_square_std_2d_array_from_munkres_matrix_Success)
{
// Arrange.
constexpr unsigned int dimension1 {2};
constexpr unsigned int dimension2 {3};
std::array <std::array <double, dimension2>, dimension1> test_array {{
{0, 0, 0},
{0, 0, 0}
}};
const std::array <std::array <double, dimension2>, dimension1> etalon_array {{
{1, 2, 3},
{4, 5, 6}
}};
const Matrix <double> etalon_matrix {
{1, 2, 3},
{4, 5, 6}
};
Std2dArrayAdapter<double,test_array.size(),dimension2> adapter;
// Act.
adapter.convertFromMatrix(test_array, etalon_matrix);
// Assert.
for (unsigned int row = 0; row < dimension1; ++row) {
for (unsigned int col = 0; col < dimension2; ++col) {
EXPECT_EQ (etalon_array [row][col], test_array [row][col]);
}
}
}
TEST_F (Adapters_std_2d_array_Test, solve_std_2d_array_Success)
{
// Arrange.
constexpr unsigned int dimension {3};
std::array <std::array <double, dimension>, dimension> etalon_array{{
{-1.0, 0.0, -1.0},
{ 0.0, -1.0, -1.0},
{-1.0, -1.0, 0.0}
}};
std::array <std::array <double, dimension>, dimension> test_array{{
{1.0, 0.0, 1.0},
{0.0, 1.0, 1.0},
{1.0, 1.0, 0.0}
}};
Std2dArrayAdapter<double,test_array.size(),test_array.size()> adapter;
// Act.
adapter.solve(test_array);
// Assert.
for (unsigned int row = 0; row < dimension; ++row) {
for (unsigned int col = 0; col < dimension; ++col) {
EXPECT_EQ (etalon_array [row][col], test_array [row][col]);
}
}
}