#include "catch.hpp" #include #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 n3 0.5" << std::endl; file << "n3 n1 1" << std::endl; file << "b0 n0 0.4" << std::endl; file << "b0 n3 0.5" << std::endl; WHEN("the network is initialized") { NeuralNetwork network(std::move(file), 1, 3); THEN("the network is constructed correctly") { network.setInput(0, 1); REQUIRE(network.findMaxOutputIndex() == 1); } } } GIVEN("a valid recurrant config file") { std::stringstream file; file << "s0 n3 0.5" << std::endl; file << "n3 n1 1" << std::endl; file << "b0 n0 0.4" << std::endl; file << "b0 n3 0.5" << std::endl; file << "n1 n3 0.5" << std::endl; WHEN("the network converges") { NeuralNetwork network(std::move(file), 1, 3); THEN("the network is constructed correctly") { network.setInput(0, 1); REQUIRE(network.findMaxOutputIndex() == 1); } } } }