Skip to content

Commit

Permalink
Tests: various minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Oct 22, 2024
1 parent a3f72e6 commit 6c2d320
Show file tree
Hide file tree
Showing 39 changed files with 1,729 additions and 1,294 deletions.
14 changes: 7 additions & 7 deletions tests/bindings/python/test_generator_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_acoth_function_string(self):
g = GeneratorProfile()

self.assertEqual(
'double acoth(double x)\n{\n double oneOverX = 1.0/x;\n\n return 0.5*log((1.0+oneOverX)/(1.0-oneOverX));\n}\n',
'double acoth(double x)\n{\n return atanh(1.0/x);\n}\n',
g.acothFunctionString())
g.setAcothFunctionString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.acothFunctionString())
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_acsch_function_string(self):
g = GeneratorProfile()

self.assertEqual(
'double acsch(double x)\n{\n double oneOverX = 1.0/x;\n\n return log(oneOverX+sqrt(oneOverX*oneOverX+1.0));\n}\n',
'double acsch(double x)\n{\n return asinh(1.0/x);\n}\n',
g.acschFunctionString())
g.setAcschFunctionString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.acschFunctionString())
Expand Down Expand Up @@ -265,7 +265,7 @@ def test_asech_function_string(self):
g = GeneratorProfile()

self.assertEqual(
'double asech(double x)\n{\n double oneOverX = 1.0/x;\n\n return log(oneOverX+sqrt(oneOverX*oneOverX-1.0));\n}\n',
'double asech(double x)\n{\n return acosh(1.0/x);\n}\n',
g.asechFunctionString())
g.setAsechFunctionString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.asechFunctionString())
Expand Down Expand Up @@ -1285,7 +1285,7 @@ def test_max_function_string(self):

g = GeneratorProfile()

self.assertEqual('double max(double x, double y)\n{\n return (x > y)?x:y;\n}\n', g.maxFunctionString())
self.assertEqual('', g.maxFunctionString())
g.setMaxFunctionString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.maxFunctionString())

Expand All @@ -1294,7 +1294,7 @@ def test_max_string(self):

g = GeneratorProfile()

self.assertEqual('max', g.maxString())
self.assertEqual('fmax', g.maxString())
g.setMaxString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.maxString())

Expand All @@ -1303,7 +1303,7 @@ def test_min_function_string(self):

g = GeneratorProfile()

self.assertEqual('double min(double x, double y)\n{\n return (x < y)?x:y;\n}\n', g.minFunctionString())
self.assertEqual('', g.minFunctionString())
g.setMinFunctionString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.minFunctionString())

Expand All @@ -1312,7 +1312,7 @@ def test_min_string(self):

g = GeneratorProfile()

self.assertEqual('min', g.minString())
self.assertEqual('fmin', g.minString())
g.setMinString(GeneratorProfileTestCase.VALUE)
self.assertEqual(GeneratorProfileTestCase.VALUE, g.minString())

Expand Down
41 changes: 20 additions & 21 deletions tests/coverage/coverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,10 @@ TEST(Coverage, generator)

EXPECT_EQ(size_t(1), analyserModel->stateCount());
EXPECT_EQ(size_t(7), analyserModel->constantCount());
EXPECT_EQ(size_t(199), analyserModel->computedConstantCount());
EXPECT_EQ(size_t(2), analyserModel->algebraicCount());
EXPECT_EQ(size_t(207), analyserModel->computedConstantCount());
EXPECT_EQ(size_t(5), analyserModel->algebraicCount());
EXPECT_EQ(size_t(1), analyserModel->externalCount());
EXPECT_EQ(size_t(203), analyserModel->equationCount());
EXPECT_EQ(size_t(214), analyserModel->equationCount());

