Skip to content

Commit

Permalink
Add a first scenario for Network using CATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
utensil committed Jul 5, 2014
1 parent 21091a3 commit 0b35526
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/test/unit/NetworkTest.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "catch.hpp"

#include <nta/engine/Network.hpp>
#include <nta/engine/NuPIC.hpp>
#include <nta/engine/Region.hpp>
#include <nta/ntypes/Dimensions.hpp>

using namespace nta;

SCENARIO( "creating a network should auto-initialize NuPIC", "[network]" ) {

GIVEN( "uninitialized NuPIC" ) {

// Uninitialize NuPIC since this test checks auto-initialization
// If shutdown fails, there is probably a problem with another test which
// is not cleaning up its networks.
if (NuPIC::isInitialized())
{
NuPIC::shutdown();
}

REQUIRE(!NuPIC::isInitialized());


WHEN("creates a network") {
Network net;

THEN("NuPIC should be initialized") {
CHECK(NuPIC::isInitialized());
}

WHEN("adds a region to the network") {
Region *l1 = net.addRegion("level1", "TestNode", "");

THEN("region name should be as specified") {
CHECK("level1" == l1->getName());
}
}

AND_THEN("NuPIC should fail to shutdown") {
// Network still exists, so this should fail.
CHECK_THROWS(NuPIC::shutdown());
}
}

WHEN("No network exists") {
THEN("NuPIC can be shut down") {
// net destructor has been called so we should be able to shut down NuPIC now
CHECK_NOTHROW(NuPIC::shutdown());
}
}
}
}
1 change: 1 addition & 0 deletions src/test/unit/UnitTestRunner.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"

#include "NetworkTest.hpp"

0 comments on commit 0b35526

Please sign in to comment.