diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-09-19 03:40:35 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-09-19 04:08:04 +0300 |
commit | 3aea5695bbdcf83c5c7769a629e0a2e4db0c85bc (patch) | |
tree | 6825ecce4a5a937f03bbd0b8dcb79faddd3be7be /tests | |
parent | 345c34826296907d85b4b367a830ff4f73ab293f (diff) |
Cleanup: rename BLI_simple_expr -> BLI_expr_pylike_eval
Simple isn't a good prefix for library names since
lots of unrelated modules could be called 'simple'.
Include 'py' in module name since this is a subset of Python,
one of the main motivations for this is to be Python like/compatible.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gtests/blenlib/BLI_expr_pylike_eval_test.cc (renamed from tests/gtests/blenlib/BLI_simple_expr_test.cc) | 124 | ||||
-rw-r--r-- | tests/gtests/blenlib/CMakeLists.txt | 2 |
2 files changed, 63 insertions, 63 deletions
diff --git a/tests/gtests/blenlib/BLI_simple_expr_test.cc b/tests/gtests/blenlib/BLI_expr_pylike_eval_test.cc index 58b33e85a5f..3aaf0d3a5c8 100644 --- a/tests/gtests/blenlib/BLI_simple_expr_test.cc +++ b/tests/gtests/blenlib/BLI_expr_pylike_eval_test.cc @@ -5,87 +5,87 @@ #include <string.h> extern "C" { -#include "BLI_simple_expr.h" +#include "BLI_expr_pylike_eval.h" #include "BLI_math.h" }; #define TRUE_VAL 1.0 #define FALSE_VAL 0.0 -static void simple_expr_parse_fail_test(const char *str) +static void expr_pylike_parse_fail_test(const char *str) { - ParsedSimpleExpr *expr = BLI_simple_expr_parse(str, 0, NULL); + ExprPyLike_Parsed *expr = BLI_expr_pylike_parse(str, 0, NULL); - EXPECT_FALSE(BLI_simple_expr_is_valid(expr)); + EXPECT_FALSE(BLI_expr_pylike_is_valid(expr)); - BLI_simple_expr_free(expr); + BLI_expr_pylike_free(expr); } -static void simple_expr_const_test(const char *str, double value, bool force_const) +static void expr_pylike_const_test(const char *str, double value, bool force_const) { - ParsedSimpleExpr *expr = BLI_simple_expr_parse(str, 0, NULL); + ExprPyLike_Parsed *expr = BLI_expr_pylike_parse(str, 0, NULL); if (force_const) { - EXPECT_TRUE(BLI_simple_expr_is_constant(expr)); + EXPECT_TRUE(BLI_expr_pylike_is_constant(expr)); } else { - EXPECT_TRUE(BLI_simple_expr_is_valid(expr)); - EXPECT_FALSE(BLI_simple_expr_is_constant(expr)); + EXPECT_TRUE(BLI_expr_pylike_is_valid(expr)); + EXPECT_FALSE(BLI_expr_pylike_is_constant(expr)); } double result; - eSimpleExpr_EvalStatus status = BLI_simple_expr_evaluate(expr, &result, 0, NULL); + eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, &result, 0, NULL); - EXPECT_EQ(status, SIMPLE_EXPR_SUCCESS); + EXPECT_EQ(status, EXPR_PYLIKE_SUCCESS); EXPECT_EQ(result, value); - BLI_simple_expr_free(expr); + BLI_expr_pylike_free(expr); } -static ParsedSimpleExpr *parse_for_eval(const char *str, bool nonconst) +static ExprPyLike_Parsed *parse_for_eval(const char *str, bool nonconst) { const char *names[1] = { "x" }; - ParsedSimpleExpr *expr = BLI_simple_expr_parse(str, 1, names); + ExprPyLike_Parsed *expr = BLI_expr_pylike_parse(str, 1, names); - EXPECT_TRUE(BLI_simple_expr_is_valid(expr)); + EXPECT_TRUE(BLI_expr_pylike_is_valid(expr)); if (nonconst) { - EXPECT_FALSE(BLI_simple_expr_is_constant(expr)); + EXPECT_FALSE(BLI_expr_pylike_is_constant(expr)); } return expr; } -static void verify_eval_result(ParsedSimpleExpr *expr, double x, double value) +static void verify_eval_result(ExprPyLike_Parsed *expr, double x, double value) { double result; - eSimpleExpr_EvalStatus status = BLI_simple_expr_evaluate(expr, &result, 1, &x); + eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, &result, 1, &x); - EXPECT_EQ(status, SIMPLE_EXPR_SUCCESS); + EXPECT_EQ(status, EXPR_PYLIKE_SUCCESS); EXPECT_EQ(result, value); } -static void simple_expr_eval_test(const char *str, double x, double value) +static void expr_pylike_eval_test(const char *str, double x, double value) { - ParsedSimpleExpr *expr = parse_for_eval(str, true); + ExprPyLike_Parsed *expr = parse_for_eval(str, true); verify_eval_result(expr, x, value); - BLI_simple_expr_free(expr); + BLI_expr_pylike_free(expr); } -static void simple_expr_error_test(const char *str, double x, eSimpleExpr_EvalStatus error) +static void expr_pylike_error_test(const char *str, double x, eExprPyLike_EvalStatus error) { - ParsedSimpleExpr *expr = parse_for_eval(str, false); + ExprPyLike_Parsed *expr = parse_for_eval(str, false); double result; - eSimpleExpr_EvalStatus status = BLI_simple_expr_evaluate(expr, &result, 1, &x); + eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, &result, 1, &x); EXPECT_EQ(status, error); - BLI_simple_expr_free(expr); + BLI_expr_pylike_free(expr); } #define TEST_PARSE_FAIL(name, str) \ - TEST(simple_expr, ParseFail_##name) { simple_expr_parse_fail_test(str); } + TEST(expr_pylike, ParseFail_##name) { expr_pylike_parse_fail_test(str); } TEST_PARSE_FAIL(Empty, "") TEST_PARSE_FAIL(ConstHex, "0x0") @@ -113,15 +113,15 @@ TEST_PARSE_FAIL(Truncated10, "fmod(1,") /* Constant expression with working constant folding */ #define TEST_CONST(name, str, value) \ - TEST(simple_expr, Const_##name) { simple_expr_const_test(str, value, true); } + TEST(expr_pylike, Const_##name) { expr_pylike_const_test(str, value, true); } /* Constant expression but constant folding is not supported */ #define TEST_RESULT(name, str, value) \ - TEST(simple_expr, Result_##name) { simple_expr_const_test(str, value, false); } + TEST(expr_pylike, Result_##name) { expr_pylike_const_test(str, value, false); } /* Expression with an argument */ #define TEST_EVAL(name, str, x, value) \ - TEST(simple_expr, Eval_##name) { simple_expr_eval_test(str, x, value); } + TEST(expr_pylike, Eval_##name) { expr_pylike_eval_test(str, x, value); } TEST_CONST(Zero, "0", 0.0) TEST_CONST(Zero2, "00", 0.0) @@ -237,9 +237,9 @@ TEST_RESULT(Or2, "0 or 3", 3.0) TEST_RESULT(Bool1, "2 or 3 and 4", 2.0) TEST_RESULT(Bool2, "not 2 or 3 and 4", 4.0) -TEST(simple_expr, Eval_Ternary1) +TEST(expr_pylike, Eval_Ternary1) { - ParsedSimpleExpr *expr = parse_for_eval("x / 2 if x < 4 else x - 2 if x < 8 else x*2 - 12", true); + ExprPyLike_Parsed *expr = parse_for_eval("x / 2 if x < 4 else x - 2 if x < 8 else x*2 - 12", true); for (int i = 0; i <= 10; i++) { double x = i; @@ -248,63 +248,63 @@ TEST(simple_expr, Eval_Ternary1) verify_eval_result(expr, x, v); } - BLI_simple_expr_free(expr); + BLI_expr_pylike_free(expr); } -TEST(simple_expr, MultipleArgs) +TEST(expr_pylike, MultipleArgs) { const char* names[3] = { "x", "y", "x" }; double values[3] = { 1.0, 2.0, 3.0 }; - ParsedSimpleExpr *expr = BLI_simple_expr_parse("x*10 + y", 3, names); + ExprPyLike_Parsed *expr = BLI_expr_pylike_parse("x*10 + y", 3, names); - EXPECT_TRUE(BLI_simple_expr_is_valid(expr)); + EXPECT_TRUE(BLI_expr_pylike_is_valid(expr)); double result; - eSimpleExpr_EvalStatus status = BLI_simple_expr_evaluate(expr, &result, 3, values); + eExprPyLike_EvalStatus status = BLI_expr_pylike_eval(expr, &result, 3, values); - EXPECT_EQ(status, SIMPLE_EXPR_SUCCESS); + EXPECT_EQ(status, EXPR_PYLIKE_SUCCESS); EXPECT_EQ(result, 32.0); - BLI_simple_expr_free(expr); + BLI_expr_pylike_free(expr); } #define TEST_ERROR(name, str, x, code) \ - TEST(simple_expr, Error_##name) { simple_expr_error_test(str, x, code); } + TEST(expr_pylike, Error_##name) { expr_pylike_error_test(str, x, code); } -TEST_ERROR(DivZero1, "0 / 0", 0.0, SIMPLE_EXPR_MATH_ERROR) -TEST_ERROR(DivZero2, "1 / 0", 0.0, SIMPLE_EXPR_DIV_BY_ZERO) -TEST_ERROR(DivZero3, "1 / x", 0.0, SIMPLE_EXPR_DIV_BY_ZERO) -TEST_ERROR(DivZero4, "1 / x", 1.0, SIMPLE_EXPR_SUCCESS) +TEST_ERROR(DivZero1, "0 / 0", 0.0, EXPR_PYLIKE_MATH_ERROR) +TEST_ERROR(DivZero2, "1 / 0", 0.0, EXPR_PYLIKE_DIV_BY_ZERO) +TEST_ERROR(DivZero3, "1 / x", 0.0, EXPR_PYLIKE_DIV_BY_ZERO) +TEST_ERROR(DivZero4, "1 / x", 1.0, EXPR_PYLIKE_SUCCESS) -TEST_ERROR(SqrtDomain1, "sqrt(-1)", 0.0, SIMPLE_EXPR_MATH_ERROR) -TEST_ERROR(SqrtDomain2, "sqrt(x)", -1.0, SIMPLE_EXPR_MATH_ERROR) -TEST_ERROR(SqrtDomain3, "sqrt(x)", 0.0, SIMPLE_EXPR_SUCCESS) +TEST_ERROR(SqrtDomain1, "sqrt(-1)", 0.0, EXPR_PYLIKE_MATH_ERROR) +TEST_ERROR(SqrtDomain2, "sqrt(x)", -1.0, EXPR_PYLIKE_MATH_ERROR) +TEST_ERROR(SqrtDomain3, "sqrt(x)", 0.0, EXPR_PYLIKE_SUCCESS) -TEST_ERROR(PowDomain1, "pow(-1, 0.5)", 0.0, SIMPLE_EXPR_MATH_ERROR) -TEST_ERROR(PowDomain2, "pow(-1, x)", 0.5, SIMPLE_EXPR_MATH_ERROR) -TEST_ERROR(PowDomain3, "pow(-1, x)", 2.0, SIMPLE_EXPR_SUCCESS) +TEST_ERROR(PowDomain1, "pow(-1, 0.5)", 0.0, EXPR_PYLIKE_MATH_ERROR) +TEST_ERROR(PowDomain2, "pow(-1, x)", 0.5, EXPR_PYLIKE_MATH_ERROR) +TEST_ERROR(PowDomain3, "pow(-1, x)", 2.0, EXPR_PYLIKE_SUCCESS) -TEST_ERROR(Mixed1, "sqrt(x) + 1 / max(0, x)", -1.0, SIMPLE_EXPR_MATH_ERROR) -TEST_ERROR(Mixed2, "sqrt(x) + 1 / max(0, x)", 0.0, SIMPLE_EXPR_DIV_BY_ZERO) -TEST_ERROR(Mixed3, "sqrt(x) + 1 / max(0, x)", 1.0, SIMPLE_EXPR_SUCCESS) +TEST_ERROR(Mixed1, "sqrt(x) + 1 / max(0, x)", -1.0, EXPR_PYLIKE_MATH_ERROR) +TEST_ERROR(Mixed2, "sqrt(x) + 1 / max(0, x)", 0.0, EXPR_PYLIKE_DIV_BY_ZERO) +TEST_ERROR(Mixed3, "sqrt(x) + 1 / max(0, x)", 1.0, EXPR_PYLIKE_SUCCESS) -TEST(simple_expr, Error_Invalid) +TEST(expr_pylike, Error_Invalid) { - ParsedSimpleExpr *expr = BLI_simple_expr_parse("", 0, NULL); + ExprPyLike_Parsed *expr = BLI_expr_pylike_parse("", 0, NULL); double result; - EXPECT_EQ(BLI_simple_expr_evaluate(expr, &result, 0, NULL), SIMPLE_EXPR_INVALID); + EXPECT_EQ(BLI_expr_pylike_eval(expr, &result, 0, NULL), EXPR_PYLIKE_INVALID); - BLI_simple_expr_free(expr); + BLI_expr_pylike_free(expr); } -TEST(simple_expr, Error_ArgumentCount) +TEST(expr_pylike, Error_ArgumentCount) { - ParsedSimpleExpr *expr = parse_for_eval("x", false); + ExprPyLike_Parsed *expr = parse_for_eval("x", false); double result; - EXPECT_EQ(BLI_simple_expr_evaluate(expr, &result, 0, NULL), SIMPLE_EXPR_FATAL_ERROR); + EXPECT_EQ(BLI_expr_pylike_eval(expr, &result, 0, NULL), EXPR_PYLIKE_FATAL_ERROR); - BLI_simple_expr_free(expr); + BLI_expr_pylike_free(expr); } diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt index 1db7949d3a5..7574d42d5a1 100644 --- a/tests/gtests/blenlib/CMakeLists.txt +++ b/tests/gtests/blenlib/CMakeLists.txt @@ -43,6 +43,7 @@ endif() BLENDER_TEST(BLI_array_store "bf_blenlib") BLENDER_TEST(BLI_array_utils "bf_blenlib") +BLENDER_TEST(BLI_expr_pylike_eval "bf_blenlib") BLENDER_TEST(BLI_ghash "bf_blenlib") BLENDER_TEST(BLI_hash_mm2a "bf_blenlib") BLENDER_TEST(BLI_heap "bf_blenlib") @@ -55,7 +56,6 @@ BLENDER_TEST(BLI_math_geom "bf_blenlib") BLENDER_TEST(BLI_memiter "bf_blenlib") BLENDER_TEST(BLI_path_util "${BLI_path_util_extra_libs}") BLENDER_TEST(BLI_polyfill_2d "bf_blenlib") -BLENDER_TEST(BLI_simple_expr "bf_blenlib") BLENDER_TEST(BLI_stack "bf_blenlib") BLENDER_TEST(BLI_string "bf_blenlib") BLENDER_TEST(BLI_string_utf8 "bf_blenlib") |