From 90bd600c5025ede4db99122f13dfb07b27de46ae Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 30 Nov 2019 01:38:08 +0300 Subject: initial commit --- test/unit_tests/parser.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/unit_tests/parser.cpp (limited to 'test/unit_tests/parser.cpp') 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 + +#include + +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); + } +} -- cgit v1.2.3