Exemplo n.º 1
0
BOOST_FIXTURE_TEST_CASE(UserInformation, Fixture)
{
    odil::pdu::AAssociateAC pdu;
    BOOST_REQUIRE_THROW(pdu.get_user_information(), odil::Exception);
    pdu.set_user_information(user_information);
    this->check_user_information(pdu.get_user_information());
}
Exemplo n.º 2
0
BOOST_FIXTURE_TEST_CASE(ApplicationContext, Fixture)
{
    odil::pdu::AAssociateAC pdu;
    BOOST_REQUIRE_THROW(pdu.get_application_context(), odil::Exception);
    pdu.set_application_context(application_context);
    this->check_application_context(pdu.get_application_context());
}
Exemplo n.º 3
0
/* Too long STDP window (considering max network delay) should throw */
void
testInvalidDynamicLength(bool stdp)
{
	nemo::Configuration conf;
	if(stdp) {
		std::vector<float> pre  = standardStdpPre(1.0, 31);
		std::vector<float> post = standardStdpPost(1.0, 31);
		conf.setStdpFunction(pre, post, 0.01f,  1.0f, -0.01f, -1.0f);
	}

	nemo::Network net;
	unsigned iz = net.addNeuronType("Izhikevich");
	float param[7] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
	net.addNeuron(iz, 0, 7, param);
	net.addNeuron(iz, 1, 7, param);
	net.addSynapse(0, 1, 34, 1.0, stdp);

	boost::scoped_ptr<nemo::Simulation> sim;

	if(stdp) {
		BOOST_REQUIRE_THROW(sim.reset(nemo::simulation(net, conf)), nemo::exception);
	} else {
		BOOST_REQUIRE_NO_THROW(sim.reset(nemo::simulation(net, conf)));
	}
}
//**********************************************************************
//
//
//**********************************************************************
BOOST_FIXTURE_TEST_CASE( AllValuesBoundedSelectivity, CWorld_Fixture ) {

  CSelectivity *pSelectivity = 0;
  BOOST_REQUIRE_NO_THROW(pSelectivity = CSelectivityFactory::buildSelectivity(PARAM_ALL_VALUES_BOUNDED, false));

  pSelectivity->addParameter(PARAM_LABEL, "selectivity");
  pSelectivity->addParameter(PARAM_L, "1");
  pSelectivity->addParameter(PARAM_H, "10");

  for (int i = 0; i < 9; ++i)
    pSelectivity->addParameter(PARAM_V, boost::lexical_cast<string>(i*2));

  pSelectivity->validate();
  BOOST_REQUIRE_NO_THROW(pSelectivity->validate());
  BOOST_REQUIRE_NO_THROW(pSelectivity->build());

  BOOST_CHECK_EQUAL(pSelectivity->getResult(0), 0.0);
  BOOST_CHECK_EQUAL(pSelectivity->getResult(1), 2.0);
  BOOST_CHECK_EQUAL(pSelectivity->getResult(2), 4.0);
  BOOST_CHECK_EQUAL(pSelectivity->getResult(3), 6.0);
  BOOST_CHECK_EQUAL(pSelectivity->getResult(4), 8.0);
  BOOST_CHECK_EQUAL(pSelectivity->getResult(5), 10.0);
  BOOST_CHECK_EQUAL(pSelectivity->getResult(6), 12.0);
  BOOST_CHECK_EQUAL(pSelectivity->getResult(7), 14.0);
  BOOST_CHECK_EQUAL(pSelectivity->getResult(8), 16.0);
  BOOST_CHECK_EQUAL(pSelectivity->getResult(9), 16.0);
  BOOST_CHECK_EQUAL(pSelectivity->getResult(10), 16.0);

  BOOST_CHECK_EQUAL(pSelectivity->getResult(19), 16.0);

  BOOST_REQUIRE_THROW(pSelectivity->getResult(20), std::string);

  delete pSelectivity;
}
Exemplo n.º 5
0
/* Make sure that calling applyStdp gives an error */
void
testInvalidStdpUsage(backend_t backend)
{
	boost::scoped_ptr<nemo::Network> net(createRing(10, 0, true));
	nemo::Configuration conf;
	setBackend(backend, conf);
	BOOST_REQUIRE_THROW(simpleStdpRun(*net, conf), nemo::exception);
}
Exemplo n.º 6
0
/* Too long STDP window (on its own) should throw */
void
testInvalidStaticLength()
{
	nemo::Configuration conf;
	std::vector<float> pre  = standardStdpPre(1.0, 35);
	std::vector<float> post = standardStdpPost(1.0, 35);
	BOOST_REQUIRE_THROW(conf.setStdpFunction(pre, post, 0.01f,  1.0f, -0.01f, -1.0f), nemo::exception);
}
Exemplo n.º 7
0
void checkModelMethodForThrow(
    Implementation::Model* model,
    Func model_method,
    int arg1,
    int arg2
) {
    BOOST_REQUIRE_THROW(
        ((*model).*model_method)(arg1, arg2), Exception
    );
}
Exemplo n.º 8
0
void checkModelMethodForThrow<IntThreeArgsMethod>(
    Implementation::Model* model,
    IntThreeArgsMethod model_method,
    int arg1,
    int arg2
) {
    int spec = 0;
    BOOST_REQUIRE_THROW(
        ((*model).*model_method)(arg1, arg2, spec), Exception
    );
}
Exemplo n.º 9
0
void checkModelMethodForThrow<ThreeArgsMethod>(
    Implementation::Model* model,
    ThreeArgsMethod model_method,
    int arg1,
    int arg2
) {
    Abstract::Point coordinates(0, 0);
    BOOST_REQUIRE_THROW(
        ((*model).*model_method)(arg1, arg2, coordinates), Exception
    );
}
Exemplo n.º 10
0
static void checkOneArgMethod(
    Implementation::Model* model,
    Func model_method,
    int arg1,
    int arg2
) {
    Abstract::Point coordinates(arg1, arg2);
    BOOST_REQUIRE_THROW(
        ((*model).*model_method)(coordinates), Exception
    );
}
Exemplo n.º 11
0
BOOST_FIXTURE_TEST_CASE_TEMPLATE(NamingConventions, T, ConventionsDatasets, T)
{
  // // These octets are obtained by the snippet below.
  // // This check is intended to detect unexpected encoding change in the future.
  // for (typename T::Dataset::const_iterator it = this->dataset.begin();
  //      it != this->dataset.end(); ++it) {
  //   Name name;
  //   name.append(it->template get<0>()(it->template get<4>()));
  //   std::cout << name << std::endl;
  // }

  name::Component invalidComponent1;
  name::Component invalidComponent2("1234567890");

  for (typename T::Dataset::const_iterator it = this->dataset.begin();
       it != this->dataset.end(); ++it) {
    const Name& expected = it->template get<3>();
    BOOST_TEST_MESSAGE("Check " << expected[0].toUri());

    BOOST_CHECK_EQUAL(expected[0].isGeneric(), true);

    name::Component actualComponent = it->template get<0>()(it->template get<4>());
    BOOST_CHECK_EQUAL(actualComponent, expected[0]);

    Name actualName;
    it->template get<2>()(actualName, it->template get<4>());
    BOOST_CHECK_EQUAL(actualName, expected);

    BOOST_CHECK_EQUAL(it->template get<5>()(expected[0]), true);
    BOOST_REQUIRE_NO_THROW(it->template get<1>()(expected[0]));
    BOOST_CHECK_EQUAL(it->template get<1>()(expected[0]), it->template get<4>());

    BOOST_CHECK_EQUAL(it->template get<5>()(invalidComponent1), false);
    BOOST_CHECK_EQUAL(it->template get<5>()(invalidComponent2), false);

    BOOST_REQUIRE_THROW(it->template get<1>()(invalidComponent1), name::Component::Error);
    BOOST_REQUIRE_THROW(it->template get<1>()(invalidComponent2), name::Component::Error);
  }
}
Exemplo n.º 12
0
void
testInvalidNeuronType()
{
	nemo::Network net;
	unsigned iz = net.addNeuronType("Izhikevich");
	float args[7] = {0, 0, 0, 0, 0, 0, 0};
	for(unsigned n=0; n<100; ++n) {
		if(n != iz) {
			// incorrect parameter order for n and iz.
			BOOST_REQUIRE_THROW(net.addNeuron(n, iz, 7, args), nemo::exception);
		}
	}
}
Exemplo n.º 13
0
int test_main( int, char* [] )
{
  InvalidResultCopyTest machine;
  machine.initiate();

  #ifdef NDEBUG
    BOOST_REQUIRE_NO_THROW( machine.process_event( E() ) );
  #else
    BOOST_REQUIRE_THROW( machine.process_event( E() ), std::logic_error );
  #endif

  return 0;
}
Exemplo n.º 14
0
void
testInvalidCurrentStimulus(backend_t backend)
{
	unsigned ncount = 1000U;
	nemo::Configuration conf = configuration(false, 1024, backend);
	boost::scoped_ptr<nemo::Network> net(createRing(ncount));
	boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(*net, conf));

	sim->step();
	sim->step();

	nemo::Simulation::current_stimulus istim;
	istim.push_back(std::make_pair(ncount+1, 0.5));
	BOOST_REQUIRE_THROW(sim->step(istim), nemo::exception);
}
Exemplo n.º 15
0
int test_main( int, char* [] )
{
  DeferralTest machine;
  machine.initiate();
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 0 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 0 );
  machine.process_event( *MakeIntrusive( new EvLeafDeferred() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 0 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 1 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 1 );
  machine.process_event( *MakeIntrusive( new EvLeafDeferred() ) );
  machine.process_event( *MakeIntrusive( new EvLeafDeferred() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 1 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 3 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 3 );
  machine.process_event( *MakeIntrusive( new EvNodeDeferred() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 3 );
  machine.process_event( *MakeIntrusive( new EvSwitch() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 3 );
  machine.process_event( EvNodeDeferred() );
  BOOST_REQUIRE( machine.ProcessedCount() == 3 );
  machine.process_event( *MakeIntrusive( new EvDestroy() ) );
  BOOST_REQUIRE( machine.ProcessedCount() == 5 );


  DeferralEventBaseTest eventBaseMachine;
  // state_cast sanity check
  BOOST_REQUIRE_THROW( eventBaseMachine.state_cast< const X1 & >(), std::bad_cast );
  eventBaseMachine.initiate();
  BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X1 & >() );
  // Deferral must work with heap-allocated and stack-allocated events
  eventBaseMachine.process_event( EvToX3() );
  BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X1 & >() );
  eventBaseMachine.process_event( EvToX2() );
  BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X3 & >() );
  eventBaseMachine.initiate();
  BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X1 & >() );
  eventBaseMachine.process_event( EvToX2() );
  BOOST_REQUIRE_NO_THROW( eventBaseMachine.state_cast< const X2 & >() );

  return 0;
}
Exemplo n.º 16
0
void
testWriteOnlySynapses(backend_t backend)
{
	bool stdp = false;
	nemo::Configuration conf = configuration(stdp, 1024, backend);
	conf.setWriteOnlySynapses();
	boost::scoped_ptr<nemo::Network> net(createRing(10, 0, true));
	boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(*net, conf));
	sim->step();
	BOOST_REQUIRE_THROW(const std::vector<synapse_id> ids = sim->getSynapsesFrom(0), nemo::exception);

	/* so, we cant use getSynapsesFrom, but create a synapse id anyway */
	nidx_t neuron = 1;
	unsigned synapse = 0;
	synapse_id id = (uint64_t(neuron) << 32) | uint64_t(synapse);

	BOOST_REQUIRE_THROW(sim->getSynapseWeight(id), nemo::exception);
}
Exemplo n.º 17
0
void checkModelMethodForThrow<MultiArgsMethod>(
    Implementation::Model* model,
    MultiArgsMethod model_method,
    int arg1,
    int arg2
) {
    Abstract::Point coordinates(arg1, arg2);
    BOOST_REQUIRE_THROW(
        ((*model).*model_method)(
            coordinates,
            DEFAULT_MASS,
            0,
            0,
            0
        ),
        Exception
    );
}
Exemplo n.º 18
0
void
testGetSynapsesFromUnconnectedNeuron(backend_t backend)
{
	nemo::Network net;
	for(int nidx = 0; nidx < 4; ++nidx) {
		net.addNeuron(nidx, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f);
	}
	nemo::Configuration conf = configuration(false, 1024, backend);
	boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(net, conf));
	sim->step();

	/* If neuron is invalid we should throw */
	BOOST_REQUIRE_THROW(sim->getSynapsesFrom(4), nemo::exception);

	/* However, if neuron is unconnected, we should get an empty list */
	std::vector<synapse_id> ids;
	BOOST_REQUIRE_NO_THROW(ids = sim->getSynapsesFrom(3));
	BOOST_REQUIRE(ids.size() == 0);
}
Exemplo n.º 19
0
/* Mixing up excitatory and inhibitory limits should throw */
void
testInvalidBounds()
{
	nemo::Configuration conf;
	std::vector<float> pre  = standardStdpPre(1.0, 20);
	std::vector<float> post = standardStdpPost(1.0, 20);

	// negative excitatory
	BOOST_REQUIRE_THROW(conf.setStdpFunction(pre, post, -0.01f,  1.0f, -0.01f, -1.0f), nemo::exception);
	BOOST_REQUIRE_THROW(conf.setStdpFunction(pre, post,  0.01f, -1.0f, -0.01f, -1.0f), nemo::exception);
	BOOST_REQUIRE_THROW(conf.setStdpFunction(pre, post, -0.01f, -1.0f, -0.01f, -1.0f), nemo::exception);

	// positive inhibitory
	BOOST_REQUIRE_THROW(conf.setStdpFunction(pre, post, 0.01f, 1.0f,  0.01f, -1.0f), nemo::exception);
	BOOST_REQUIRE_THROW(conf.setStdpFunction(pre, post, 0.01f, 1.0f, -0.01f,  1.0f), nemo::exception);
	BOOST_REQUIRE_THROW(conf.setStdpFunction(pre, post, 0.01f, 1.0f,  0.01f,  1.0f), nemo::exception);

	// incorrect order of excitatory
	BOOST_REQUIRE_THROW(conf.setStdpFunction(pre, post, 1.0f, 0.01f, -0.01f, -1.0), nemo::exception);

	// incorrect order of inhibitory
	BOOST_REQUIRE_THROW(conf.setStdpFunction(pre, post, 0.01f, 1.0f, -1.0f, -0.01f), nemo::exception);
}
Exemplo n.º 20
0
void TestTransitions( M & machine )
{
  machine.initiate();
  ActionArray init = 
  {
    Entry< S0< M > >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    Entry< S11< M > >,
    Entry< Default2< S1< M > > >,
    Entry< Default1< S0< M > > >,
    Entry< Default2< S0< M > > >
  };
  machine.CompareToExpectedActionSequence( init );

  machine.process_event( A() );
  ActionArray a1 =
  {
    Exit< Default2< S1< M > > >,
    Exit< S11< M > >,
    Exit< Default0< S1< M > > >,
    Exit< S1< M > >,
    Trans< S0< M >, A >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    Entry< S11< M > >,
    Entry< Default2< S1< M > > >
  };
  machine.CompareToExpectedActionSequence( a1 );

  machine.process_event( B() );
  ActionArray b1 =
  {
    Exit< Default2< S1< M > > >,
    Exit< S11< M > >,
    Exit< Default0< S1< M > > >,
    Exit< S1< M > >,
    Trans< S0< M >, B >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    Entry< S11< M > >,
    Entry< Default2< S1< M > > >
  };
  machine.CompareToExpectedActionSequence( b1 );

  machine.process_event( C() );
  ActionArray c1 =
  {
    Exit< Default2< S1< M > > >,
    Exit< S11< M > >,
    Exit< Default0< S1< M > > >,
    Exit< S1< M > >,
    Trans< S0< M >, C >,
    Entry< S2< M > >,
    Entry< Default0< S2< M > > >,
    Entry< Default1< S2< M > > >,
    Entry< S21< M > >,
    Entry< Default0< S21< M > > >,
    Entry< S211< M > >,
    Entry< Default2< S21< M > > >
  };
  machine.CompareToExpectedActionSequence( c1 );

  machine.process_event( D() );
  ActionArray d2 =
  {
    Exit< Default2< S21< M > > >,
    Exit< S211< M > >,
    Exit< Default0< S21< M > > >,
    Exit< S21< M > >,
    Trans< S0< M >, D >,
    Entry< S21< M > >,
    Entry< Default0< S21< M > > >,
    Entry< S211< M > >,
    Entry< Default2< S21< M > > >
  };
  machine.CompareToExpectedActionSequence( d2 );

  machine.process_event( E() );
  ActionArray e2 =
  {
    Exit< Default2< S0< M > > >,
    Exit< Default1< S0< M > > >,
    Exit< Default2< S21< M > > >,
    Exit< S211< M > >,
    Exit< Default0< S21< M > > >,
    Exit< S21< M > >,
    Exit< Default1< S2< M > > >,
    Exit< Default0< S2< M > > >,
    Exit< S2< M > >,
    Exit< S0< M > >,
    Entry< S0< M > >,
    Entry< S2< M > >,
    Entry< Default0< S2< M > > >,
    Entry< Default1< S2< M > > >,
    Entry< S21< M > >,
    Entry< Default0< S21< M > > >,
    Entry< S211< M > >,
    Entry< Default2< S21< M > > >,
    Entry< Default1< S0< M > > >,
    Entry< Default2< S0< M > > >
  };
  machine.CompareToExpectedActionSequence( e2 );

  machine.process_event( F() );
  ActionArray f2 =
  {
    Exit< Default2< S21< M > > >,
    Exit< S211< M > >,
    Exit< Default0< S21< M > > >,
    Exit< S21< M > >,
    Exit< Default1< S2< M > > >,
    Exit< Default0< S2< M > > >,
    Exit< S2< M > >,
    Trans< S0< M >, F >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    Entry< S11< M > >,
    Entry< Default2< S1< M > > >
  };
  machine.CompareToExpectedActionSequence( f2 );

  machine.process_event( G() );
  ActionArray g1 =
  {
    Exit< Default2< S1< M > > >,
    Exit< S11< M > >,
    Exit< Default0< S1< M > > >,
    Exit< S1< M > >,
    Trans< S0< M >, G >,
    Entry< S2< M > >,
    Entry< Default0< S2< M > > >,
    Entry< Default1< S2< M > > >,
    Entry< S21< M > >,
    Entry< Default0< S21< M > > >,
    Entry< S211< M > >,
    Entry< Default2< S21< M > > >
  };
  machine.CompareToExpectedActionSequence( g1 );

  machine.process_event( H() );
  ActionArray h2 =
  {
    Exit< Default2< S21< M > > >,
    Exit< S211< M > >,
    Exit< Default0< S21< M > > >,
    Exit< S21< M > >,
    Trans< S0< M >, H >,
    Entry< S21< M > >,
    Entry< Default0< S21< M > > >,
    Entry< S211< M > >,
    Entry< Default2< S21< M > > >
  };
  machine.CompareToExpectedActionSequence( h2 );

  BOOST_REQUIRE( machine.GetUnconsumedEventCount() == 0 );
  machine.process_event( A() );
  BOOST_REQUIRE( machine.GetUnconsumedEventCount() == 1 );
  ActionArray a2 =
  {
  };
  machine.CompareToExpectedActionSequence( a2 );

  machine.process_event( B() );
  ActionArray b2 =
  {
    Exit< Default2< S21< M > > >,
    Exit< S211< M > >,
    Exit< Default0< S21< M > > >,
    Exit< S21< M > >,
    Trans< S0< M >, B >,
    Entry< S21< M > >,
    Entry< Default0< S21< M > > >,
    Entry< S211< M > >,
    Entry< Default2< S21< M > > >
  };
  machine.CompareToExpectedActionSequence( b2 );

  machine.process_event( C() );
  ActionArray c2 =
  {
    Exit< Default2< S21< M > > >,
    Exit< S211< M > >,
    Exit< Default0< S21< M > > >,
    Exit< S21< M > >,
    Exit< Default1< S2< M > > >,
    Exit< Default0< S2< M > > >,
    Exit< S2< M > >,
    Trans< S0< M >, C >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    Entry< S11< M > >,
    Entry< Default2< S1< M > > >
  };
  machine.CompareToExpectedActionSequence( c2 );

  machine.process_event( D() );
  ActionArray d1 = 
  {
    Exit< Default2< S0< M > > >,
    Exit< Default1< S0< M > > >,
    Exit< Default2< S1< M > > >,
    Exit< S11< M > >,
    Exit< Default0< S1< M > > >,
    Exit< S1< M > >,
    Exit< S0< M > >,
    Entry< S0< M > >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    Entry< S11< M > >,
    Entry< Default2< S1< M > > >,
    Entry< Default1< S0< M > > >,
    Entry< Default2< S0< M > > >
  };
  machine.CompareToExpectedActionSequence( d1 );

  machine.process_event( F() );
  ActionArray f1 =
  {
    Exit< Default2< S1< M > > >,
    Exit< S11< M > >,
    Exit< Default0< S1< M > > >,
    Exit< S1< M > >,
    Trans< S0< M >, F >,
    Entry< S2< M > >,
    Entry< Default0< S2< M > > >,
    Entry< Default1< S2< M > > >,
    Entry< S21< M > >,
    Entry< Default0< S21< M > > >,
    Entry< S211< M > >,
    Entry< Default2< S21< M > > >
  };
  machine.CompareToExpectedActionSequence( f1 );

  machine.process_event( G() );
  ActionArray g2 =
  {
    Exit< Default2< S0< M > > >,
    Exit< Default1< S0< M > > >,
    Exit< Default2< S21< M > > >,
    Exit< S211< M > >,
    Exit< Default0< S21< M > > >,
    Exit< S21< M > >,
    Exit< Default1< S2< M > > >,
    Exit< Default0< S2< M > > >,
    Exit< S2< M > >,
    Exit< S0< M > >,
    Entry< S0< M > >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    Entry< S11< M > >,
    Entry< Default2< S1< M > > >,
    Entry< Default1< S0< M > > >,
    Entry< Default2< S0< M > > >
  };
  machine.CompareToExpectedActionSequence( g2 );

  machine.process_event( H() );
  ActionArray h1 =
  {
    Trans< S11< M >, H >
  };
  machine.CompareToExpectedActionSequence( h1 );

  machine.process_event( E() );
  ActionArray e1 =
  {
    Exit< Default2< S0< M > > >,
    Exit< Default1< S0< M > > >,
    Exit< Default2< S1< M > > >,
    Exit< S11< M > >,
    Exit< Default0< S1< M > > >,
    Exit< S1< M > >,
    Exit< S0< M > >,
    Entry< S0< M > >,
    Entry< S2< M > >,
    Entry< Default0< S2< M > > >,
    Entry< Default1< S2< M > > >,
    Entry< S21< M > >,
    Entry< Default0< S21< M > > >,
    Entry< S211< M > >,
    Entry< Default2< S21< M > > >,
    Entry< Default1< S0< M > > >,
    Entry< Default2< S0< M > > >
  };
  machine.CompareToExpectedActionSequence( e1 );

  machine.terminate();
  ActionArray term =
  {
    Exit< Default2< S0< M > > >,
    Exit< Default1< S0< M > > >,
    Exit< Default2< S21< M > > >,
    Exit< S211< M > >,
    Exit< Default0< S21< M > > >,
    Exit< S21< M > >,
    Exit< Default1< S2< M > > >,
    Exit< Default0< S2< M > > >,
    Exit< S2< M > >,
    Exit< S0< M > >
  };
  machine.CompareToExpectedActionSequence( term );

  machine.ThrowAction( &Entry< Default0< S1< M > > > );
  BOOST_REQUIRE_THROW( machine.initiate(), TransitionTestException );
  ActionArray initThrow1 = 
  {
    Entry< S0< M > >,
    Entry< S1< M > >,
    &::Throw< &::Entry< Default0< S1< M > > > >,
    Dtor< S1< M > >,
    Dtor< S0< M > >
  };
  machine.CompareToExpectedActionSequence( initThrow1 );
  BOOST_REQUIRE( machine.terminated() );

  machine.ThrowAction( &Entry< S11< M > > );
  BOOST_REQUIRE_THROW( machine.initiate(), TransitionTestException );
  ActionArray initThrow2 = 
  {
    Entry< S0< M > >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    &::Throw< &::Entry< S11< M > > >,
    Dtor< Default0< S1< M > > >,
    Dtor< S1< M > >,
    Dtor< S0< M > >
  };
  machine.CompareToExpectedActionSequence( initThrow2 );
  BOOST_REQUIRE( machine.terminated() );

  machine.ThrowAction( &Trans< S0< M >, A > );
  machine.initiate();
  BOOST_REQUIRE_THROW( machine.process_event( A() ), TransitionTestException );
  ActionArray a1Throw1 =
  {
    Entry< S0< M > >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    Entry< S11< M > >,
    Entry< Default2< S1< M > > >,
    Entry< Default1< S0< M > > >,
    Entry< Default2< S0< M > > >,
    Exit< Default2< S1< M > > >,
    Exit< S11< M > >,
    Exit< Default0< S1< M > > >,
    Exit< S1< M > >,
    &::Throw< &::Trans< S0< M >, A > >,
    Dtor< Default2< S0< M > > >,
    Dtor< Default1< S0< M > > >,
    Dtor< S0< M > >
  };
  machine.CompareToExpectedActionSequence( a1Throw1 );
  BOOST_REQUIRE( machine.terminated() );

  machine.ThrowAction( &Entry< S211< M > > );
  machine.initiate();
  BOOST_REQUIRE_THROW( machine.process_event( C() ), TransitionTestException );
  ActionArray c1Throw1 =
  {
    Entry< S0< M > >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    Entry< S11< M > >,
    Entry< Default2< S1< M > > >,
    Entry< Default1< S0< M > > >,
    Entry< Default2< S0< M > > >,
    Exit< Default2< S1< M > > >,
    Exit< S11< M > >,
    Exit< Default0< S1< M > > >,
    Exit< S1< M > >,
    Trans< S0< M >, C >,
    Entry< S2< M > >,
    Entry< Default0< S2< M > > >,
    Entry< Default1< S2< M > > >,
    Entry< S21< M > >,
    Entry< Default0< S21< M > > >,
    &::Throw< &::Entry< S211< M > > >,
    Dtor< Default2< S0< M > > >,
    Dtor< Default1< S0< M > > >,
    Dtor< Default0< S21< M > > >,
    Dtor< S21< M > >,
    Dtor< Default1< S2< M > > >,
    Dtor< Default0< S2< M > > >,
    Dtor< S2< M > >,
    Dtor< S0< M > >
  };
  machine.CompareToExpectedActionSequence( c1Throw1 );
  BOOST_REQUIRE( machine.terminated() );

  machine.ThrowAction( &ExitFn< S11< M > > );
  machine.initiate();
  BOOST_REQUIRE_THROW( machine.process_event( C() ), TransitionTestException );
  ActionArray c1Throw2 =
  {
    Entry< S0< M > >,
    Entry< S1< M > >,
    Entry< Default0< S1< M > > >,
    Entry< S11< M > >,
    Entry< Default2< S1< M > > >,
    Entry< Default1< S0< M > > >,
    Entry< Default2< S0< M > > >,
    Exit< Default2< S1< M > > >,
    &::Throw< &::ExitFn< S11< M > > >,
    Dtor< S11< M > >,
    Dtor< Default2< S0< M > > >,
    Dtor< Default1< S0< M > > >,
    Dtor< Default0< S1< M > > >,
    Dtor< S1< M > >,
    Dtor< S0< M > >
  };
  machine.CompareToExpectedActionSequence( c1Throw2 );
  BOOST_REQUIRE( machine.terminated() );
  BOOST_REQUIRE( machine.GetUnconsumedEventCount() == 1 );
}
Exemplo n.º 21
0
/* Both the simulation and network classes have neuron setters. Here we perform
 * the same test for both. */
