Skip to content

Commit

Permalink
Merge pull request #15 from openworm/experimental
Browse files Browse the repository at this point in the history
More tests & properly initialising AVA_inact etc.
  • Loading branch information
pgleeson authored Jan 8, 2025
2 parents 6ec1e08 + ccd94a6 commit eba46bf
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/workflows/ci-make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
- name: C++ info
run: g++ -v

- name: Run C++ tests
run: |
make tests
./tests
- name: Test makefile
run: make

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/seed.dat
/__pycache__
/testExample
/tests
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ 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
g++ -c -O3 -flto tests.cpp
tests: tests.o
g++ -pthread -o tests tests.o
clean:
rm *.o main
rm -f *.o main tests
8 changes: 8 additions & 0 deletions Worm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ int nn(int neuronNumber, int unitNumber)
// The constructor
Worm::Worm(TVector<double> &v,double output)
{

// PG: Setting these to zero as they were not initialised before use!
// Note: the usage of these needs to be further investigated!
AVA_act = 0;
AVA_inact = 0;
AVB_act = 0;
AVB_inact = 0;

// Muscles
m.SetMuscleParams(N_muscles, T_muscle);

Expand Down
4 changes: 4 additions & 0 deletions test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
set -ex

make clean
make tests

./tests

make

rm -rf exampleRun
Expand Down
39 changes: 39 additions & 0 deletions tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// =============================================================
// Tests for C++ code
// =============================================================

#include <iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include "TSearch.h"
#include <cassert>



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

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

std::cout << clip(10, -10, 20) << std::endl;

assert(clip(10, -10, 20) == 10.0);
assert(clip(1, -1, 1) == 1);
assert(clip(-1.1, -1, 1) == -1);
assert(clip(0, -1, 1) == 0);
assert(clip(0, 1, 1) == 1);

std::cout << MapSearchParameter(-1, 0, 10, -1.0e99, 1.0e99) << std::endl;

assert( MapSearchParameter(-1, 0, 10) == 0);
assert( MapSearchParameter(1, 0, 10) == 10);
assert( MapSearchParameter(1, 0, 10, -5,5) == 5);

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

return 0;
}

0 comments on commit eba46bf

Please sign in to comment.