Skip to content

Commit

Permalink
Merge branch 'test_pg' into test_parameters_pg
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Jan 7, 2025
2 parents 783f8f3 + f5cedfb commit f26441e
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 6 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/ci-make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,41 @@ jobs:
run: brew install nlohmann-json
if: matrix.runs-on == 'macos-latest'

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

- name: Test directly running main program
run: |
./main -p 4
./main -p 6 # Note: small population of 6 for quick runtime
ls -alth
- name: Test Python command line script
run: |
pip install numpy matplotlib
python run_main.py -R 1234 -p 6 --doEvol --folderName exampleRun2
python run_main.py -R 1233 -p 6 --doEvol --folderName exampleRun2 # Note: small population of 6 for quick runtime
- name: Test using OMV
- name: Test using OMV 1
run: |
pip install OSBModelValidation
omv all -V
git diff exampleRun/phenotype.dat
- name: Test using OMV 2
run: |
# Running OMV multiple times to test whether run results are nondeterministic
omv all -V
git diff exampleRun/phenotype.dat
- name: Test using OMV 3
run: |
# Running OMV multiple times to test whether run results are nondeterministic
omv all -V
git diff exampleRun/phenotype.dat
- name: list generated files
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
/nv2.dat
/phenotype2.dat
/w_verb.dat
/exampleRun/
/tests
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,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 -f *.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
7 changes: 6 additions & 1 deletion test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
set -ex

make clean
make tests

./tests

make

rm -rf exampleRun
time python run_main.py -R 1233 -p 96 --doEvol --folderName exampleRun
#time python run_main.py -R 1233 -p 96 --doEvol --folderName exampleRun

time omv all -V
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 f26441e

Please sign in to comment.