diff options
Diffstat (limited to 'host/tests/nocscript_ftable_test.cpp')
-rw-r--r-- | host/tests/nocscript_ftable_test.cpp | 75 |
1 files changed, 35 insertions, 40 deletions
diff --git a/host/tests/nocscript_ftable_test.cpp b/host/tests/nocscript_ftable_test.cpp index 99ac2231a..36aa314f2 100644 --- a/host/tests/nocscript_ftable_test.cpp +++ b/host/tests/nocscript_ftable_test.cpp @@ -6,15 +6,14 @@ // #include "../lib/rfnoc/nocscript/function_table.hpp" -#include <boost/test/unit_test.hpp> -#include <boost/test/floating_point_comparison.hpp> +#include "nocscript_common.hpp" #include <boost/bind.hpp> #include <boost/make_shared.hpp> +#include <boost/test/floating_point_comparison.hpp> +#include <boost/test/unit_test.hpp> #include <algorithm> #include <iostream> -#include "nocscript_common.hpp" - BOOST_AUTO_TEST_CASE(test_basic_funcs) { function_table::sptr ft = function_table::make(); @@ -49,7 +48,7 @@ BOOST_AUTO_TEST_CASE(test_basic_funcs) BOOST_REQUIRE_EQUAL(ft->get_type("DIV", two_double_args), expression::TYPE_DOUBLE); expression_literal e_div_d = ft->eval("DIV", two_double_args, two_double_values); BOOST_REQUIRE_EQUAL(e_div_d.infer_type(), expression::TYPE_DOUBLE); - BOOST_CHECK_CLOSE(e_div_d.get_double(), 2.0/3.0, 0.01); + BOOST_CHECK_CLOSE(e_div_d.get_double(), 2.0 / 3.0, 0.01); BOOST_REQUIRE_EQUAL(ft->get_type("MODULO", two_int_args), expression::TYPE_INT); expression_literal e_modulo_i = ft->eval("MODULO", two_int_args, two_int_values); @@ -103,15 +102,11 @@ BOOST_AUTO_TEST_CASE(test_add_funcs) BOOST_CHECK(not ft->function_exists("ADD_PLUS_2")); expression_function::argtype_list_type add_int_args{ + expression::TYPE_INT, expression::TYPE_INT}; + ft->register_function("ADD_PLUS_2", + boost::bind(&add_plus2_int, _1), expression::TYPE_INT, - expression::TYPE_INT - }; - ft->register_function( - "ADD_PLUS_2", - boost::bind(&add_plus2_int, _1), - expression::TYPE_INT, - add_int_args - ); + add_int_args); BOOST_CHECK(ft->function_exists("ADD_PLUS_2")); BOOST_CHECK(ft->function_exists("ADD_PLUS_2", add_int_args)); @@ -144,22 +139,16 @@ BOOST_AUTO_TEST_CASE(test_conditionals) { function_table::sptr ft = function_table::make(); ft->register_function( - "DUMMY", - boost::bind(&dummy_true, _1), - expression::TYPE_BOOL, - no_args - ); + "DUMMY", boost::bind(&dummy_true, _1), expression::TYPE_BOOL, no_args); ft->register_function( - "DUMMY_F", - boost::bind(&dummy_false, _1), - expression::TYPE_BOOL, - no_args - ); + "DUMMY_F", boost::bind(&dummy_false, _1), expression::TYPE_BOOL, no_args); BOOST_REQUIRE(ft->function_exists("DUMMY", no_args)); BOOST_REQUIRE(ft->function_exists("DUMMY_F", no_args)); - expression_function::sptr dummy_statement = boost::make_shared<expression_function>("DUMMY", ft); - expression_function::sptr if_statement = boost::make_shared<expression_function>("IF", ft); + expression_function::sptr dummy_statement = + boost::make_shared<expression_function>("DUMMY", ft); + expression_function::sptr if_statement = + boost::make_shared<expression_function>("IF", ft); if_statement->add(E(true)); if_statement->add(dummy_statement); @@ -170,7 +159,8 @@ BOOST_AUTO_TEST_CASE(test_conditionals) std::cout << "END." << std::endl; std::cout << "Dummy statement should not run until END:" << std::endl; - expression_function::sptr if_statement2 = boost::make_shared<expression_function>("IF", ft); + expression_function::sptr if_statement2 = + boost::make_shared<expression_function>("IF", ft); if_statement2->add(E(false)); if_statement2->add(dummy_statement); dummy_true_counter = 0; @@ -178,12 +168,14 @@ BOOST_AUTO_TEST_CASE(test_conditionals) BOOST_CHECK_EQUAL(dummy_true_counter, 0); std::cout << "END." << std::endl; - expression_function::sptr if_else_statement = boost::make_shared<expression_function>("IF_ELSE", ft); - expression_function::sptr dummy_statement_f = boost::make_shared<expression_function>("DUMMY_F", ft); + expression_function::sptr if_else_statement = + boost::make_shared<expression_function>("IF_ELSE", ft); + expression_function::sptr dummy_statement_f = + boost::make_shared<expression_function>("DUMMY_F", ft); if_else_statement->add(E(true)); if_else_statement->add(dummy_statement); if_else_statement->add(dummy_statement_f); - dummy_true_counter = 0; + dummy_true_counter = 0; dummy_false_counter = 0; std::cout << "Should execute dummy/true statement before END:" << std::endl; BOOST_CHECK(if_else_statement->eval().get_bool()); @@ -191,11 +183,12 @@ BOOST_AUTO_TEST_CASE(test_conditionals) BOOST_CHECK_EQUAL(dummy_false_counter, 0); std::cout << "END." << std::endl; - expression_function::sptr if_else_statement2 = boost::make_shared<expression_function>("IF_ELSE", ft); + expression_function::sptr if_else_statement2 = + boost::make_shared<expression_function>("IF_ELSE", ft); if_else_statement2->add(E(false)); if_else_statement2->add(dummy_statement); if_else_statement2->add(dummy_statement_f); - dummy_true_counter = 0; + dummy_true_counter = 0; dummy_false_counter = 0; std::cout << "Should execute dummy/false statement before END:" << std::endl; BOOST_CHECK(not if_else_statement2->eval().get_bool()); @@ -221,33 +214,35 @@ BOOST_AUTO_TEST_CASE(test_bitwise_funcs) // Bitwise Math int int_value1 = 0x2; int int_value2 = 0x3; - expression_container::expr_list_type two_int_values{ - E(int_value1), - E(int_value2) - }; + expression_container::expr_list_type two_int_values{E(int_value1), E(int_value2)}; BOOST_REQUIRE_EQUAL(ft->get_type("SHIFT_RIGHT", two_int_args), expression::TYPE_INT); - expression_literal e_shift_right = ft->eval("SHIFT_RIGHT", two_int_args, two_int_values); + expression_literal e_shift_right = + ft->eval("SHIFT_RIGHT", two_int_args, two_int_values); BOOST_REQUIRE_EQUAL(e_shift_right.infer_type(), expression::TYPE_INT); BOOST_CHECK_EQUAL(e_shift_right.get_int(), int_value1 >> int_value2); BOOST_REQUIRE_EQUAL(ft->get_type("SHIFT_LEFT", two_int_args), expression::TYPE_INT); - expression_literal e_shift_left = ft->eval("SHIFT_LEFT", two_int_args, two_int_values); + expression_literal e_shift_left = + ft->eval("SHIFT_LEFT", two_int_args, two_int_values); BOOST_REQUIRE_EQUAL(e_shift_left.infer_type(), expression::TYPE_INT); BOOST_CHECK_EQUAL(e_shift_left.get_int(), int_value1 << int_value2); BOOST_REQUIRE_EQUAL(ft->get_type("BITWISE_AND", two_int_args), expression::TYPE_INT); - expression_literal e_bitwise_and = ft->eval("BITWISE_AND", two_int_args, two_int_values); + expression_literal e_bitwise_and = + ft->eval("BITWISE_AND", two_int_args, two_int_values); BOOST_REQUIRE_EQUAL(e_bitwise_and.infer_type(), expression::TYPE_INT); BOOST_CHECK_EQUAL(e_bitwise_and.get_int(), int_value1 & int_value2); BOOST_REQUIRE_EQUAL(ft->get_type("BITWISE_OR", two_int_args), expression::TYPE_INT); - expression_literal e_bitwise_or = ft->eval("BITWISE_OR", two_int_args, two_int_values); + expression_literal e_bitwise_or = + ft->eval("BITWISE_OR", two_int_args, two_int_values); BOOST_REQUIRE_EQUAL(e_bitwise_or.infer_type(), expression::TYPE_INT); BOOST_CHECK_EQUAL(e_bitwise_or.get_int(), int_value1 | int_value2); BOOST_REQUIRE_EQUAL(ft->get_type("BITWISE_XOR", two_int_args), expression::TYPE_INT); - expression_literal e_bitwise_xor = ft->eval("BITWISE_XOR", two_int_args, two_int_values); + expression_literal e_bitwise_xor = + ft->eval("BITWISE_XOR", two_int_args, two_int_values); BOOST_REQUIRE_EQUAL(e_bitwise_xor.infer_type(), expression::TYPE_INT); BOOST_CHECK_EQUAL(e_bitwise_xor.get_int(), int_value1 ^ int_value2); } |