Commit bdf613e2 authored by David Vojtek's avatar David Vojtek

Fix of Unit tests

parent fe92f5a1
......@@ -72,6 +72,12 @@ target_link_libraries(connection_weight_identity_test boost_unit_test 4neuro)
add_executable(dataset_test tests/DataSet_test.cpp)
target_link_libraries(dataset_test boost_unit_test 4neuro)
add_executable(errorfunction_test tests/ErrorFunctions_test.cpp)
target_link_libraries(errorfunction_test boost_unit_test 4neuro)
add_executable(functioncosine_test tests/Graph_Elemetary_Functions_Function_Cosine_test.cpp)
target_link_libraries(functioncosine_test boost_unit_test 4neuro)
add_executable(particle_swarm_test tests/ParticleSwarm_test.cpp)
target_link_libraries(particle_swarm_test boost_unit_test 4neuro)
......
/**
* DESCRIPTION OF THE CLASS
*
* @author David Vojtek
* @date 2018
*/
#define BOOST_TEST_NO_MAIN
#include <boost/test/unit_test.hpp>
#include "../ErrorFunction/ErrorFunctions.h"
#include "../Neuron/NeuronLinear.h"
/**
* Boost testing suite for testing ErrorFunction.h
* doesn't test inherited methods
*/
BOOST_AUTO_TEST_SUITE(ErrorFunctions_test)
BOOST_AUTO_TEST_CASE(ErrorFunction_MSE_Construction_Test) {
NeuralNetwork network;
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);
BOOST_CHECK_NO_THROW(MSE mse(&network, &dataSet));
}
BOOST_AUTO_TEST_CASE(ErrorFunction_MSE_Eval_Test) {
Neuron *n1 = new NeuronLinear(1, 1);
Neuron *n2 = new NeuronLinear(2, 2);
NeuralNetwork network;
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));
network.add_neuron(n1);
network.add_neuron(n2);
network.add_connection_simple(0, 1, 0, 2.5);
network.randomize_weights();
std::vector<size_t> net_input_neurons_indices(1);
std::vector<size_t> net_output_neurons_indices(1);
net_input_neurons_indices[0] = 0;
net_output_neurons_indices[0] = 1;
network.specify_input_neurons(net_input_neurons_indices);
network.specify_output_neurons(net_output_neurons_indices);
DataSet dataSet(&data_vec);
double weights[1] = {0};
MSE mse(&network, &dataSet);
BOOST_CHECK_EQUAL(4, mse.eval(&weights[0]));
}
BOOST_AUTO_TEST_CASE(ErrorFunction_MSE_Get_dimension_test) {
Neuron *n1 = new NeuronLinear(1, 1);
Neuron *n2 = new NeuronLinear(2, 2);
NeuralNetwork network;
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));
network.add_neuron(n1);
network.add_neuron(n2);
network.add_connection_simple(0, 1, 0, 2.5);
network.randomize_weights();
std::vector<size_t> net_input_neurons_indices(1);
std::vector<size_t> net_output_neurons_indices(1);
net_input_neurons_indices[0] = 0;
net_output_neurons_indices[0] = 1;
network.specify_input_neurons(net_input_neurons_indices);
network.specify_output_neurons(net_output_neurons_indices);
DataSet dataSet(&data_vec);
MSE mse(&network, &dataSet);
BOOST_CHECK_EQUAL(1, mse.get_dimension());
}
BOOST_AUTO_TEST_CASE(ErrorFunction_MSE_SUM_Construction_Test) {
BOOST_CHECK_NO_THROW(MSE_SUM mse_sum);
}
BOOST_AUTO_TEST_CASE(ErrorFunction_MSE_SUM_Add_Error_Function_Test) {
NeuralNetwork network;
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);
ErrorFunction *f = new MSE(&network, &dataSet);
MSE_SUM mse_sum;
BOOST_CHECK_NO_THROW(mse_sum.add_error_function(f));
}
BOOST_AUTO_TEST_CASE(ErrorFunction_MSE_SUM_Eval_Test) {
MSE_SUM mse_sum;
double weights[1] = {0};
Neuron *n1 = new NeuronLinear(1, 1);
Neuron *n2 = new NeuronLinear(2, 2);
NeuralNetwork network;
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));
network.add_neuron(n1);
network.add_neuron(n2);
network.add_connection_simple(0, 1, 0, 2.5);
network.randomize_weights();
std::vector<size_t> net_input_neurons_indices(1);
std::vector<size_t> net_output_neurons_indices(1);
net_input_neurons_indices[0] = 0;
net_output_neurons_indices[0] = 1;
network.specify_input_neurons(net_input_neurons_indices);
network.specify_output_neurons(net_output_neurons_indices);
DataSet dataSet(&data_vec);
ErrorFunction *f = new MSE(&network, &dataSet);
mse_sum.add_error_function(f);
BOOST_CHECK_EQUAL(4, mse_sum.eval(&weights[0]));
}
BOOST_AUTO_TEST_CASE(ErrorFunction_MSE_SUM_Get_Dimension_test) {
MSE_SUM mse_sum;
BOOST_CHECK_EQUAL(0, mse_sum.get_dimension());
Neuron *n1 = new NeuronLinear(1, 1);
Neuron *n2 = new NeuronLinear(2, 2);
NeuralNetwork network;
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));
network.add_neuron(n1);
network.add_neuron(n2);
network.add_connection_simple(0, 1, 0, 2.5);
network.randomize_weights();
std::vector<size_t> net_input_neurons_indices(1);
std::vector<size_t> net_output_neurons_indices(1);
net_input_neurons_indices[0] = 0;
net_output_neurons_indices[0] = 1;
network.specify_input_neurons(net_input_neurons_indices);
network.specify_output_neurons(net_output_neurons_indices);
DataSet dataSet(&data_vec);
ErrorFunction *f = new MSE(&network, &dataSet);
mse_sum.add_error_function(f);
BOOST_CHECK_EQUAL(1, mse_sum.get_dimension());
}
BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment