From dc429b152a620ca33cd570dfba31b0eb21f88769 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Mon, 9 Dec 2024 20:05:47 +0100 Subject: [PATCH] LDEV-5189 - add test cases (not tested yet) --- test/functions/LSParseNumber.cfc | 33 ++++++++++++++++++ test/functions/ParseNumber.cfc | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 test/functions/LSParseNumber.cfc create mode 100644 test/functions/ParseNumber.cfc diff --git a/test/functions/LSParseNumber.cfc b/test/functions/LSParseNumber.cfc new file mode 100644 index 0000000000..d170927ba1 --- /dev/null +++ b/test/functions/LSParseNumber.cfc @@ -0,0 +1,33 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" { + function beforeAll(){ + variables.preciseMath = getApplicationSettings().preciseMath; + }; + + function afterAll(){ + application action="update" precisemath=variables.preciseMath; + }; + + function run( testResults, testBox ){ + describe( "Test LSParseNumber", function(){ + + it( "Test with Large number", function(){ + var n = "2.305.843.009,01"; + var locale = "german (standard)"; + application action="update" preciseMath=false; + expect( LSParseNumber( n, locale ) ).toBe( 2305843009.01 ); + application action="update" preciseMath=true; + expect( LSparseNumber( n, locale ) ).toBe( 2305843009.01 ); // but it returns 2305843009.01 ? + }); + + it( "Test with Large number", function(){ + var n = "2.305.843.009.213.693.951,01"; + var locale = "german (standard)"; + application action="update" preciseMath=false; + expect( LSParseNumber( n, locale ) ).toBe( 2305843009213693696.01 ); + application action="update" preciseMath=true; + expect( LSparseNumber( n, locale ) ).toBe( 2305843009213693952.01 ); // LSParseNumber doesn't support big numbers + }); + + } ); + } +} \ No newline at end of file diff --git a/test/functions/ParseNumber.cfc b/test/functions/ParseNumber.cfc new file mode 100644 index 0000000000..7bbf624285 --- /dev/null +++ b/test/functions/ParseNumber.cfc @@ -0,0 +1,59 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" { + function beforeAll(){ + variables.preciseMath = getApplicationSettings().preciseMath; + }; + + function afterAll(){ + application action="update" precisemath=variables.preciseMath; + }; + + function run( testResults, testBox ){ + describe( "Test ParseNumber", function(){ + + it( "Test with smaller number", function(){ + var n = "2305843.44"; + application action="update" preciseMath=false; + expect( parseNumber( n ) ).toBe( 2305843.44 ); + application action="update" preciseMath=true; + expect( parseNumber( n ) ).toBe( 2305843.44 ); + }); + + it( "Test with Large number", function(){ + var n = "2305843009213693951.77"; + application action="update" preciseMath=false; + expect( parseNumber( n ) ).toBe( 2305843009213693696 ); + application action="update" preciseMath=true; + expect( parseNumber( n ) ).toBe( 2305843009213693951 ); // returns 2305843009213693951.77 + }); + + it( "Test Bin", function(){ + application action="update" preciseMath=false; + var n = "1000"; + var radix = "bin"; + expect( parseNumber( n, radix ) ).toBe( 8 ); + application action="update" preciseMath=true; + expect( parseNumber( n, radix ) ).toBe( 8 ); + }); + + it( "Test Oct", function(){ + application action="update" preciseMath=false; + var n = "1000"; + var radix = "oct"; + expect( parseNumber( n, radix ) ).toBe( 512 ); + application action="update" preciseMath=true; + expect( parseNumber( n, radix ) ).toBe( 512 ); + }); + + it( "Test Hex", function(){ + application action="update" preciseMath=false; + var n = "1000"; + var radix = "hex"; + expect( parseNumber( n, radix ) ).toBe( 4096 ); + application action="update" preciseMath=true; + expect( parseNumber( n, radix ) ).toBe( 4096 ); + }); + + } ); + } + +} \ No newline at end of file