mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1985 Expression Parser: Add unit test
This commit is contained in:
parent
c976091336
commit
5cd7ffc75e
@ -30,6 +30,7 @@ ${CEE_CURRENT_LIST_DIR}RigCellGeometryTools-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RigHexIntersectionTools-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}ObservedDataParser-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}EclipseRftReader-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RicExpressionParser-Test.cpp
|
||||
)
|
||||
|
||||
if (RESINSIGHT_ENABLE_PROTOTYPE_FEATURE_FRACTURES)
|
||||
|
50
ApplicationCode/UnitTests/RicExpressionParser-Test.cpp
Normal file
50
ApplicationCode/UnitTests/RicExpressionParser-Test.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
|
||||
#include "expressionparser/ExpressionParser.h"
|
||||
|
||||
#include <numeric>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RicExpressionParserTest, BasicUsage)
|
||||
{
|
||||
std::vector<double> a(10);
|
||||
std::iota(a.begin(), a.end(), 10);
|
||||
|
||||
std::vector<double> b(10);
|
||||
std::iota(b.begin(), b.end(), 100);
|
||||
|
||||
std::vector<double> c(10);
|
||||
|
||||
ExpressionParser parser;
|
||||
parser.assignVector("a", a);
|
||||
parser.assignVector("b", b);
|
||||
parser.assignVector("c", c);
|
||||
|
||||
QString expr = "c := a + b";
|
||||
parser.setExpression(expr);
|
||||
|
||||
EXPECT_TRUE(parser.evaluate());
|
||||
|
||||
EXPECT_DOUBLE_EQ(c[0], 110.0);
|
||||
EXPECT_DOUBLE_EQ(c[9], 128.0);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RicExpressionParserTest, DetectVariables)
|
||||
{
|
||||
QString expr = "c := a + (x / y)";
|
||||
|
||||
std::vector<QString> variables = ExpressionParser::detectReferencedVariables(expr);
|
||||
|
||||
EXPECT_STREQ(variables[0].toStdString().data(), "a");
|
||||
EXPECT_STREQ(variables[1].toStdString().data(), "c");
|
||||
EXPECT_STREQ(variables[2].toStdString().data(), "x");
|
||||
EXPECT_STREQ(variables[3].toStdString().data(), "y");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user