summaryrefslogtreecommitdiffstats
path: root/tests/core/math/test_expression.h
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-09-11 12:34:39 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-09-11 12:34:39 +0200
commitd1caac5e75e633b52471afd3d437aaa50ed3c5fd (patch)
treee141c0acdc251a891a97c4d284661ad315fb0216 /tests/core/math/test_expression.h
parentc1bc42b3f1eb08c3e8fcff3121ac8f6f3270a4c1 (diff)
parentee9cea521d97088eb368cb1820db71100da9837b (diff)
downloadredot-engine-d1caac5e75e633b52471afd3d437aaa50ed3c5fd.tar.gz
Merge pull request #93856 from timothyqiu/expression-period
Fix parsing of `4.` in Expression
Diffstat (limited to 'tests/core/math/test_expression.h')
-rw-r--r--tests/core/math/test_expression.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/core/math/test_expression.h b/tests/core/math/test_expression.h
index 512d7932f9..c3e4280491 100644
--- a/tests/core/math/test_expression.h
+++ b/tests/core/math/test_expression.h
@@ -122,6 +122,59 @@ TEST_CASE("[Expression] Floating-point arithmetic") {
"Float multiplication-addition-subtraction-division should return the expected result.");
}
+TEST_CASE("[Expression] Floating-point notation") {
+ Expression expression;
+
+ CHECK_MESSAGE(
+ expression.parse("2.") == OK,
+ "The expression should parse successfully.");
+ CHECK_MESSAGE(
+ double(expression.execute()) == doctest::Approx(2.0),
+ "The expression should return the expected result.");
+
+ CHECK_MESSAGE(
+ expression.parse("(2.)") == OK,
+ "The expression should parse successfully.");
+ CHECK_MESSAGE(
+ double(expression.execute()) == doctest::Approx(2.0),
+ "The expression should return the expected result.");
+
+ CHECK_MESSAGE(
+ expression.parse(".3") == OK,
+ "The expression should parse successfully.");
+ CHECK_MESSAGE(
+ double(expression.execute()) == doctest::Approx(0.3),
+ "The expression should return the expected result.");
+
+ CHECK_MESSAGE(
+ expression.parse("2.+5.") == OK,
+ "The expression should parse successfully.");
+ CHECK_MESSAGE(
+ double(expression.execute()) == doctest::Approx(7.0),
+ "The expression should return the expected result.");
+
+ CHECK_MESSAGE(
+ expression.parse(".3-.8") == OK,
+ "The expression should parse successfully.");
+ CHECK_MESSAGE(
+ double(expression.execute()) == doctest::Approx(-0.5),
+ "The expression should return the expected result.");
+
+ CHECK_MESSAGE(
+ expression.parse("2.+.2") == OK,
+ "The expression should parse successfully.");
+ CHECK_MESSAGE(
+ double(expression.execute()) == doctest::Approx(2.2),
+ "The expression should return the expected result.");
+
+ CHECK_MESSAGE(
+ expression.parse(".0*0.") == OK,
+ "The expression should parse successfully.");
+ CHECK_MESSAGE(
+ double(expression.execute()) == doctest::Approx(0.0),
+ "The expression should return the expected result.");
+}
+
TEST_CASE("[Expression] Scientific notation") {
Expression expression;