From aad67cdad90a8c66a66a8e35b21212f6c3ed23ea Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 16 Nov 2021 11:00:35 +0000 Subject: [PATCH] Test Nasal trunc/floor/round --- .../unit_tests/Scripting/testNasalSys.cxx | 24 +++++++++++++++++++ .../unit_tests/Scripting/testNasalSys.hxx | 2 ++ 2 files changed, 26 insertions(+) diff --git a/test_suite/unit_tests/Scripting/testNasalSys.cxx b/test_suite/unit_tests/Scripting/testNasalSys.cxx index ce694f026..d536a8958 100644 --- a/test_suite/unit_tests/Scripting/testNasalSys.cxx +++ b/test_suite/unit_tests/Scripting/testNasalSys.cxx @@ -203,3 +203,27 @@ void NasalSysTests::testCompileLarge() // )"); // CPPUNIT_ASSERT(ok); } + + +void NasalSysTests::testRoundFloor() +{ + auto nasalSys = globals->get_subsystem(); + nasalSys->getAndClearErrorList(); + + bool ok = FGTestApi::executeNasal(R"( + unitTest.assert_equal(math.round(121266, 1000), 121000); + unitTest.assert_equal(math.round(121.1234, 0.01), 121.12); + unitTest.assert_equal(math.round(121266, 10), 121270); + + unitTest.assert_equal(math.floor(121766, 1000), 121000); + unitTest.assert_equal(math.floor(121.1299, 0.01), 121.12); + + # floor towards lower value + unitTest.assert_equal(math.floor(-121.1229, 0.01), -121.13); + + # truncate towards zero + unitTest.assert_equal(math.trunc(-121.1229, 0.01), -121.12); + unitTest.assert_equal(math.trunc(-121.1299, 0.01), -121.12); + )"); + CPPUNIT_ASSERT(ok); +} diff --git a/test_suite/unit_tests/Scripting/testNasalSys.hxx b/test_suite/unit_tests/Scripting/testNasalSys.hxx index b328de3b3..256bab50e 100644 --- a/test_suite/unit_tests/Scripting/testNasalSys.hxx +++ b/test_suite/unit_tests/Scripting/testNasalSys.hxx @@ -35,6 +35,7 @@ class NasalSysTests : public CppUnit::TestFixture CPPUNIT_TEST(testCommands); CPPUNIT_TEST(testAirportGhost); CPPUNIT_TEST(testCompileLarge); + CPPUNIT_TEST(testRoundFloor); CPPUNIT_TEST_SUITE_END(); public: @@ -49,6 +50,7 @@ public: void testCommands(); void testAirportGhost(); void testCompileLarge(); + void testRoundFloor(); }; #endif // _FG_NASALSYS_UNIT_TESTS_HXX