Newer
Older
/**
* DESCRIPTION OF THE CLASS
*
* @author David Vojtek
* @date 2018
*/
kra568
committed
#define BOOST_TEST_MODULE DataSet_test
kra568
committed
/**
* Boost testing suite for testing DataSet.h
*/
BOOST_AUTO_TEST_SUITE(DataSet_test)
/**
* Test of DataSet constructor with filepath parameter
*/
BOOST_AUTO_TEST_CASE(DataSet_construction_from_file_test) {
//test of exception with non-existing file path
//TODO resolve exception throw
//DataSet dataSet("file/unknown");
//BOOST_CHECK_THROW(DataSet dataSet("file unknown"), std::out_of_range);// boost::archive::archive_exception::input_stream_error);
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
}
/**
* Test of DataSet constructor with vector parameter
*/
BOOST_AUTO_TEST_CASE(DataSet_construction_from_vector_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
//test of no exception when create object DataSet
BOOST_CHECK_NO_THROW(DataSet dataSet(&data_vec));
}
/**
* Test of get_data method
*/
BOOST_AUTO_TEST_CASE(DataSet_get_data_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 1; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
//test of equal data
BOOST_CHECK_EQUAL(0, dataSet.get_data()->at(0).first.at(0));
BOOST_CHECK_EQUAL(4, dataSet.get_data()->at(0).second.at(0));
}
/**
* Test of add_data_pair method
*/
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
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
inp.clear();
out.clear();
for (int i = 8; i < 11; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
dataSet.add_data_pair(inp, out);
// Test of correct add of input
BOOST_CHECK_EQUAL(8, dataSet.get_data()->at(1).first.at(0));
// Test of correct add of output
BOOST_CHECK_EQUAL(12, dataSet.get_data()->at(1).second.at(0));
}
/**
* Test of get_input_dim and get_output_dim methods
*/
BOOST_AUTO_TEST_CASE(DataSet_dimension_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
//Test of correct input dimension
BOOST_CHECK_EQUAL(3, dataSet.get_input_dim());
//Test of correct output dimension
BOOST_CHECK_EQUAL(3, dataSet.get_output_dim());
}
/**
* Test of get_n_elements method
*/
BOOST_AUTO_TEST_CASE(DataSet_get_number_of_elements_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
inp.clear();
out.clear();
for (int i = 8; i < 11; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
//Test of correct number of elements
BOOST_CHECK_EQUAL(2, dataSet.get_n_elements());
}
/**
* Test of print_data method
*/
BOOST_AUTO_TEST_CASE(DataSet_print_data_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 1; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
std::stringstream buffer;
std::streambuf * old = std::cout.rdbuf(buffer.rdbuf());
dataSet.print_data();
//Test of correct print of DataSet
std::string text = buffer.str();
BOOST_CHECK(text._Equal("0 -> 4 \n"));
std::cout.rdbuf(old);
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
}
/**
* Test of store_text method
*/
BOOST_AUTO_TEST_CASE(DataSet_store_text_test) {
std::vector<std::pair<std::vector<double>, std::vector<double>>> data_vec;
std::vector<double> inp, out;
for (int i = 0; i < 3; i++) {
inp.push_back(i);
out.push_back(i + 4);
}
data_vec.emplace_back(std::make_pair(inp, out));
DataSet dataSet(&data_vec);
int elements = dataSet.get_n_elements();
std::string filename = "testDataSet";
dataSet.store_text(filename);
//Test of correct file creations
DataSet newDataSet("testDataSet");
//Test of correct number of element from dataSet from file
BOOST_CHECK_EQUAL(elements, newDataSet.get_n_elements());
// removing of created file
remove("testDataSet");
}
BOOST_AUTO_TEST_SUITE_END()