Nektar++
Functions
Nektar::InterpreterUnitTests Namespace Reference

Functions

 BOOST_AUTO_TEST_CASE (TestConstant)
 
 BOOST_AUTO_TEST_CASE (TestPowOperator)
 
 BOOST_AUTO_TEST_CASE (TestFmodOperator)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

Nektar::InterpreterUnitTests::BOOST_AUTO_TEST_CASE ( TestConstant  )

Definition at line 47 of file TestInterpreter.cpp.

48{
50 int func1 = interp.DefineFunction("x", "-2");
51 Array<OneD, NekDouble> in(1, 2.0), out(1);
52
53 interp.Evaluate(func1, {in}, out);
54 BOOST_CHECK_EQUAL(out[0], -2);
55}
Interpreter class for the evaluation of mathematical expressions.
Definition: Interpreter.h:78
int DefineFunction(const std::string &vlist, const std::string &expr)
Defines a function for the purposes of evaluation.
NekDouble Evaluate(const int id)
Evaluate a function which depends only on constants and/or parameters.

References Nektar::LibUtilities::Interpreter::DefineFunction(), and Nektar::LibUtilities::Interpreter::Evaluate().

◆ BOOST_AUTO_TEST_CASE() [2/3]

Nektar::InterpreterUnitTests::BOOST_AUTO_TEST_CASE ( TestFmodOperator  )

Definition at line 75 of file TestInterpreter.cpp.

76{
78 int func1 = interp.DefineFunction("x", "x % 3.2");
79 int func2 = interp.DefineFunction("x", "fmod(x,3.2)");
80 Array<OneD, NekDouble> in(1, 5.2), out(1);
81
82 NekDouble epsilon = std::numeric_limits<NekDouble>::epsilon();
83
84 interp.Evaluate(func1, {in}, out);
85 BOOST_CHECK_CLOSE(out[0], 2.0, epsilon);
86 interp.Evaluate(func2, {in}, out);
87 BOOST_CHECK_CLOSE(out[0], 2.0, epsilon);
88}
double NekDouble

References Nektar::LibUtilities::Interpreter::DefineFunction(), and Nektar::LibUtilities::Interpreter::Evaluate().

◆ BOOST_AUTO_TEST_CASE() [3/3]

Nektar::InterpreterUnitTests::BOOST_AUTO_TEST_CASE ( TestPowOperator  )

Definition at line 57 of file TestInterpreter.cpp.

58{
60 int func1 = interp.DefineFunction("x", "5*(-(2^x)^4)");
61 int func2 = interp.DefineFunction("x", "-x^2");
62 int func3 = interp.DefineFunction("x", "2^2^4");
63 Array<OneD, NekDouble> in(1, 2.0), out(1);
64
65 interp.Evaluate(func1, {in}, out);
66 BOOST_CHECK_EQUAL(out[0], -1280);
67
68 interp.Evaluate(func2, {in}, out);
69 BOOST_CHECK_EQUAL(out[0], -4);
70
71 interp.Evaluate(func3, {in}, out);
72 BOOST_CHECK_EQUAL(out[0], 65536);
73}

References Nektar::LibUtilities::Interpreter::DefineFunction(), and Nektar::LibUtilities::Interpreter::Evaluate().