Newer
Older
/**
* DESCRIPTION OF THE CLASS
*
* @author David Vojtek
* @date 2018
*/
kra568
committed
#define BOOST_TEST_MODULE Particle_test
kra568
committed
#ifdef _WINDOWS
Martin Beseda
committed
//#include <turtle/mock.hpp>
#endif
#ifndef BOOST_TEST_DYN_LINK
#define BOOST_TEST_DYN_LINK
#endif
#ifndef BOOST_TEST_NO_MAIN
#define BOOST_TEST_NO_MAIN
#endif
Martin Beseda
committed
#include <turtle/mock.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
#include "../LearningMethods/ParticleSwarm.h"
Martin Beseda
committed
using namespace lib4neuro;
MOCK_BASE_CLASS(mock_Error, ErrorFunction)
Martin Beseda
committed
MOCK_METHOD(eval, 1)
MOCK_METHOD(get_dimension, 0)
MOCK_METHOD(calculate_error_gradient, 4)
MOCK_METHOD(get_parameters, 0)
MOCK_METHOD(get_dataset, 0)
MOCK_METHOD(get_network_instance, 0)
Martin Beseda
committed
MOCK_METHOD(divide_data_train_test, 1)
Martin Beseda
committed
MOCK_METHOD(return_full_data_set_for_training, 0)
Martin Beseda
committed
MOCK_METHOD(eval_on_test_data, 1, double(std::vector<double>*), id1)
MOCK_METHOD(eval_on_test_data, 2, double(std::string, std::vector<double>*), id2)
MOCK_METHOD(eval_on_test_data, 2, double(std::ofstream*, std::vector<double>*), id3)
MOCK_METHOD(eval_on_data_set, 2, double(DataSet*, std::vector<double>*), id4)
MOCK_METHOD(eval_on_data_set, 3, double(DataSet*, std::string, std::vector<double>*), id5)
MOCK_METHOD(eval_on_data_set, 3, double(DataSet*, std::ofstream*, std::vector<double>*), id6)
/**
* Boost testing suite for testing ParticleSwarm.h
* TODO
*/
BOOST_AUTO_TEST_SUITE(Particle_test)
BOOST_AUTO_TEST_CASE(Particle_construction_test) {
std::vector<double> domain_bound{ 1, 2, 3, 4, 5 };
mock_Error error;
MOCK_EXPECT(error.get_dimension).once().returns(5);
MOCK_EXPECT(error.eval).once().returns(0.8);
BOOST_CHECK_NO_THROW(Particle(&error, &domain_bound));
}
BOOST_AUTO_TEST_CASE(Particle_get_coordinate_test) {
std::vector<double> domain_bound{ 1, 2, 3, 4, 5 };
mock_Error error;
MOCK_EXPECT(error.get_dimension).returns(5);
MOCK_EXPECT(error.eval).returns(0.8);
Particle particle1(&error, &domain_bound);
Particle particle2(&error, &domain_bound);
BOOST_CHECK(*particle1.get_coordinate() != *particle2.get_coordinate());
Martin Beseda
committed
std::vector<double> domain_bound{ 1, 2, 3, 4, 5 };
mock_Error error;
MOCK_EXPECT(error.get_dimension).returns(5);
MOCK_EXPECT(error.eval).returns(0.8);
Martin Beseda
committed
Particle particle1(&error, &domain_bound);
BOOST_CHECK_EQUAL(0.8, particle1.get_optimal_value());