summaryrefslogtreecommitdiff
path: root/test/neural_network.cpp
blob: 6040c83ad5924fb2eca93b5454cd07c93d585434 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "catch.hpp"
#include <sstream>

#include "brain/neural_network.h"

SCENARIO("network is read from istream")
{
    GIVEN("an empty config file")
    {
	std::stringstream file;
	file << "" << std::endl;

	WHEN ("the network is initialized")
	{
	    NeuralNetwork network(std::move(file), 1, 2);
	    
	    THEN("the specified number of inputs and outputs are created")
	    {
		REQUIRE(network.numberOfSensors() == 1);
		REQUIRE(network.numberOfOutputs() == 2);
	    }
	}
    }

    GIVEN("a valid config file")
    {
	std::stringstream file;
	file << "s0 n2 0.5" << std::endl;
	file << "n2 n1 1" << std::endl;
	file << "b0 n0 0.4" << std::endl;
	file << "b0 n2 0.5" << std:: endl;

	WHEN("the network is initialized")
	{
	    NeuralNetwork network(std::move(file), 1, 2);
	    
	    THEN("the network is constructed correctly")
	    {
		network.setInput(0, 1);
		REQUIRE(network.findMaxOutputIndex() == 1);
	    }
	}
    }
}