testDivModWithIntMin.js (1593B)
1 var intMin = -2147483648; 2 var intMax = 2147483647; 3 var negativeZero = -0; 4 var zero = 0; 5 6 function testModNegativeZero() { 7 assertEq(intMin % -2147483648, -0); 8 assertEq(intMin % -1, -0); 9 assertEq(intMin % 1, -0); 10 assertEq(intMin % -2147483648, -0); 11 12 assertEq(((intMin|0) % -2147483648)|0, 0); 13 assertEq(((intMin|0) % -1)|0, 0); 14 assertEq(((intMin|0) % 1)|0, 0); 15 assertEq(((intMin|0) % -2147483648)|0, 0); 16 } 17 18 testModNegativeZero(); 19 testModNegativeZero(); 20 21 function testMinModulus1() { 22 assertEq(intMin % -3, -2); 23 assertEq(intMin % 3, -2); 24 assertEq(intMin % 10, -8); 25 assertEq(intMin % 2147483647, -1); 26 27 assertEq(((intMin|0) % -3)|0, -2); 28 assertEq(((intMin|0) % 3)|0, -2); 29 assertEq(((intMin|0) % 10)|0, -8); 30 assertEq(((intMin|0) % 2147483647)|0, -1); 31 } 32 33 testMinModulus1(); 34 testMinModulus1(); 35 36 function testMinModulus2() { 37 for (var i = -10; i <= 10; ++i) 38 assertEq(i % -2147483648, i); 39 assertEq(intMax % -2147483648, intMax); 40 41 for (var i = -10; i <= 10; ++i) 42 assertEq(((i|0) % -2147483648)|0, i); 43 assertEq(((intMax|0) % -2147483648)|0, intMax); 44 } 45 46 testMinModulus2(); 47 testMinModulus2(); 48 49 function testDivEdgeCases() { 50 assertEq(intMin / -2147483648, 1); 51 assertEq(intMin / -1, -intMin); 52 assertEq(negativeZero / -2147483648, 0); 53 assertEq(zero / -2147483648, -0); 54 55 assertEq(((intMin|0) / -2147483648)|0, 1); 56 assertEq(((intMin|0) / -1)|0, intMin); 57 assertEq(((negativeZero|0) / -2147483648)|0, 0); 58 assertEq(((zero|0) / -2147483648)|0, 0); 59 } 60 61 testDivEdgeCases(); 62 testDivEdgeCases();