1
0
Fork 0

Test Nasal trunc/floor/round

This commit is contained in:
James Turner 2021-11-16 11:00:35 +00:00
parent 6320c06e6b
commit aad67cdad9
2 changed files with 26 additions and 0 deletions

View file

@ -203,3 +203,27 @@ void NasalSysTests::testCompileLarge()
// )");
// CPPUNIT_ASSERT(ok);
}
void NasalSysTests::testRoundFloor()
{
auto nasalSys = globals->get_subsystem<FGNasalSys>();
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);
}

View file

@ -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