Skip to content

Commit

Permalink
Merge pull request #2451 from zspitzer/LDEV-5180
Browse files Browse the repository at this point in the history
LDEV-5180 update testcases to test with preciseMath enabled and disabled
  • Loading branch information
michaeloffner authored Dec 10, 2024
2 parents a3d227e + bcb8ea1 commit a5c5cf7
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 43 deletions.
42 changes: 29 additions & 13 deletions test/functions/BitSHLN.cfc
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
component extends="org.lucee.cfml.test.LuceeTestCase"{

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

function run( testResults , testBox ) {
describe( title="Test suite for BitSHLN()", body=function() {
it(title="Checking BitSHLN() function with small shifts", body = function(currentSpec) {
function afterAll(){
application action="update" preciseMath=variables.preciseMath;
};

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

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

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

it(title="Checking BitSHLN() function with small shifts", body = function(currentSpec) {
assertEquals("2", BitSHLN(1, 1)); // 1 << 1 = 2
assertEquals("1073741824", BitSHLN(1, 30));
assertEquals("2147483648", BitSHLN(1, 31));
Expand All @@ -18,10 +32,10 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{

it(title="Checking BitSHLN() function with large number shift", body = function(currentSpec) {
// Shift a large number that's already near the boundary of 32-bit integer range
if ( variables.preciseMath )
assertEquals("4294967294", toString(BitSHLN(2147483647, 1))); // 2147483647 << 1 = 0 (overflow)
else
assertEquals("4294967296", toString(BitSHLN(2147483647, 1))); // 2147483647 << 1 = 0 (overflow)
application action="update" preciseMath=true;
assertEquals("4294967294", toString(BitSHLN(2147483647, 1))); // 2147483647 << 1 = 0 (overflow)
application action="update" preciseMath=false;
assertEquals("4294967296", toString(BitSHLN(2147483647, 1))); // 2147483647 << 1 = 0 (overflow)
});

it(title="Checking BitSHLN() function with negative shift", body = function(currentSpec) {
Expand All @@ -38,19 +52,21 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{

it(title="Checking BitSHLN() function with extreme shifts 16", body = function(currentSpec) {
// Extreme shift cases where the shift count is very large
application action="update" preciseMath=true;
assertEquals(65536, BitSHLN(1, 16)); // 1 << 64 = 0 (all bits shifted out in a 64-bit context)
});
it(title="Checking BitSHLN() function with extreme shifts 64", body = function(currentSpec) {
// Extreme shift cases where the shift count is very large
application action="update" preciseMath=true;
assertEquals("18446744073709551616",toString(BitSHLN(1, 64))); // 1 << 64 = 0 (all bits shifted out in a 64-bit context)
});
it(title="Checking BitSHLN() function with extreme shifts 128", body = function(currentSpec) {
// Extreme shift cases where the shift count is very large
if ( variables.preciseMath )
assertEquals("340282366920938463463374607431768211456",toString(BitSHLN(1, 128))); // 1 << 64 = 0 (all bits shifted out in a 64-bit context)
else
assertEquals("0", BitSHLN(1, 64)); // 1 << 64 = 0 (all bits shifted out in a 64-bit context)
application action="update" preciseMath=true;
assertEquals("340282366920938463463374607431768211456",toString(BitSHLN(1, 128))); // 1 << 64 = 0 (all bits shifted out in a 64-bit context)
application action="update" preciseMath=false;
assertEquals("0", BitSHLN(1, 64)); // 1 << 64 = 0 (all bits shifted out in a 64-bit context)
});
});
}
});
}
}
59 changes: 37 additions & 22 deletions test/functions/BitSHRN.cfc
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
component extends="org.lucee.cfml.test.LuceeTestCase"{

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

function run( testResults , testBox ) {
describe( title="Test suite for BitSHRN()", body=function() {
it(title="Checking BitSHRN() function", body = function( currentSpec ) {
assertEquals("0",BitSHRN(1,1));
assertEquals("0",BitSHRN(1,30));
assertEquals("0",BitSHRN(1,31));
assertEquals("0",BitSHRN(2,31));
assertEquals("32",BitSHRN(128,2));
});
variables.preciseMath = getApplicationSettings().preciseMath;
};

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

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

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

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

it(title="Checking BitSHRN() function", body = function( currentSpec ) {
assertEquals("0",BitSHRN(1,1));
assertEquals("0",BitSHRN(1,30));
assertEquals("0",BitSHRN(1,31));
assertEquals("0",BitSHRN(2,31));
assertEquals("32",BitSHRN(128,2));
});

it(title="Checking BitSHRN() function with shifting zero", body = function(currentSpec) {
assertEquals("1", BitSHRN(1, 0)); // 1 >> 0 = 1 (no shift should occur)
});

it(title="Checking BitSHRN() function with large numbers", body = function(currentSpec) {
if ( variables.preciseMath )
assertEquals("2147483647", BitSHRN(4294967295, 1)); // Large number shifted right
else
assertEquals("2147483648", BitSHRN(4294967295, 1)); // Large number shifted right
application action="update" preciseMath=true;
assertEquals("2147483647", BitSHRN(4294967295, 1)); // Large number shifted right
application action="update" preciseMath=false;
assertEquals("2147483648", BitSHRN(4294967295, 1)); // Large number shifted right
});

it(title="Checking BitSHRN() function with negative numbers", body = function(currentSpec) {
application action="update" preciseMath=true;
assertEquals("-1", BitSHRN(-2, 1)); // -2 >> 1 = -1 (propagating the sign bit)
assertEquals("-64", BitSHRN(-255, 2)); // -255 >> 2 = -64 (propagating the sign bit)
});

it(title="Checking BitSHRN() function with extreme shift values", body = function(currentSpec) {
if ( variables.preciseMath )
assertEquals("8", BitSHRN(147573952589676412928, 64)); // 128 >> 64 = 0 (all bits shifted out)
else
assertEquals("0", BitSHRN(128, 64)); // 128 >> 64 = 0 (all bits shifted out)
application action="update" preciseMath=true;
assertEquals("8", BitSHRN(147573952589676412928, 64)); // 128 >> 64 = 0 (all bits shifted out)
application action="update" preciseMath=false;
assertEquals("0", BitSHRN(128, 64)); // 128 >> 64 = 0 (all bits shifted out)
});
});
}
});
}
}
29 changes: 21 additions & 8 deletions test/functions/BitXor.cfc
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
component extends="org.lucee.cfml.test.LuceeTestCase"{

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

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

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

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

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

it(title="Checking BitXOr() function", body = function( currentSpec ) {
assertEquals("2",BitXOr(1, 3));
});
Expand All @@ -32,12 +45,12 @@ component extends="org.lucee.cfml.test.LuceeTestCase"{
// Both numbers are large and outside the standard int range
assertEquals("0", BitXOr("18446744073709551615", "18446744073709551615")); // All bits are the same, so XOR results in 0
});

it(title="Checking BitXOr() function with different large numbers", body = function(currentSpec) {
if ( variables.preciseMath )
assertEquals("18446744073709551614", BitXOr("18446744073709551615", "1")); // 111...11111111 XOR 000...00000001 = 111...11111110
else
assertEquals("9223372036854775807", BitXOr("18446744073709551615", "1")); // 111...11111111 XOR 000...00000001 = 111...11111110
application action="update" preciseMath=true;
assertEquals("18446744073709551614", BitXOr("18446744073709551615", "1")); // 111...11111111 XOR 000...00000001 = 111...11111110

application action="update" preciseMath=false;
assertEquals("9223372036854775807", BitXOr("18446744073709551615", "1")); // 111...11111111 XOR 000...00000001 = 111...11111110
});

});
Expand Down

0 comments on commit a5c5cf7

Please sign in to comment.