blob: 11f48d3d2d48538aef73fda8a6f811e89c580c51 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include <server/parser.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test_parser_exec) {
using namespace math::server;
{
Parser parser{""};
BOOST_CHECK_THROW(parser.exec(), parser::Error);
}
{
Parser parser{"1"};
BOOST_TEST(parser.exec() == 1);
}
{
Parser parser{" 1 + "};
BOOST_CHECK_THROW(parser.exec(), parser::Error);
}
{
Parser parser{" 1 + 2 "};
BOOST_TEST(parser.exec() == 3);
}
{
Parser parser{" 2 * 1 + 3 "};
BOOST_TEST(parser.exec() == 5);
}
{
Parser parser{" 2 * (1 + 3) "};
BOOST_TEST(parser.exec() == 8);
}
{
Parser parser{" 2 * (1 + 3 "};
BOOST_CHECK_THROW(parser.exec(), parser::Error);
}
{
Parser parser{" 2 * (1 + 3) )"};
BOOST_CHECK_THROW(parser.exec(), parser::Error);
}
{
Parser parser{" 2 * (1 + 3 * (1 - -3)) "};
BOOST_TEST(parser.exec() == 26);
}
{
Parser parser{" -2 * ---- (3 + -100e-1) "}; // Looks weird, but also works in e.g. Python
BOOST_TEST(parser.exec() == 14);
}
}
|