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

Method testVariables

tests/backend/Parser/ParserTest.cpp:148–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148void ParserTest::testVariables() {
149 Parsing::Parser parser(false);
150 parser.assign_symbol("a", 1.);
151 const QVector<QPair<QString, double>> tests{{QStringLiteral("a"), 1.},
152 {QStringLiteral("a+1"), 2.},
153 {QStringLiteral("a+1.5"), 2.5},
154 {QStringLiteral("a!"), 1.}};
155
156 for (auto& expr : tests)
157 QCOMPARE(parser.parse(qPrintable(expr.first), "C"), expr.second);
158
159 parser.assign_symbol("a", 0.); // only vars set to zero get removed
160 parser.remove_symbol("a");
161 for (auto& expr : tests)
162 QVERIFY(std::isnan(parser.parse(qPrintable(expr.first), "C")));
163
164 // longer var name
165 parser.assign_symbol("sina", 1.5);
166 const QVector<QPair<QString, double>> tests2{{QStringLiteral("sina"), 1.5},
167 {QStringLiteral("sina+1"), 2.5},
168 {QStringLiteral("sina+1.5"), 3.},
169 {QStringLiteral("2*sina"), 3.}};
170
171 for (auto& expr : tests2)
172 QCOMPARE(parser.parse(qPrintable(expr.first), "C"), expr.second);
173
174 // parse_with_vars()
175 parser_var vars[] = {{"x", 1.}, {"y", 2.}};
176 QCOMPARE(parser.parse_with_vars("x + y", vars, 2, "C"), 3.);
177}
178
179void ParserTest::testLocale() {
180// TODO: locale test currently does not work on FreeBSD

Callers

nothing calls this directly

Calls 3

remove_symbolMethod · 0.80
parse_with_varsMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected