Skip to content

Commit

Permalink
Add a few more formula math tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Mar 18, 2016
1 parent f6be40b commit a9a29a1
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/tests/test_formula_function.cpp
Expand Up @@ -147,16 +147,24 @@ BOOST_AUTO_TEST_CASE(test_formula_function_math)
{
BOOST_CHECK_EQUAL(formula("abs(5)").evaluate().as_int(), 5);
BOOST_CHECK_EQUAL(formula("abs(-5)").evaluate().as_int(), 5);
BOOST_CHECK_EQUAL(formula("abs(5.0)").evaluate().as_int(), 5);
BOOST_CHECK_EQUAL(formula("abs(-5.0)").evaluate().as_int(), 5);

BOOST_CHECK_EQUAL(formula("min(3,5)").evaluate().as_int(), 3);
BOOST_CHECK_EQUAL(formula("min(5,2)").evaluate().as_int(), 2);
BOOST_CHECK_EQUAL(formula("max(3,5)").evaluate().as_int(), 5);
BOOST_CHECK_EQUAL(formula("max(5,2)").evaluate().as_int(), 5);

BOOST_CHECK_EQUAL(formula("max(4,5,[2,18,7])").evaluate().as_int(), 18);

BOOST_CHECK_EQUAL(formula("log(8,2)").evaluate().as_int(), 3);
BOOST_CHECK_EQUAL(formula("log(12)").evaluate().as_decimal(),
static_cast<int>(round(1000.0 * log(12))));
BOOST_CHECK_EQUAL(formula("exp(3)").evaluate().as_decimal(),
static_cast<int>(round(1000.0 * exp(3))));
}

BOOST_AUTO_TEST_CASE(test_formula_function_sin_cos)
BOOST_AUTO_TEST_CASE(test_formula_function_trig)
{
const double pi = 4. * atan(1.);

Expand All @@ -174,6 +182,17 @@ BOOST_AUTO_TEST_CASE(test_formula_function_sin_cos)
game_logic::formula("cos(x)")
.evaluate(variables).as_decimal()
, static_cast<int>(round(1000. * cos(x * pi / 180.))));

if(x % 90 == 0 && x % 180 != 0) {
BOOST_CHECK(
game_logic::formula("tan(x)")
.evaluate(variables).is_null());
} else {
BOOST_CHECK_EQUAL(
game_logic::formula("tan(x)")
.evaluate(variables).as_decimal(),
static_cast<int>(round(1000. * tan(x * pi / 180.))));
}
}
}

Expand Down

0 comments on commit a9a29a1

Please sign in to comment.