MCPcopy Create free account
hub / github.com/KDE/labplot / testEvaluateLogicalExpression

Method testEvaluateLogicalExpression

tests/backend/gsl/ExpressionParserTest.cpp:438–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

436}
437
438void ExpressionParserTest::testEvaluateLogicalExpression() {
439 const QString expr = QStringLiteral("!x || y && x");
440 const QStringList vars = {QStringLiteral("x"), QStringLiteral("y")};
441
442 QVector<QVector<double>*> xVectors;
443
444 xVectors << new QVector<double>({0., 1., 0., 1.}); // x
445 xVectors << new QVector<double>({0., 0., 1., 1.}); // y
446 QVector<double> yVector({
447 5.,
448 5.,
449 5.,
450 5.,
451 }); // random value
452 auto* parser = ExpressionParser::getInstance();
453 parser->tryEvaluateCartesian(expr, vars, xVectors, &yVector);
454
455 // if or evaluated first:
456 // x y
457 // 0 0 : 0
458 // 1 0 : 0
459 // 0 1 : 0
460 // 1 1 : 1
461
462 // if and evaluated first:
463 // x y
464 // 0 0 : 1
465 // 1 0 : 0
466 // 0 1 : 1
467 // 1 1 : 1
468
469 // And must be evaluated before or!
470 QCOMPARE(yVector.size(), 4);
471 QCOMPARE(yVector.at(0), 1.);
472 QCOMPARE(yVector.at(1), 0.);
473 QCOMPARE(yVector.at(2), 1.);
474 QCOMPARE(yVector.at(3), 1.);
475}
476
477void ExpressionParserTest::testevaluateGreaterThan() {
478 const QString expr = QStringLiteral("x > y");

Callers

nothing calls this directly

Calls 2

tryEvaluateCartesianMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected