diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2019-11-30 01:38:08 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-01 05:23:11 +0300 |
commit | 90bd600c5025ede4db99122f13dfb07b27de46ae (patch) | |
tree | 0b581b43e5fcb54114c6c373352ed6ab5fcd61dc /test/unit_tests/parser.cpp | |
download | math-server-90bd600c5025ede4db99122f13dfb07b27de46ae.tar.gz math-server-90bd600c5025ede4db99122f13dfb07b27de46ae.zip |
initial commit
Diffstat (limited to '')
-rw-r--r-- | test/unit_tests/parser.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/unit_tests/parser.cpp b/test/unit_tests/parser.cpp new file mode 100644 index 0000000..11f48d3 --- /dev/null +++ b/test/unit_tests/parser.cpp @@ -0,0 +1,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); + } +} |