Skip to content
Snippets Groups Projects
NeuralNetworkSum_test.cpp 2.66 KiB
Newer Older
/**
 * DESCRIPTION OF THE CLASS
 *
 * @author David Vojtek
 * @date 2018
 */

David Vojtek's avatar
David Vojtek committed
#include "boost_unit_tests_preamble.h"
#include "../Network/NeuralNetworkSum.h"
#include <turtle/mock.hpp>
David Vojtek's avatar
David Vojtek committed
using namespace lib4neuro;

MOCK_BASE_CLASS(mock_network, lib4neuro::NeuralNetwork)
{
	MOCK_METHOD(get_subnet, 2)
		MOCK_METHOD(add_neuron, 3)
		MOCK_METHOD(add_connection_simple, 4)
		MOCK_METHOD(add_existing_connection, 4)
		MOCK_METHOD(copy_parameter_space, 1)
		MOCK_METHOD(set_parameter_space_pointers, 1)
		MOCK_METHOD(eval_single, 3)
		MOCK_METHOD(add_to_gradient_single, 4)
		MOCK_METHOD(randomize_weights, 0)
		MOCK_METHOD(randomize_biases, 0)
		MOCK_METHOD(randomize_parameters, 0)
		MOCK_METHOD(get_n_inputs, 0)
		MOCK_METHOD(get_n_outputs, 0)
		MOCK_METHOD(get_n_weights, 0)
		MOCK_METHOD(get_n_biases, 0)
		MOCK_METHOD(get_neuron_bias_index, 1)
		MOCK_METHOD(get_n_neurons, 0)
		MOCK_METHOD(specify_input_neurons, 1)
		MOCK_METHOD(specify_output_neurons, 1)
		MOCK_METHOD(get_parameter_ptr_biases, 0)
		MOCK_METHOD(get_parameter_ptr_weights, 0)
		MOCK_METHOD(save_text, 1)
		MOCK_METHOD(print_stats, 0)
		MOCK_METHOD(print_weights, 0)
};

/**
 * Boost testing suite for testing NeuralNetworkSum.h
 */
BOOST_AUTO_TEST_SUITE(NeuralNetworkSum_test)
    /**
     * Test of creating new instance of NeuralNetworkSum
     */
    BOOST_AUTO_TEST_CASE(NeuralNetworkSum_constuction_test) {
        //Test of none exception raise when creating new instance of NeuralNewtwork
        BOOST_CHECK_NO_THROW(NeuralNetworkSum networkSum);
    }

    BOOST_AUTO_TEST_CASE(NeuralNetworkSum_add_network_test) {
        mock_network network;
		//NeuralNetwork network;
        NeuralNetworkSum networkSum;
David Vojtek's avatar
David Vojtek committed
		std::string po = "f(x,y,z,t) =x+y+z+t";
        BOOST_CHECK_NO_THROW(networkSum.add_network(&network, po));
David Vojtek's avatar
David Vojtek committed
   BOOST_AUTO_TEST_CASE(NeuralNetworkSum_eval_single_weights_test) {
       
	   mock_network network;
	   MOCK_EXPECT(network.eval_single);

        std::vector<double> input;
        input.push_back(1);
        std::vector<double> output;
        output.push_back(1);

        double weights = 5;
        NeuralNetworkSum networkSum;
David Vojtek's avatar
David Vojtek committed
        networkSum.add_network(&network, "f(x) =x");

        networkSum.eval_single(input, output);
David Vojtek's avatar
David Vojtek committed
        BOOST_CHECK_EQUAL(0, output.at(0));
    BOOST_AUTO_TEST_CASE(NeuralNetworkSum_get_weights_test) {
        NeuralNetworkSum networkSum;
        BOOST_CHECK_EQUAL(0, networkSum.get_n_weights());

David Vojtek's avatar
David Vojtek committed
		mock_network network;
		MOCK_EXPECT(network.get_n_weights).returns(1);
        networkSum.add_network(&network, "f(x) =x");

        BOOST_CHECK_EQUAL(1, networkSum.get_n_weights());
    }

BOOST_AUTO_TEST_SUITE_END()