From 43b9ad311bc1d1001aeb225cafd7b9bf3df29ae3 Mon Sep 17 00:00:00 2001 From: NilsForssen Date: Fri, 6 Oct 2023 16:41:54 +0200 Subject: [PATCH] Added compound ex tests --- src/operators.cc | 2 +- src/test.cc | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/operators.cc b/src/operators.cc index f4e43a3..5cdf094 100644 --- a/src/operators.cc +++ b/src/operators.cc @@ -26,7 +26,7 @@ std::string Operator::get_infix() const std::string Operator::get_prefix() const { std::stringstream concat{}; - concat << symbol << " " << lhs->get_postfix() << " " << rhs->get_postfix(); + concat << symbol << " " << lhs->get_prefix() << " " << rhs->get_prefix(); return concat.str(); } diff --git a/src/test.cc b/src/test.cc index 434a80c..57ad9a0 100644 --- a/src/test.cc +++ b/src/test.cc @@ -70,6 +70,24 @@ TEST_CASE("Noder") CHECK_THROWS( Exponent{my_n_double, my_double}.get_value() ); CHECK_THROWS( Exponent{zero, my_n_double}.get_value() ); } + + SECTION("Compound Expressions") + { + Const_double my_double{2}; + Const_double my_double_2{1.5}; + Const_int my_int{3}; + Const_int my_int_2{7}; + + Addition my_add{my_int, my_double}; + Multiplication my_mult{my_int_2, my_double_2}; + Exponent my_exp{my_add, my_mult}; + + CHECK( my_exp.get_postfix() == "3 2.000 + 7 1.500 * ^" ); + CHECK( my_exp.get_infix() == "((3+2.000)^(7*1.500))" ); + CHECK( my_exp.get_prefix() == "^ + 3 2.000 * 7 1.500" ); + CHECK( my_exp.get_value() == 21836601.3427713849 ); + + } } int main() -- 2.30.2