Skip to content
Snippets Groups Projects
Connection_test.cpp 1.95 KiB
Newer Older
  • Learn to ignore specific revisions
  • David Vojtek's avatar
    David Vojtek committed
    /**
     * DESCRIPTION OF THE CLASS
     *
     * @author David Vojtek
     * @date 2018
     */
    
    #define BOOST_TEST_NO_MAIN
    
    #include <boost/test/unit_test.hpp>
    
    
    #include "../NetConnection/Connection.h"
    #include "../NetConnection/ConnectionWeight.h"
    #include "../Neuron/NeuronLinear.h"
    #include <iostream>
    /**
     * Boost testing suite for testing Connection.h
     */
    
    BOOST_AUTO_TEST_SUITE(Connection_test)
    
    
        /**
         * Test of constructor of Connection
         */
    
    David Vojtek's avatar
    David Vojtek committed
        BOOST_AUTO_TEST_CASE(Connection_construction__test) {
    
    
            Neuron *neuron1 = new NeuronLinear(2, 3);
            Neuron *neuron2 = new NeuronLinear(4, 5);
            std::vector<double> w_array = {2, 3, 4, 5, 6};
    
    David Vojtek's avatar
    David Vojtek committed
    
    
            ConnectionWeight *conn = new ConnectionWeight(2, &w_array);
    
    David Vojtek's avatar
    David Vojtek committed
            Connection connection(neuron1, neuron2, conn);
    
            //Test of correct input neuron
    
    David Vojtek's avatar
    David Vojtek committed
            BOOST_CHECK_EQUAL(neuron1, connection.get_neuron_in());
    
            //Test of correct output neuron
    
    David Vojtek's avatar
    David Vojtek committed
            BOOST_CHECK_EQUAL(neuron2, connection.get_neuron_out());
        }
    
    
        /**
         * Test of pass_signal method
         */
    
    David Vojtek's avatar
    David Vojtek committed
        BOOST_AUTO_TEST_CASE(Connection_pass_signal_test) {
    
    
            Neuron *neuron1 = new NeuronLinear(2, 3);
            Neuron *neuron2 = new NeuronLinear(4, 5);
            std::vector<double> w_array = {2, 3, 4, 5, 6};
            std::function<double(double *, int *, int)> f = [](double *weight_array, int *index_array, int n_params) {
    
    David Vojtek's avatar
    David Vojtek committed
                double a = weight_array[0];
                double b = weight_array[1];
                return (a + 1.5 * b);
            };
    
    
    
            ConnectionWeight *conn = new ConnectionWeight(2, &w_array);
    
    
    David Vojtek's avatar
    David Vojtek committed
            Connection connection(neuron1, neuron2, conn);
    
            neuron1->activate();
            neuron2->activate();
    
            // test of neuron state before passing signal
    
    David Vojtek's avatar
    David Vojtek committed
            BOOST_CHECK_EQUAL(4, neuron2->get_state());
            connection.pass_signal();
            neuron2->activate();
    
            // test of neuron state after passing signal
    
    David Vojtek's avatar
    David Vojtek committed
            BOOST_CHECK_EQUAL(7204, neuron2->get_state());
    
    David Vojtek's avatar
    David Vojtek committed
    
        }
    
    
    BOOST_AUTO_TEST_SUITE_END()