Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/generator/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,30 @@ TEST(Generator, cellmlLeadingPlusSign)
EXPECT_EQ_FILE_CONTENTS("generator/cellml_leading_plus_sign/model.py", generator->implementationCode(analyserModel, profile));
}

TEST(Generator, notOperandWithParentheses)
{
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/cellml_not/model.cellml"));

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

auto analyser = libcellml::Analyser::create();

analyser->analyseModel(model);

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

auto analyserModel = analyser->analyserModel();
auto generator = libcellml::Generator::create();

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

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

EXPECT_EQ_FILE_CONTENTS("generator/cellml_not/model.py", generator->implementationCode(analyserModel, profile));
}

TEST(Generator, dependentEqns)
{
auto parser = libcellml::Parser::create();
Expand Down
52 changes: 0 additions & 52 deletions tests/generator/generatornot.cpp

This file was deleted.

177 changes: 49 additions & 128 deletions tests/generator/generatorunary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,189 +20,110 @@ limitations under the License.

#include <libcellml>

TEST(GeneratorUnaryMinus, example01)
// Unary minus tests.

namespace {

static void expectUnaryMinusExample(const std::string &example)
{
// rates[0] = --1.0;
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/unary_minus/example_01.cellml"));
auto model = parser->parseModel(fileContents("generator/cellml_unary_minus/" + example + ".cellml"));

EXPECT_NE(nullptr, model);
EXPECT_EQ(size_t(0), parser->issueCount());

auto analyser = libcellml::Analyser::create();

analyser->analyseModel(model);

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

auto analyserModel = analyser->analyserModel();
auto generator = libcellml::Generator::create();
auto profile = libcellml::GeneratorProfile::create();

auto implementationCode = generator->implementationCode(analyser->analyserModel());
profile->setInterfaceFileNameString(example + ".h");

EXPECT_TRUE(implementationCode.find("rates[0] = -(-1.0);\n") != std::string::npos);
}
EXPECT_EQ_FILE_CONTENTS("generator/cellml_unary_minus/" + example + ".h", generator->interfaceCode(analyserModel, profile));
EXPECT_EQ_FILE_CONTENTS("generator/cellml_unary_minus/" + example + ".c", generator->implementationCode(analyserModel, profile));

TEST(GeneratorUnaryMinus, example02)
{
// rates[0] = --2.0*constants[0];
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/unary_minus/example_02.cellml"));
profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

EXPECT_NE(nullptr, model);
EXPECT_EQ_FILE_CONTENTS("generator/cellml_unary_minus/" + example + ".py", generator->implementationCode(analyserModel, profile));
}

auto analyser = libcellml::Analyser::create();
analyser->analyseModel(model);
} // namespace

EXPECT_EQ(size_t(0), analyser->issueCount());
TEST(GeneratorUnary, unaryMinusExample01)
{
// rates[0] = --1.0;

auto generator = libcellml::Generator::create();
expectUnaryMinusExample("example_01");
}

auto implementationCode = generator->implementationCode(analyser->analyserModel());
TEST(GeneratorUnary, unaryMinusExample02)
{
// rates[0] = --2.0*constants[0];

EXPECT_TRUE(implementationCode.find("rates[0] = -(-2.0*constants[0]);\n") != std::string::npos);
expectUnaryMinusExample("example_02");
}

TEST(GeneratorUnaryMinus, example03)
TEST(GeneratorUnary, unaryMinusExample03)
{
// rates[0] = --constants[1]/constants[0];
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/unary_minus/example_03.cellml"));

EXPECT_NE(nullptr, model);

auto analyser = libcellml::Analyser::create();
analyser->analyseModel(model);

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

auto generator = libcellml::Generator::create();

auto implementationCode = generator->implementationCode(analyser->analyserModel());

EXPECT_TRUE(implementationCode.find("rates[0] = -(-constants[1]/constants[0]);\n") != std::string::npos);
expectUnaryMinusExample("example_03");
}

TEST(GeneratorUnaryMinus, example04)
TEST(GeneratorUnary, unaryMinusExample04)
{
// rates[0] = -(-1.0);
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/unary_minus/example_04.cellml"));

EXPECT_NE(nullptr, model);

auto analyser = libcellml::Analyser::create();
analyser->analyseModel(model);

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

auto generator = libcellml::Generator::create();

auto implementationCode = generator->implementationCode(analyser->analyserModel());

EXPECT_TRUE(implementationCode.find("rates[0] = -(-1.0);\n") != std::string::npos);
expectUnaryMinusExample("example_04");
}

TEST(GeneratorUnaryMinus, example05)
TEST(GeneratorUnary, unaryMinusExample05)
{
// rates[0] = -(-constants[1]+constants[0]);
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/unary_minus/example_05.cellml"));

EXPECT_NE(nullptr, model);

auto analyser = libcellml::Analyser::create();
analyser->analyseModel(model);

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

auto generator = libcellml::Generator::create();

auto implementationCode = generator->implementationCode(analyser->analyserModel());

EXPECT_TRUE(implementationCode.find("rates[0] = -(-constants[1]+constants[0]);\n") != std::string::npos);
expectUnaryMinusExample("example_05");
}

TEST(GeneratorUnaryMinus, example06)
TEST(GeneratorUnary, unaryMinusExample06)
{
// rates[0] = -pow(-constants[1], constants[0]);
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/unary_minus/example_06.cellml"));

EXPECT_NE(nullptr, model);

auto analyser = libcellml::Analyser::create();
analyser->analyseModel(model);

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

auto generator = libcellml::Generator::create();

auto implementationCode = generator->implementationCode(analyser->analyserModel());

EXPECT_TRUE(implementationCode.find("rates[0] = -pow(-constants[1], constants[0]);\n") != std::string::npos);
expectUnaryMinusExample("example_06");
}

TEST(GeneratorUnaryMinus, example07)
TEST(GeneratorUnary, unaryMinusExample07)
{
// rates[0] = constants[1]-(-constants[0]);
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/unary_minus/example_07.cellml"));

EXPECT_NE(nullptr, model);

auto analyser = libcellml::Analyser::create();
analyser->analyseModel(model);

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

auto generator = libcellml::Generator::create();

auto implementationCode = generator->implementationCode(analyser->analyserModel());

EXPECT_TRUE(implementationCode.find("rates[0] = constants[1]-(-constants[0]);\n") != std::string::npos);
expectUnaryMinusExample("example_07");
}

TEST(GeneratorUnaryPlus, operandWithParentheses)
// Unary plus tests.

TEST(GeneratorUnary, unaryPlusOperandWithParentheses)
{
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/unary_plus/model.cellml"));
auto model = parser->parseModel(fileContents("generator/cellml_unary_plus/model.cellml"));

EXPECT_NE(nullptr, model);
EXPECT_EQ(size_t(0), parser->issueCount());

auto analyser = libcellml::Analyser::create();

analyser->analyseModel(model);

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

auto analyserModel = analyser->analyserModel();
auto generator = libcellml::Generator::create();
auto implementationCode = generator->implementationCode(analyser->analyserModel());

EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[0] = voi*(voi+constants[0]);\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[1] = voi-(voi+constants[0]);\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[2] = voi/(voi+constants[0]);\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[3] = ((voi > 5.5) || constants[0]) && constants[0];\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[4] = (voi > 5.5)*constants[0];\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[5] = (voi+constants[0])*voi;\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[6] = voi/(voi*constants[0]);\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[7] = voi+(voi > 5.5);\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[8] = -(voi+constants[0]);\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[9] = -voi*constants[0];\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[10] = voi-(-constants[0]);\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[11] = pow(constants[0], 1.0/(voi+constants[0]));\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraicVariables[12] = constants[0] || ((voi > 5.5) && constants[0]);\n"));

implementationCode = generator->implementationCode(analyser->analyserModel(), libcellml::GeneratorProfile::Profile::PYTHON);

EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[0] = voi*(voi+constants[0])\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[1] = voi-(voi+constants[0])\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[2] = voi/(voi+constants[0])\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[3] = and_func(or_func(gt_func(voi, 5.5), constants[0]), constants[0])\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[4] = gt_func(voi, 5.5)*constants[0]\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[5] = (voi+constants[0])*voi\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[6] = voi/(voi*constants[0])\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[7] = voi+gt_func(voi, 5.5)\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[8] = -(voi+constants[0])\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[9] = -voi*constants[0]\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[10] = voi-(-constants[0])\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[11] = pow(constants[0], 1.0/(voi+constants[0]))\n"));
EXPECT_NE(std::string::npos, implementationCode.find("algebraic_variables[12] = or_func(constants[0], and_func(gt_func(voi, 5.5), constants[0]))\n"));

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

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

EXPECT_EQ_FILE_CONTENTS("generator/cellml_unary_plus/model.py", generator->implementationCode(analyserModel, profile));
}
1 change: 0 additions & 1 deletion tests/generator/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ list(APPEND LIBCELLML_TESTS ${CURRENT_TEST})

set(${CURRENT_TEST}_SRCS
${CMAKE_CURRENT_LIST_DIR}/generator.cpp
${CMAKE_CURRENT_LIST_DIR}/generatornot.cpp
${CMAKE_CURRENT_LIST_DIR}/generatorprofile.cpp
${CMAKE_CURRENT_LIST_DIR}/generatorunary.cpp
${CMAKE_CURRENT_LIST_DIR}/generatorvariabletracker.cpp
Expand Down
Loading
Loading