1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/imptests/html/js/builtins/Math.maxmin.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +function testMathMaxMin(aFun) { 1.5 + var test_error = { name: "test" }; 1.6 + test(function() { 1.7 + assert_throws(test_error, function() { 1.8 + Math[aFun](NaN, { 1.9 + valueOf: function() { 1.10 + throw test_error; 1.11 + } 1.12 + }); 1.13 + }); 1.14 + }, "ToNumber should be called on all arguments: NaN."); 1.15 + test(function() { 1.16 + assert_throws(test_error, function() { 1.17 + Math[aFun](-Infinity, { 1.18 + valueOf: function() { 1.19 + throw test_error; 1.20 + } 1.21 + }); 1.22 + }); 1.23 + }, "ToNumber should be called on all arguments: -Infinity."); 1.24 + test(function() { 1.25 + assert_throws(test_error, function() { 1.26 + Math[aFun](Infinity, { 1.27 + valueOf: function() { 1.28 + throw test_error; 1.29 + } 1.30 + }); 1.31 + }); 1.32 + }, "ToNumber should be called on all arguments: Infinity."); 1.33 + test(function() { 1.34 + assert_throws(test_error, function() { 1.35 + Math[aFun]({ 1.36 + valueOf: function() { 1.37 + throw test_error; 1.38 + } 1.39 + }, 1.40 + { 1.41 + valueOf: function() { 1.42 + throw 7; 1.43 + } 1.44 + }); 1.45 + }); 1.46 + }, "ToNumber should be called left to right."); 1.47 + test(function() { 1.48 + assert_equals(Math[aFun]("1"), 1); 1.49 + }, "Should return a number."); 1.50 + test(function() { 1.51 + var expected = { 1.52 + "max": 0, 1.53 + "min": -0 1.54 + } 1.55 + assert_equals(Math[aFun](0, -0), expected[aFun]); 1.56 + assert_equals(Math[aFun](-0, 0), expected[aFun]); 1.57 + assert_equals(Math[aFun](0, 0), 0); 1.58 + assert_equals(Math[aFun](-0, -0), -0); 1.59 + }, "Should handle negative zero correctly."); 1.60 +}