Skip to content
Snippets Groups Projects
Particle_test.cpp 2.46 KiB
Newer Older
  • Learn to ignore specific revisions
  • /**
     * DESCRIPTION OF THE CLASS
     *
     * @author David Vojtek
     * @date 2018
     */
    
    
    David Vojtek's avatar
    David Vojtek committed
    #include <boost/test/included/unit_test.hpp>
    
    David Vojtek's avatar
    David Vojtek committed
    #ifndef BOOST_TEST_DYN_LINK
    #define BOOST_TEST_DYN_LINK
    #endif
    
    David Vojtek's avatar
    David Vojtek committed
    #ifndef BOOST_TEST_NO_MAIN
    #define BOOST_TEST_NO_MAIN
    #endif
    
    David Vojtek's avatar
    David Vojtek committed
    #include <turtle/mock.hpp>
    #include <boost/test/unit_test.hpp>
    #include <boost/test/output_test_stream.hpp>
    
    #include "../LearningMethods/ParticleSwarm.h"
    
    David Vojtek's avatar
    David Vojtek committed
    
    
    using namespace lib4neuro;
    
    MOCK_BASE_CLASS(mock_Error, ErrorFunction)
    
    David Vojtek's avatar
    David Vojtek 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)
    
        MOCK_METHOD(return_full_data_set_for_training, 0)
    
        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)
    
    David Vojtek's avatar
    David Vojtek committed
    };
    
    David Vojtek's avatar
    David Vojtek committed
    
    
    /**
     * Boost testing suite for testing ParticleSwarm.h
     * TODO
     */
    
    David Vojtek's avatar
    David Vojtek committed
    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));
    
    David Vojtek's avatar
    David Vojtek committed
    }
    
    BOOST_AUTO_TEST_CASE(Particle_get_coordinate_test) {
    
    	std::vector<double> domain_bound{ 1, 2, 3, 4, 5 };
    	mock_Error error;
    
    David Vojtek's avatar
    David Vojtek committed
    
    
    	MOCK_EXPECT(error.get_dimension).returns(5);
    	MOCK_EXPECT(error.eval).returns(0.8);
    
    David Vojtek's avatar
    David Vojtek committed
    
    
    	Particle particle1(&error, &domain_bound);
    	Particle particle2(&error, &domain_bound);
    
    David Vojtek's avatar
    David Vojtek committed
    
    
    	BOOST_CHECK(*particle1.get_coordinate() != *particle2.get_coordinate());
    
    David Vojtek's avatar
    .  
    David Vojtek committed
    }
    
    David Vojtek's avatar
    .  
    David Vojtek committed
    BOOST_AUTO_TEST_CASE(Particle_get_optimal_value_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);
    
    David Vojtek's avatar
    David Vojtek committed
    
    
    	Particle particle1(&error, &domain_bound);
    	BOOST_CHECK_EQUAL(0.8, particle1.get_optimal_value());
    
    David Vojtek's avatar
    David Vojtek committed
    }
    
    BOOST_AUTO_TEST_SUITE_END()