Skip to content

Commit

Permalink
LDEV-5161 update tests to test both preciseMath true and false
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Dec 4, 2024
1 parent e41ff0b commit bb9165e
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 45 deletions.
25 changes: 20 additions & 5 deletions test/functions/ACos.cfc
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
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( title="Test suite for acos()", body=function() {

beforeEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

afterEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

it(title="checking acos(1) function", body = function( currentSpec ) {
assertEquals(0,acos(1));
});

it(title="checking acos(0.7) function", body = function( currentSpec ) {
if ( getApplicationSettings().preciseMath )
assertEquals("0.7953988301841436", toString(acos(0.7)));
else
assertEquals("0.795398830184", toString(acos(0.7)));

application action="update" preciseMath=true;
assertEquals("0.7953988301841436", toString(acos(0.7)));
application action="update" preciseMath=false;
assertEquals("0.795398830184", toString(acos(0.7)));
});

it(title="checking acos() function invalid range", body = function( currentSpec ) {
Expand Down
24 changes: 20 additions & 4 deletions test/functions/ASin.cfc
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
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( title="Test suite for ASin()", body=function() {
beforeEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

afterEach( function(){
application action="update" preciseMath=variables.preciseMath;
});
it(title="Checking ASin() function", body = function( currentSpec ) {
if ( getApplicationSettings().preciseMath )
assertEquals("0.3046926540153975",tostring( asin(0.3) ));
else
assertEquals("0.304692654015",tostring( asin(0.3) ));
application action="update" preciseMath=true;
assertEquals("0.3046926540153975",tostring( asin(0.3) ));
application action="update" preciseMath=false;
assertEquals("0.304692654015",tostring( asin(0.3) ));
});
it(title="Checking ASin() function invaid input", body = function( currentSpec ) {
try{
Expand Down
27 changes: 18 additions & 9 deletions test/functions/Atn.cfc
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
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( title="Test suite for Atn()", body=function() {
it(title="Checking Atn() function", body = function( currentSpec ) {
if ( getApplicationSettings().preciseMath ){
assertEquals( "0.2914567944778671",tostring(atn(0.3)));
assertEquals( "0.9151007005533605",tostring(atn(1.3)));
assertEquals("-1.5607966601082315",tostring(atn(-100)));
} else {
assertEquals( "0.291456794478",tostring(atn(0.3)));
assertEquals( "0.915100700553",tostring(atn(1.3)));
assertEquals("-1.560796660108",tostring(atn(-100)));
}
application action="update" preciseMath=true;
assertEquals( "0.2914567944778671",tostring(atn(0.3)));
assertEquals( "0.9151007005533605",tostring(atn(1.3)));
assertEquals("-1.5607966601082315",tostring(atn(-100)));

application action="update" preciseMath=false;
assertEquals( "0.291456794478",tostring(atn(0.3)));
assertEquals( "0.915100700553",tostring(atn(1.3)));
assertEquals("-1.560796660108",tostring(atn(-100)));

});
});
Expand Down
27 changes: 21 additions & 6 deletions test/functions/BitAnd.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
variables.preciseMath = getApplicationSettings().preciseMath;
};

function afterAll(){
application action="update" preciseMath=variables.preciseMath;
};

function run( testResults , testBox ) {
describe( title="Test suite for BitAnd()", body=function() {

beforeEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

afterEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

it(title="Checking BitAnd() function integers", body = function( currentSpec ) {
assertEquals("0",BitAnd(1, 0));
assertEquals("0",BitAnd(0, 0));
Expand All @@ -21,13 +34,13 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{

it(title="Checking BitAnd() function float edge case ", body = function( currentSpec ) {
// they can be converted because they are below the threshold
application action="update" preciseMath=true;
assertEquals("0",BitAnd(1, 0.00000000000001));
if ( variables.preciseMath ) {
assertEquals("1",BitAnd(1, 0.999999999999999));
} else {
var Integer=createObject("java","java.lang.Integer");
assertEquals("1",BitAnd(1, Integer.MAX_VALUE));
}
assertEquals("1",BitAnd(1, 0.999999999999999));

application action="update" preciseMath=false;
var Integer=createObject("java","java.lang.Integer");
assertEquals("1",BitAnd(1, Integer.MAX_VALUE));
});

it("should correctly perform bitwise AND between two positive numbers", function() {
Expand Down Expand Up @@ -55,10 +68,12 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});

it("should correctly perform bitwise AND between two large BigInteger values", function() {
application action="update" preciseMath=true;
expect( BitAnd(9223372036854775808, 9223372036854775807) ).toBe(0);
});

it("should correctly perform bitwise AND between a BigInteger and a smaller integer", function() {
application action="update" preciseMath=true;
// Expect zero because 255 does not overlap with high bits of largeNumber
expect( BitAnd(9223372036854775808, 255) ).toBe(0);
});
Expand Down
41 changes: 29 additions & 12 deletions test/functions/BitOr.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
variables.preciseMath = getApplicationSettings().preciseMath;
};

function afterAll(){
application action="update" preciseMath=variables.preciseMath;
};


function run( testResults , testBox ) {
describe( title="Test suite for BitOr()", body=function() {

beforeEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

afterEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

it(title="Checking BitOr() function", body = function( currentSpec ) {
assertEquals("1", BitOr(1, 0));
});
Expand All @@ -27,27 +41,30 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});

it("should handle bitwise OR where one number is the maximum integer value", function() {
if ( variables.preciseMath )
expect( BitOr(2147483647, 1) ).toBe(2147483647);
else
expect( BitOr(2147483647, 1) ).toBe(2147483648);
application action="update" preciseMath=true;
expect( BitOr(2147483647, 1) ).toBe(2147483647);
application action="update" preciseMath=false;
expect( BitOr(2147483647, 1) ).toBe(2147483648);
});

it("should return the non-zero value when one number is zero", function() {
expect( BitOr(0, 0) ).toBe(0);
});

it("should correctly perform bitwise OR between two large String values", function() {
if ( variables.preciseMath )
expect( BitOr("9223372036854775808", "9223372036854775807") ).toBe("18446744073709551615");
else
expect( BitOr("9223372036854775808", "9223372036854775807") ).toBe("9223372036854775807");
systemOutput("------", true);
application action="update" preciseMath=true;
systemOutput(getApplicationSettings().preciseMath, true);
expect( BitOr("9223372036854775808", "9223372036854775807") ).toBe("18446744073709551615");
application action="update" preciseMath=false;
systemOutput(getApplicationSettings().preciseMath, true);
expect( BitOr("9223372036854775808", "9223372036854775807") ).toBe("9223372036854775807");
});
it("should correctly perform bitwise OR between two large Number values", function() {
if ( variables.preciseMath )
expect( BitOr(9223372036854775808, 9223372036854775807) ).toBe(18446744073709551615);
else
expect( BitOr(9223372036854775808, 9223372036854775807) ).toBe(9223372036854775807);
application action="update" preciseMath=true;
expect( BitOr(9223372036854775808, 9223372036854775807) ).toBe(18446744073709551615);
application action="update" preciseMath=false;
expect( BitOr(9223372036854775808, 9223372036854775807) ).toBe(9223372036854775807);
});

it("should correctly perform bitwise OR between a BigInteger and a smaller integer", function() {
Expand Down
27 changes: 23 additions & 4 deletions test/functions/sin.cfc
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {

function beforeAll(){
variables.preciseMath = getApplicationSettings().preciseMath;
};

function afterAll(){
application action="update" preciseMath=variables.preciseMath;
};

public function run( testResults, testBox ) {
describe( title="Testcase for sin() function", body=function() {


beforeEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

afterEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

it(title="Checking the sin() function", body=function( currentSpec ) {
var a = 90;
expect(sin(a)).toBe(0.8939966636005579);
Expand All @@ -18,10 +37,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase" {

it(title="Checking the sin() function to string", body=function( currentSpec ) {
var a = 90;
if ( getApplicationSettings().preciseMath )
expect("#tostring(sin(a))#").toBe("0.8939966636005579");
else
expect("#tostring(sin(a))#").toBe("0.893996663601");
application action="update" preciseMath=true;
expect("#tostring(sin(a))#").toBe("0.8939966636005579");
application action="update" preciseMath=false;
expect("#tostring(sin(a))#").toBe("0.893996663601");

});
});
Expand Down
28 changes: 23 additions & 5 deletions test/tickets/LDEV3661.cfc
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
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( title="Test suite for LDEV-3661", body=function() {

beforeEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

afterEach( function(){
application action="update" preciseMath=variables.preciseMath;
});

it( title='check deserializeJSON 1',body=function( currentSpec ) {

var myJSON = '{"lat":20.12283319000001}';
Expand All @@ -11,13 +28,14 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
});

it( title='check deserializeJSON 2',body=function( currentSpec ) {

application action="update" preciseMath=true;
var myJSON = '{"lat":20.12283319000001}';
var decoded = deserializeJSON( myJSON );
if ( getApplicationSettings().preciseMath )
expect( serializeJSON( decoded ) ).toBe( '{"lat":20.12283319000001}' );
else
expect( serializeJSON( decoded ) ).toBe( '{"lat":20.12283319}' );
expect( serializeJSON( decoded ) ).toBe( '{"lat":20.12283319000001}' );

application action="update" preciseMath=false;
decoded = deserializeJSON( myJSON );
expect( serializeJSON( decoded ) ).toBe( '{"lat":20.12283319}' );

});

Expand Down

0 comments on commit bb9165e

Please sign in to comment.