Newer
Older
/**
* DESCRIPTION OF THE CLASS
*
* @author David Vojtek
* @date 2018
*/
kra568
committed
#define BOOST_TEST_MODULE DataSet_test
kra568
committed
//#include <boost/filesystem.hpp>
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
/**
* Boost testing suite for testing DataSet.h
*/
BOOST_AUTO_TEST_SUITE(DataSet_test)
struct cout_redirect {
cout_redirect(std::streambuf *new_buffer)
: old(std::cout.rdbuf(new_buffer)) {}
~cout_redirect() {
std::cout.rdbuf(old);
}
private:
std::streambuf *old;
};
/**
* 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"), boost::archive::archive_exception::input_stream_error);
}
/**
* 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
//TODO out of range, ==
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
*/
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
161
162
163
164
165
166
167
168
169
170
171
172
173
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) {
//TODO this test causes problems on windows machines
/*
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);
boost::test_tools::output_test_stream output;
{
cout_redirect guard(output.rdbuf());
dataSet.print_data();
}
//Test of correct print of DataSet
BOOST_CHECK(output.is_equal("0 -> 4 \n"));
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
}
/**
* 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
//BOOST_CHECK(boost::filesystem::exists( "testDataSet" ));
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()