From be8e043cb8667786bc9c7ca09d1e86eba7ce46e5 Mon Sep 17 00:00:00 2001 From: NilsForssen Date: Fri, 6 Oct 2023 16:28:57 +0200 Subject: [PATCH] Committing test file --- src/test.cc | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/test.cc diff --git a/src/test.cc b/src/test.cc new file mode 100644 index 0000000..434a80c --- /dev/null +++ b/src/test.cc @@ -0,0 +1,82 @@ +#define CATCH_CONFIG_RUNNER +#include "catch.hpp" + +#include "operators.h" +#include "operands.h" + +using namespace std; + +TEST_CASE("Noder") +{ + Const_int my_int{5}; + Const_double my_double{2}; + Const_double my_n_double{-2.3123124}; + Const_int zero{0}; + + SECTION("Operands") + { + CHECK( my_int.get_postfix() == "5" ); + CHECK( my_double.get_postfix() == "2.000" ); + CHECK( my_n_double.get_postfix() == "-2.312" ); + + CHECK( my_int.get_infix() == "5" ); + CHECK( my_double.get_infix() == "2.000" ); + CHECK( my_n_double.get_infix() == "-2.312" ); + + CHECK( my_int.get_prefix() == "5" ); + CHECK( my_double.get_prefix() == "2.000" ); + CHECK( my_n_double.get_prefix() == "-2.312" ); + + CHECK( my_int.get_value() == 5 ); + CHECK( my_double.get_value() == 2.0 ); + CHECK( my_n_double.get_value() == -2.3123124 ); + } + + Addition my_add{my_int, my_double}; + Subtraction my_sub{my_int, my_double}; + Multiplication my_mult{my_int, my_double}; + Division my_div{my_int, my_double}; + Exponent my_exp{my_int, my_double}; + + SECTION("Operators") + { + CHECK( my_add.get_postfix() == "5 2.000 +" ); + CHECK( my_add.get_infix() == "(5+2.000)" ); + CHECK( my_add.get_prefix() == "+ 5 2.000" ); + CHECK( my_add.get_value() == 7.0 ); + + CHECK( my_sub.get_postfix() == "5 2.000 -" ); + CHECK( my_sub.get_infix() == "(5-2.000)" ); + CHECK( my_sub.get_prefix() == "- 5 2.000" ); + CHECK( my_sub.get_value() == 3.0 ); + + CHECK( my_mult.get_postfix() == "5 2.000 *" ); + CHECK( my_mult.get_infix() == "(5*2.000)" ); + CHECK( my_mult.get_prefix() == "* 5 2.000" ); + CHECK( my_mult.get_value() == 10.0 ); + + CHECK( my_div.get_postfix() == "5 2.000 /" ); + CHECK( my_div.get_infix() == "(5/2.000)" ); + CHECK( my_div.get_prefix() == "/ 5 2.000" ); + CHECK( my_div.get_value() == 2.5 ); + + CHECK( my_exp.get_postfix() == "5 2.000 ^" ); + CHECK( my_exp.get_infix() == "(5^2.000)" ); + CHECK( my_exp.get_prefix() == "^ 5 2.000" ); + CHECK( my_exp.get_value() == 25.0); + + CHECK_THROWS( Division{my_int, zero}.get_value() ); + CHECK_THROWS( Division{my_double, zero}.get_value() ); + CHECK_THROWS( Exponent{my_n_double, my_double}.get_value() ); + CHECK_THROWS( Exponent{zero, my_n_double}.get_value() ); + } +} + +int main() +{ + Catch::Session session; + + session.run(); + + return 0; +} -- 2.30.2