void
testSetNeuron(backend_t backend)
{
	float a = 0.02f;
	float b = 0.2f;
	float c = -65.0f+15.0f*0.25f;
	float d = 8.0f-6.0f*0.25f;
	float v = -65.0f;
	float u = b * v;
	float sigma = 5.0f;

	/* Create a minimal network with a single neuron */
	nemo::Network net;

	/* setNeuron should only succeed for existing neurons */
	BOOST_REQUIRE_THROW(net.setNeuron(0, a, b, c, d, u, v, sigma), nemo::exception);

	net.addNeuron(0, a, b, c-0.1f, d, u, v-1.0f, sigma);

	/* Invalid neuron */
	BOOST_REQUIRE_THROW(net.getNeuronParameter(1, 0), nemo::exception);
	BOOST_REQUIRE_THROW(net.getNeuronState(1, 0), nemo::exception);

	/* Invalid parameter */
	BOOST_REQUIRE_THROW(net.getNeuronParameter(0, 5), nemo::exception);
	BOOST_REQUIRE_THROW(net.getNeuronState(0, 2), nemo::exception);

	float e = 0.1f;
	BOOST_REQUIRE_NO_THROW(net.setNeuron(0, a-e, b-e, c-e, d-e, u-e, v-e, sigma-e));
	BOOST_REQUIRE_EQUAL(net.getNeuronParameter(0, 0), a-e);
	BOOST_REQUIRE_EQUAL(net.getNeuronParameter(0, 1), b-e);
	BOOST_REQUIRE_EQUAL(net.getNeuronParameter(0, 2), c-e);
	BOOST_REQUIRE_EQUAL(net.getNeuronParameter(0, 3), d-e);
	BOOST_REQUIRE_EQUAL(net.getNeuronParameter(0, 4), sigma-e);
	BOOST_REQUIRE_EQUAL(net.getNeuronState(0, 0), u-e);
	BOOST_REQUIRE_EQUAL(net.getNeuronState(0, 1), v-e);

	/* Try setting individual parameters during construction */

	net.setNeuronParameter(0, 0, a);
	BOOST_REQUIRE_EQUAL(net.getNeuronParameter(0, 0), a);

	net.setNeuronParameter(0, 1, b);
	BOOST_REQUIRE_EQUAL(net.getNeuronParameter(0, 1), b);

	net.setNeuronParameter(0, 2, c);
	BOOST_REQUIRE_EQUAL(net.getNeuronParameter(0, 2), c);

	net.setNeuronParameter(0, 3, d);
	BOOST_REQUIRE_EQUAL(net.getNeuronParameter(0, 3), d);

	net.setNeuronParameter(0, 4, sigma);
	BOOST_REQUIRE_EQUAL(net.getNeuronParameter(0, 4), sigma);

	net.setNeuronState(0, 0, u);
	BOOST_REQUIRE_EQUAL(net.getNeuronState(0, 0), u);

	net.setNeuronState(0, 1, v);
	BOOST_REQUIRE_EQUAL(net.getNeuronState(0, 1), v);

	/* Invalid neuron */
	BOOST_REQUIRE_THROW(net.setNeuronParameter(1, 0, 0.0f), nemo::exception);
	BOOST_REQUIRE_THROW(net.setNeuronState(1, 0, 0.0f), nemo::exception);

	/* Invalid parameter */
	BOOST_REQUIRE_THROW(net.setNeuronParameter(0, 5, 0.0f), nemo::exception);
	BOOST_REQUIRE_THROW(net.setNeuronState(0, 2, 0.0f), nemo::exception);

	nemo::Configuration conf = configuration(false, 1024, backend);

	/* Try setting individual parameters during simulation */
	{
		boost::scoped_ptr<nemo::Simulation> sim(simulation(net, conf));

		sim->step();

		sim->setNeuronState(0, 0, u-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronState(0, 0), u-e);

		sim->setNeuronState(0, 1, v-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronState(0, 1), v-e);

		/* Get the data back to later verify that it does in fact change during
		 * simulation, rather than being overwritten again on subsequent
		 * simulation steps */
		float u0 = sim->getNeuronState(0, 0);
		float v0 = sim->getNeuronState(0, 1);

		sim->setNeuronParameter(0, 0, a-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 0), a-e);

		sim->setNeuronParameter(0, 1, b-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 1), b-e);

		sim->setNeuronParameter(0, 2, c-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 2), c-e);

		sim->setNeuronParameter(0, 3, d-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 3), d-e);

		sim->setNeuronParameter(0, 4, sigma-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 4), sigma-e);

		sim->step();

		/* After simulating one more step all the parameter should remain the
		 * same, whereas all the state variables should have changed */
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 0), a-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 1), b-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 2), c-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 3), d-e);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 4), sigma-e);

		BOOST_REQUIRE(sim->getNeuronState(0, 0) != u0);
		BOOST_REQUIRE(sim->getNeuronState(0, 1) != v0);


		/* Invalid neuron */
		BOOST_REQUIRE_THROW(sim->setNeuronParameter(1, 0, 0.0f), nemo::exception);
		BOOST_REQUIRE_THROW(sim->setNeuronState(1, 0, 0.0f), nemo::exception);
		BOOST_REQUIRE_THROW(sim->getNeuronParameter(1, 0), nemo::exception);
		BOOST_REQUIRE_THROW(sim->getNeuronState(1, 0), nemo::exception);

		/* Invalid parameter */
		BOOST_REQUIRE_THROW(sim->setNeuronParameter(0, 5, 0.0f), nemo::exception);
		BOOST_REQUIRE_THROW(sim->setNeuronState(0, 2, 0.0f), nemo::exception);
		BOOST_REQUIRE_THROW(sim->getNeuronParameter(0, 5), nemo::exception);
		BOOST_REQUIRE_THROW(sim->getNeuronState(0, 2), nemo::exception);
	}

	float v0 = 0.0f;
	{
		boost::scoped_ptr<nemo::Simulation> sim(simulation(net, conf));
		sim->step();
		v0 = sim->getMembranePotential(0);
	}

	{
		boost::scoped_ptr<nemo::Simulation> sim(simulation(net, conf));
		BOOST_REQUIRE_EQUAL(sim->getNeuronState(0, 0), u);
		BOOST_REQUIRE_EQUAL(sim->getNeuronState(0, 1), v);
		/* Marginally change the 'c' parameter. This is only used if the neuron
		 * fires (which it shouldn't do this cycle). This modification
		 * therefore should not affect the simulation result (here measured via
		 * the membrane potential) */
		sim->setNeuron(0, a, b, c+1.0f, d, u, v, sigma);

		sim->step();

		BOOST_REQUIRE_EQUAL(v0, sim->getMembranePotential(0));

		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 0), a);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 1), b);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 2), c+1.0f);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 3), d);
		BOOST_REQUIRE_EQUAL(sim->getNeuronParameter(0, 4), sigma);
	}

	{
		/* Ensure that when setting the state variable, it is not copied
		 * multiple times */
		nemo::Network net0;
		net0.addNeuron(0, a, b, c, d, u, v, 0.0f);

		boost::scoped_ptr<nemo::Simulation> sim0(simulation(net0, conf));
		sim0->step();
		sim0->step();
		float v0 = sim0->getMembranePotential(0);

		boost::scoped_ptr<nemo::Simulation> sim1(simulation(net0, conf));
		sim1->step();
		sim1->setNeuron(0, a, b, c, d, u, v, 0.0f);
		sim1->step();
		sim1->step();
		float v1 = sim1->getMembranePotential(0);

		BOOST_REQUIRE_EQUAL(v0, v1);
	}

	{
		/* Modify membrane potential after simulation has been created.
		 * Again the result should be the same */
		nemo::Network net1;
		net1.addNeuron(0, a, b, c, d, u, v-1.0f, sigma);
		boost::scoped_ptr<nemo::Simulation> sim(simulation(net1, conf));
		sim->setNeuron(0, a, b, c, d, u, v, sigma);
		BOOST_REQUIRE_EQUAL(v, sim->getMembranePotential(0));
		sim->step();
		BOOST_REQUIRE_EQUAL(v0, sim->getMembranePotential(0));
	}
}
Exemplo n.º 22
0
BOOST_FIXTURE_TEST_CASE(ConstructorMal2Config, TestHomeAndPibFixture<DefaultPibDir>)
{
  createClientConf({"pib=pib-sqlite3:%PATH%", "tpm=just-wrong"});
  BOOST_REQUIRE_THROW(KeyChain(), KeyChain::Error); // Wrong configuration. Error expected.
}
Exemplo n.º 23
0
void checkPost(const openfluid::utils::RESTClient& Client)
{
  BOOST_REQUIRE_THROW(Client.postResource("",""), openfluid::base::FrameworkException);
}