summaryrefslogtreecommitdiff
path: root/test/neural_network.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/neural_network.cpp')
-rw-r--r--test/neural_network.cpp137
1 files changed, 97 insertions, 40 deletions
diff --git a/test/neural_network.cpp b/test/neural_network.cpp
index 801f0ec..418f5c4 100644
--- a/test/neural_network.cpp
+++ b/test/neural_network.cpp
@@ -7,59 +7,116 @@ SCENARIO("network is read from istream")
{
GIVEN("an empty config file")
{
- std::stringstream file;
- file << "" << std::endl;
+ std::stringstream file;
+ file << "" << std::endl;
- WHEN ("the network is initialized")
- {
- NeuralNetwork network(std::move(file), 1, 2);
+ 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);
- }
- }
+ 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;
+ 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);
+ 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);
- }
- }
+ THEN("the network is constructed correctly")
+ {
+ REQUIRE(network.linkExists("s0", "n3", 0.5));
+ REQUIRE(network.linkExists("n3", "n1", 1));
+ REQUIRE(network.linkExists("b0", "n0", 0.4));
+ REQUIRE(network.linkExists("b0", "n3", 0.5));
+ }
+ THEN("The network evaluates 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;
+ 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);
+ 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);
- }
- }
+ THEN("the network is constructed correctly")
+ {
+ network.setInput(0, 1);
+ REQUIRE(network.findMaxOutputIndex() == 1);
+ }
+ }
+ }
+
+ GIVEN("my handcoded config file")
+ {
+ std::stringstream file;
+ file << "b0 n0 20" << std::endl;
+ file << "s55 n3 10" << std::endl;
+ file << "b0 n4 -10" << std::endl;
+ file << "s59 n4 -50" << std::endl;
+ file << "s60 n4 20" << std::endl;
+ file << "b0 n6 10" << std::endl;
+ file << "s51 n6 -10" << std::endl;
+ file << "s53 n6 -10" << std::endl;
+ file << "n3 n0 -20" << std::endl;
+ file << "n4 n0 -20" << std::endl;
+ file << "n6 n0 -20" << std::endl;
+ file << "n3 n4 -20" << std::endl;
+ file << "n6 n3 -20" << std::endl;
+ file << "n6 n4 -20" << std::endl;
+
+ WHEN("the netwok is constructed")
+ {
+ std::vector<bool> sensors(61);
+
+ NeuralNetwork network(std::move(file), sensors, 7);
+ THEN("it is constructred correctly")
+ {
+ REQUIRE(network.linkExists("b0", "n0", 20));
+ REQUIRE(network.linkExists("s55", "n3", 10));
+ REQUIRE(network.linkExists("b0", "n4", -10));
+ REQUIRE(network.linkExists("s59", "n4", -50));
+ REQUIRE(network.linkExists("s60", "n4", 20));
+ REQUIRE(network.linkExists("b0", "n6", 10));
+ REQUIRE(network.linkExists("s51", "n6", -10));
+ REQUIRE(network.linkExists("s53", "n6", -10));
+ REQUIRE(network.linkExists("n3", "n0", -20));
+ REQUIRE(network.linkExists("n4", "n0", -20));
+ REQUIRE(network.linkExists("n6", "n0", -20));
+ REQUIRE(network.linkExists("n3", "n4", -20));
+ REQUIRE(network.linkExists("n6", "n3", -20));
+ REQUIRE(network.linkExists("n6", "n4", -20));
+ }
+
+ THEN("it has the right number of nodes and sensors")
+ {
+ REQUIRE(network.numberOfSensors() == 61);
+ REQUIRE(network.numberOfOutputs() == 7);
+ REQUIRE(network.numberOfNeurons() == 7);
+ }
+ }
}
}