EXPECT_NE(nullptr, analyserModel->voi());
EXPECT_EQ(size_t(0), analyserModel->voi()->equationCount());
Expand All @@ -627,6 +627,7 @@ TEST(Coverage, generator)
EXPECT_EQ(size_t(1), analyserModel->equation(0)->states().size());
EXPECT_NE(nullptr, analyserModel->equation(0)->state(0));
EXPECT_EQ(nullptr, analyserModel->equation(0)->state(analyserModel->equation(0)->stateCount()));
/*---GRY--- STILL NEEDED?
EXPECT_NE(nullptr, analyserModel->equation(199));
EXPECT_NE(size_t(0), analyserModel->equation(199)->dependencyCount());
EXPECT_NE(size_t(0), analyserModel->equation(199)->dependencies().size());
Expand All @@ -649,6 +650,7 @@ TEST(Coverage, generator)
EXPECT_EQ(nullptr, analyserModel->equation(199)->external(0));
EXPECT_EQ(nullptr, analyserModel->equation(199)->external(analyserModel->equation(199)->externalCount()));
EXPECT_EQ(nullptr, analyserModel->equation(analyserModel->equationCount()));
*/

for (const auto &equation : analyserModel->equations()) {
checkAstTypeAsString(equation->ast());
Expand All @@ -666,9 +668,11 @@ TEST(Coverage, generator)
EXPECT_NE(nullptr, analyserModel->constant(i)->initialisingVariable());
}

/*---GRY--- STILL NEEDED?
for (size_t i = 0; i < analyserModel->algebraicCount(); ++i) {
EXPECT_NE(nullptr, analyserModel->algebraic(i)->initialisingVariable());
}
*/

EXPECT_EQ(nullptr, generator->model());
EXPECT_EQ(EMPTY_STRING, generator->interfaceCode());
Expand All @@ -682,20 +686,14 @@ TEST(Coverage, generator)

auto profile = generator->profile();

profile->setInterfaceCreateStatesArrayMethodString("double * createStatesVector();\n");
profile->setImplementationCreateStatesArrayMethodString("double * createStatesVector()\n"
"{\n"
" double *res = (double *) malloc(STATE_COUNT*sizeof(double));\n"
"\n"
" for (size_t i = 0; i < STATE_COUNT; ++i) {\n"
" res[i] = NAN;\n"
" }\n"
"\n"
" return res;\n"
"}\n");

EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.modified.profile.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.modified.profile.c", generator->implementationCode());
profile->setXorString("XOR");
profile->setXorFunctionString("double XOR(double x, double y)\n"
"{\n"
" return (x != 0.0) ^ (y != 0.0);\n"
"}\n");

EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.xor.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.xor.c", generator->implementationCode());

profile = libcellml::GeneratorProfile::create();

Expand Down Expand Up @@ -847,12 +845,13 @@ TEST(Coverage, generator)
EXPECT_EQ(EMPTY_STRING, generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.py", generator->implementationCode());

profile->setImplementationCreateStatesArrayMethodString("\n"
"def create_states_vector():\n"
" return [nan]*STATE_COUNT\n");
profile->setXorString("XOR_FUNC");
profile->setXorFunctionString("\n"
"def XOR_FUNC(x, y):\n"
" return 1.0 if bool(x) ^ bool(y) else 0.0\n");

EXPECT_EQ(EMPTY_STRING, generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.modified.profile.py", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("coverage/generator/model.xor.py", generator->implementationCode());

// Coverage for the case where mProfile is equal to nullptr in Generator.

Expand Down
69 changes: 36 additions & 33 deletions tests/generator/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952)
TEST(Generator, hodgkinHuxleySquidAxonModel1952UnknownVarsOnRhs)
{
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model_unknown_vars_on_rhs.cellml"));
auto model = parser->parseModel(fileContents("generator/hodgkin_huxley_squid_axon_model_1952/model.unknown.vars.on.rhs.cellml"));

EXPECT_EQ(size_t(0), parser->issueCount());

Expand Down Expand Up @@ -1253,16 +1253,16 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithStateVariableAsExternalVariab

auto profile = generator->profile();

profile->setInterfaceFileNameString("model.state.h");
profile->setInterfaceFileNameString("model.state.external.h");

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.state.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.state.c", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.c", generator->implementationCode());

profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

generator->setProfile(profile);

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.state.py", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.state.external.py", generator->implementationCode());
}

TEST(Generator, hodgkinHuxleySquidAxonModel1952WithStateVariablesAsExternalVariablesIncludingOneDependingOnTheOther)
Expand Down Expand Up @@ -1297,16 +1297,16 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithStateVariablesAsExternalVaria

auto profile = generator->profile();

profile->setInterfaceFileNameString("model.dependent.state.h");
profile->setInterfaceFileNameString("model.dependent.state.external.h");

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.c", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.c", generator->implementationCode());

profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

generator->setProfile(profile);

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.py", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.state.external.py", generator->implementationCode());
}

TEST(Generator, hodgkinHuxleySquidAxonModel1952WithConstantAsExternalVariable)
Expand Down Expand Up @@ -1334,16 +1334,16 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithConstantAsExternalVariable)

auto profile = generator->profile();

profile->setInterfaceFileNameString("model.constant.h");
profile->setInterfaceFileNameString("model.constant.external.h");

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.c", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.c", generator->implementationCode());

profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

generator->setProfile(profile);

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.py", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.constant.external.py", generator->implementationCode());
}

TEST(Generator, hodgkinHuxleySquidAxonModel1952WithConstantsAsExternalVariablesIncludingOneDependingOnTheOther)
Expand Down Expand Up @@ -1377,16 +1377,16 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithConstantsAsExternalVariablesI

auto profile = generator->profile();

profile->setInterfaceFileNameString("model.dependent.constant.h");
profile->setInterfaceFileNameString("model.dependent.constant.external.h");

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.c", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.c", generator->implementationCode());

profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

generator->setProfile(profile);

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.py", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.constant.external.py", generator->implementationCode());
}

TEST(Generator, hodgkinHuxleySquidAxonModel1952WithComputedConstantAsExternalVariable)
Expand Down Expand Up @@ -1414,16 +1414,16 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithComputedConstantAsExternalVar

auto profile = generator->profile();

profile->setInterfaceFileNameString("model.computed.constant.h");
profile->setInterfaceFileNameString("model.computed.constant.external.h");

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.c", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.c", generator->implementationCode());

profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

generator->setProfile(profile);

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.py", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.computed.constant.external.py", generator->implementationCode());
}

TEST(Generator, hodgkinHuxleySquidAxonModel1952WithComputedConstantsAsExternalVariablesIncludingOneDependingOnTheOther)
Expand Down Expand Up @@ -1457,16 +1457,16 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithComputedConstantsAsExternalVa

auto profile = generator->profile();

profile->setInterfaceFileNameString("model.dependent.computed.constant.h");
profile->setInterfaceFileNameString("model.dependent.computed.constant.external.h");

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.c", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.c", generator->implementationCode());

profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

generator->setProfile(profile);

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.py", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.computed.constant.external.py", generator->implementationCode());
}

TEST(Generator, hodgkinHuxleySquidAxonModel1952WithAlgebraicVariableAsExternalVariable)
Expand Down Expand Up @@ -1494,16 +1494,16 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithAlgebraicVariableAsExternalVa

auto profile = generator->profile();

profile->setInterfaceFileNameString("model.algebraic.h");
profile->setInterfaceFileNameString("model.algebraic.external.h");

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.c", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.c", generator->implementationCode());

profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

generator->setProfile(profile);

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.py", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.algebraic.external.py", generator->implementationCode());
}

TEST(Generator, hodgkinHuxleySquidAxonModel1952WithAlgebraicVariablesAsExternalVariablesIncludingOneDependingOnTheOther)
Expand Down Expand Up @@ -1537,16 +1537,16 @@ TEST(Generator, hodgkinHuxleySquidAxonModel1952WithAlgebraicVariablesAsExternalV

auto profile = generator->profile();

profile->setInterfaceFileNameString("model.dependent.algebraic.h");
profile->setInterfaceFileNameString("model.dependent.algebraic.external.h");

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.c", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.c", generator->implementationCode());

profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

generator->setProfile(profile);

EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.py", generator->implementationCode());
EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/model.dependent.algebraic.external.py", generator->implementationCode());
}

TEST(Generator, hodgkinHuxleySquidAxonModel1952WithVariousExternalVariables)
Expand Down Expand Up @@ -1972,6 +1972,9 @@ TEST(Generator, modelWithComplexUnitsOutOfScope)

generator->setModel(analyserModel);

EXPECT_EQ_FILE_CONTENTS("generator/cellml_slc_example/model.h", generator->interfaceCode());
EXPECT_EQ_FILE_CONTENTS("generator/cellml_slc_example/model.c", generator->implementationCode());

auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

generator->setProfile(profile);
Expand Down
Loading

0 comments on commit 6c2d320

Please sign in to comment.