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 45 of file TestInterpreter.cpp.

46{
48 int func1 = interp.DefineFunction("x", "-2");
49 Array<OneD, NekDouble> in(1, 2.0), out(1);
50
51 interp.Evaluate(func1, {in}, out);
52 BOOST_CHECK_EQUAL(out[0], -2);
53}
Interpreter class for the evaluation of mathematical expressions.
Definition: Interpreter.h:76
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 73 of file TestInterpreter.cpp.

74{
76 int func1 = interp.DefineFunction("x", "x % 3.2");
77 int func2 = interp.DefineFunction("x", "fmod(x,3.2)");
78 Array<OneD, NekDouble> in(1, 5.2), out(1);
79
80 NekDouble epsilon = std::numeric_limits<NekDouble>::epsilon();
81
82 interp.Evaluate(func1, {in}, out);
83 BOOST_CHECK_CLOSE(out[0], 2.0, epsilon);
84 interp.Evaluate(func2, {in}, out);
85 BOOST_CHECK_CLOSE(out[0], 2.0, epsilon);
86}
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 55 of file TestInterpreter.cpp.

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

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