Skip to content

Commit

Permalink
Add initial test on building, running & saving output of NervousSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Jan 8, 2025
1 parent ccd94a6 commit a9b6560
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Muscles.o: Muscles.cpp Muscles.h VectorMatrix.h random.h
g++ -c -O3 -flto Muscles.cpp
main.o: main.cpp Worm.h WormBody.h StretchReceptor.h Muscles.h TSearch.h
g++ -c -O3 -flto main.cpp
tests.o: tests.cpp
tests.o: tests.cpp NervousSystem.o random.o
g++ -c -O3 -flto tests.cpp
tests: tests.o
g++ -pthread -o tests tests.o
Expand Down
1 change: 1 addition & 0 deletions test_output/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Output of tests will be generated here...
55 changes: 51 additions & 4 deletions tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,62 @@
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include "TSearch.h"
#include <cassert>
#include "TSearch.h"
#include "NervousSystem.cpp"

void testNervousSystem()
{
NervousSystem n;
std::cout << "Created simple Nervous System..." << std::endl;
int N_units = 2;
int N_neuronsperunit = 2;
n.SetCircuitSize(N_units*N_neuronsperunit, 3, 2);

for (int i=0;i<n.size;i+=1)
{
n.SetNeuronBias(i,2);
n.SetNeuronTimeConstant(i,10);
}

n.SetNeuronExternalInput(1,2.0);

n.SetChemicalSynapseWeight(0,1,1);
n.SetChemicalSynapseWeight(1,2,1);

double Duration = 20;
const double StepSize = 0.005;

ofstream state_file("test_output/test.state.dat");
ofstream output_file("test_output/test.output.dat");

for (double t = 0.0; t <= Duration; t += StepSize) {

std::cout << "Time: "<<t<<"" << std::endl;
n.EulerStep(StepSize);
state_file << t<< " ";
output_file << t<< " ";
for (int i=0;i<n.size;i+=1)
{
double st = n.NeuronState(i);
double ou = n.NeuronOutput(i);
std::cout << " Neuron: "<<i<<", state: "<<st<<", output: "<<ou<<"" << std::endl;

state_file << st<<" ";
output_file << ou<<" ";
}
state_file << "\n";
output_file << "\n";
}
state_file.close();
output_file.close();
}

// ------------------------------------
// The main program
// ------------------------------------
int main (int argc, const char* argv[])
{

// Many more tests should be added!

std::cout << "Running a number of tests..." << std::endl;

std::cout << clip(10, -10, 20) << std::endl;
Expand All @@ -33,6 +78,8 @@ int main (int argc, const char* argv[])
assert( MapSearchParameter(1, 0, 10) == 10);
assert( MapSearchParameter(1, 0, 10, -5,5) == 5);

testNervousSystem();

std::cout << "Done!" << std::endl;

return 0;
Expand Down

0 comments on commit a9b6560

Please sign in to comment.