| 146 | } |
| 147 | |
| 148 | void 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 | |
| 179 | void ParserTest::testLocale() { |
| 180 | // TODO: locale test currently does not work on FreeBSD |
nothing calls this directly
no test coverage detected