1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
{
"testCollection": {
"name": "15.7.4.5_Number.prototype.toFixed",
"numTests": 6,
"tests": [
{
"section": "15.7.4.5",
"description": "calling on Number prototype object",
"test": "//CHECK#1\nif(Number.prototype.toFixed() !== \"0\"){\n $ERROR('#1: Number.prototype.toFixed() === \"0\"');\n}\n\n//CHECK#2\nif(Number.prototype.toFixed(0) !== \"0\"){\n $ERROR('#2: Number.prototype.toFixed(0) === \"0\"');\n}\n\n//CHECK#3\nif(Number.prototype.toFixed(1) !== \"0.0\"){\n $ERROR('#3: Number.prototype.toFixed(1) === \"0.0\"');\n}\n\n//CHECK#4\nif(Number.prototype.toFixed(1.1) !== \"0.0\"){\n $ERROR('#4: Number.prototype.toFixed(1.1) === \"0.0\"');\n}\n\n//CHECK#5\nif(Number.prototype.toFixed(0.9) !== \"0\"){\n $ERROR('#5: Number.prototype.toFixed(0.9) === \"0\"');\n}\n\n//CHECK#6\nif(Number.prototype.toFixed(\"1\") !== \"0.0\"){\n $ERROR('#6: Number.prototype.toFixed(\"1\") === \"0.0\"');\n}\n\n//CHECK#7\nif(Number.prototype.toFixed(\"1.1\") !== \"0.0\"){\n $ERROR('#7: Number.prototype.toFixed(\"1.1\") === \"0.0\"');\n}\n\n//CHECK#8\nif(Number.prototype.toFixed(\"0.9\") !== \"0\"){\n $ERROR('#8: Number.prototype.toFixed(\"0.9\") === \"0\"');\n}\n\n//CHECK#9\nif(Number.prototype.toFixed(Number.NaN) !== \"0\"){\n $ERROR('#9: Number.prototype.toFixed(Number.NaN) === \"0\"');\n}\n\n//CHECK#10\nif(Number.prototype.toFixed(\"some string\") !== \"0\"){\n $ERROR('#9: Number.prototype.toFixed(\"some string\") === \"0\"');\n}\n\n//CHECK#10\ntry{\n if(Number.prototype.toFixed(-0.1) !== \"0\"){\n $ERROR('#10: Number.prototype.toFixed(-0.1) === \"0\"');\n }\n}\ncatch(e){\n $ERROR('#10: Number.prototype.toFixed(-0.1) should not throw '+e);\n}\n",
"id": "S15.7.4.5_A1.1_T01"
},
{
"section": "15.7.4.5",
"description": "calling on Number object",
"test": "//CHECK#1\nif((new Number(1)).toFixed() !== \"1\"){\n $ERROR('#1: (new Number(1)).prototype.toFixed() === \"1\"');\n}\n\n//CHECK#2\nif((new Number(1)).toFixed(0) !== \"1\"){\n $ERROR('#2: (new Number(1)).prototype.toFixed(0) === \"1\"');\n}\n\n//CHECK#3\nif((new Number(1)).toFixed(1) !== \"1.0\"){\n $ERROR('#3: (new Number(1)).prototype.toFixed(1) === \"1.0\"');\n}\n\n//CHECK#4\nif((new Number(1)).toFixed(1.1) !== \"1.0\"){\n $ERROR('#4: (new Number(1)).toFixed(1.1) === \"1.0\"');\n}\n\n//CHECK#5\nif((new Number(1)).toFixed(0.9) !== \"1\"){\n $ERROR('#5: (new Number(1)).toFixed(0.9) === \"1\"');\n}\n\n//CHECK#6\nif((new Number(1)).toFixed(\"1\") !== \"1.0\"){\n $ERROR('#6: (new Number(1)).toFixed(\"1\") === \"1.0\"');\n}\n\n//CHECK#7\nif((new Number(1)).toFixed(\"1.1\") !== \"1.0\"){\n $ERROR('#7: (new Number(1)).toFixed(\"1.1\") === \"1.0\"');\n}\n\n//CHECK#8\nif((new Number(1)).toFixed(\"0.9\") !== \"1\"){\n $ERROR('#8: (new Number(1)).toFixed(\"0.9\") === \"1\"');\n}\n\n//CHECK#9\nif((new Number(1)).toFixed(Number.NaN) !== \"1\"){\n $ERROR('#9: (new Number(1)).toFixed(Number.NaN) === \"1\"');\n}\n\n//CHECK#10\nif((new Number(1)).toFixed(\"some string\") !== \"1\"){\n $ERROR('#9: (new Number(1)).toFixed(\"some string\") === \"1\"');\n}\n\n//CHECK#10\ntry{\n if((new Number(1)).toFixed(-0.1) !== \"1\"){\n $ERROR('#10: (new Number(1)).toFixed(-0.1) === \"1\"');\n }\n}\ncatch(e){\n $ERROR('#10: (new Number(1)).toFixed(-0.1) should not throw '+e);\n}\n",
"id": "S15.7.4.5_A1.1_T02"
},
{
"section": "15.7.4.5",
"description": "NaN is computed by new Number(\"string\")",
"test": "//CHECK#1\nif((new Number(\"a\")).toFixed() !== \"NaN\"){\n $ERROR('#1: (new Number(\"a\")).prototype.toFixed() === \"NaN\"');\n}\n\n//CHECK#2\nif((new Number(\"a\")).toFixed(0) !== \"NaN\"){\n $ERROR('#2: (new Number(\"a\")).prototype.toFixed(0) === \"NaN\"');\n}\n\n//CHECK#3\nif((new Number(\"a\")).toFixed(1) !== \"NaN\"){\n $ERROR('#3: (new Number(\"a\")).prototype.toFixed(1) === \"NaN\"');\n}\n\n//CHECK#4\nif((new Number(\"a\")).toFixed(1.1) !== \"NaN\"){\n $ERROR('#4: (new Number(\"a\")).toFixed(1.1) === \"NaN\"');\n}\n\n//CHECK#5\nif((new Number(\"a\")).toFixed(0.9) !== \"NaN\"){\n $ERROR('#5: (new Number(\"a\")).toFixed(0.9) === \"NaN\"');\n}\n\n//CHECK#6\nif((new Number(\"a\")).toFixed(\"1\") !== \"NaN\"){\n $ERROR('#6: (new Number(\"a\")).toFixed(\"1\") === \"NaN\"');\n}\n\n//CHECK#7\nif((new Number(\"a\")).toFixed(\"1.1\") !== \"NaN\"){\n $ERROR('#7: (new Number(\"a\")).toFixed(\"1.1\") === \"NaN\"');\n}\n\n//CHECK#8\nif((new Number(\"a\")).toFixed(\"0.9\") !== \"NaN\"){\n $ERROR('#8: (new Number(\"a\")).toFixed(\"0.9\") === \"NaN\"');\n}\n\n//CHECK#9\nif((new Number(\"a\")).toFixed(Number.NaN) !== \"NaN\"){\n $ERROR('#9: (new Number(\"a\")).toFixed(Number.NaN) === \"NaN\"');\n}\n\n//CHECK#10\nif((new Number(\"a\")).toFixed(\"some string\") !== \"NaN\"){\n $ERROR('#9: (new Number(\"a\")).toFixed(\"some string\") === \"NaN\"');\n}\n\n//CHECK#10\ntry{\n s = (new Number(\"a\")).toFixed(Number.POSITIVE_INFINITY);\n $ERROR('#10: (new Number(\"a\")).toFixed(Number.POSITIVE_INFINITY) should throw RangeError, not return NaN');\n}\ncatch(e){\n if(!(e instanceof RangeError)){\n $ERROR('#10: (new Number(\"a\")).toFixed(Number.POSITIVE_INFINITY) should throw RangeError, not '+e);\n }\n}\n",
"id": "S15.7.4.5_A1.3_T01"
},
{
"section": "15.7.4.5",
"description": "direct usage of NaN",
"test": "//CHECK#1\nif(Number.NaN.toFixed() !== \"NaN\"){\n $ERROR('#1: Number.NaN.prototype.toFixed() === \"NaN\"');\n}\n\n//CHECK#2\nif(Number.NaN.toFixed(0) !== \"NaN\"){\n $ERROR('#2: Number.NaN.prototype.toFixed(0) === \"NaN\"');\n}\n\n//CHECK#3\nif(Number.NaN.toFixed(1) !== \"NaN\"){\n $ERROR('#3: Number.NaN.prototype.toFixed(1) === \"NaN\"');\n}\n\n//CHECK#4\nif(Number.NaN.toFixed(1.1) !== \"NaN\"){\n $ERROR('#4: Number.NaN.toFixed(1.1) === \"NaN\"');\n}\n\n//CHECK#5\nif(Number.NaN.toFixed(0.9) !== \"NaN\"){\n $ERROR('#5: Number.NaN.toFixed(0.9) === \"NaN\"');\n}\n\n//CHECK#6\nif(Number.NaN.toFixed(\"1\") !== \"NaN\"){\n $ERROR('#6: Number.NaN.toFixed(\"1\") === \"NaN\"');\n}\n\n//CHECK#7\nif(Number.NaN.toFixed(\"1.1\") !== \"NaN\"){\n $ERROR('#7: Number.NaN.toFixed(\"1.1\") === \"NaN\"');\n}\n\n//CHECK#8\nif(Number.NaN.toFixed(\"0.9\") !== \"NaN\"){\n $ERROR('#8: Number.NaN.toFixed(\"0.9\") === \"NaN\"');\n}\n\n//CHECK#9\nif(Number.NaN.toFixed(Number.NaN) !== \"NaN\"){\n $ERROR('#9: Number.NaN.toFixed(Number.NaN) === \"NaN\"');\n}\n\n//CHECK#10\nif(Number.NaN.toFixed(\"some string\") !== \"NaN\"){\n $ERROR('#9: Number.NaN.toFixed(\"some string\") === \"NaN\"');\n}\n\n//CHECK#10\ntry{\n s = Number.NaN.toFixed(Number.POSITIVE_INFINITY);\n $ERROR('#10: Number.NaN.toFixed(Number.POSITIVE_INFINITY) should throw RangeError, not return NaN');\n}\ncatch(e){\n if(!(e instanceof RangeError)){\n $ERROR('#10: Number.NaN.toFixed(Number.POSITIVE_INFINITY) should throw RangeError, not '+e);\n }\n}\n",
"id": "S15.7.4.5_A1.3_T02"
},
{
"section": "15.7.4.5",
"description": "x is 10^21",
"test": "//CHECK#1\nif((new Number(1e21)).toFixed() !== String(1e21)){\n $ERROR('#1: (new Number(1e21)).prototype.toFixed() === String(1e21)');\n}\n\n//CHECK#2\nif((new Number(1e21)).toFixed(0) !== String(1e21)){\n $ERROR('#2: (new Number(1e21)).prototype.toFixed(0) === String(1e21)');\n}\n\n//CHECK#3\nif((new Number(1e21)).toFixed(1) !== String(1e21)){\n $ERROR('#3: (new Number(1e21)).prototype.toFixed(1) === String(1e21)');\n}\n\n//CHECK#4\nif((new Number(1e21)).toFixed(1.1) !== String(1e21)){\n $ERROR('#4: (new Number(1e21)).toFixed(1.1) === String(1e21)');\n}\n\n//CHECK#5\nif((new Number(1e21)).toFixed(0.9) !== String(1e21)){\n $ERROR('#5: (new Number(1e21)).toFixed(0.9) === String(1e21)');\n}\n\n//CHECK#6\nif((new Number(1e21)).toFixed(\"1\") !== String(1e21)){\n $ERROR('#6: (new Number(1e21)).toFixed(\"1\") === String(1e21)');\n}\n\n//CHECK#7\nif((new Number(1e21)).toFixed(\"1.1\") !== String(1e21)){\n $ERROR('#7: (new Number(1e21)).toFixed(\"1.1\") === String(1e21)');\n}\n\n//CHECK#8\nif((new Number(1e21)).toFixed(\"0.9\") !== String(1e21)){\n $ERROR('#8: (new Number(1e21)).toFixed(\"0.9\") === String(1e21)');\n}\n\n//CHECK#9\nif((new Number(1e21)).toFixed(Number.NaN) !== String(1e21)){\n $ERROR('#9: (new Number(1e21)).toFixed(Number.NaN) === String(1e21)');\n}\n\n//CHECK#10\nif((new Number(1e21)).toFixed(\"some string\") !== String(1e21)){\n $ERROR('#9: (new Number(1e21)).toFixed(\"some string\") === String(1e21)');\n}\n\n//CHECK#10\ntry{\n s = (new Number(1e21)).toFixed(Number.POSITIVE_INFINITY);\n $ERROR('#10: (new Number(1e21)).toFixed(Number.POSITIVE_INFINITY) should throw RangeError, not return NaN');\n}\ncatch(e){\n if(!(e instanceof RangeError)){\n $ERROR('#10: (new Number(1e21)).toFixed(Number.POSITIVE_INFINITY) should throw RangeError, not '+e);\n }\n}\n",
"id": "S15.7.4.5_A1.4_T01"
},
{
"section": "15.7.4.5",
"description": "Checking Number prototype itself",
"test": "//CHECK#1\nif(Number.prototype.toFixed.hasOwnProperty(\"length\") !== true){\n $ERROR('#1: The length property of the toFixed method is 1');\n}\n\n//CHECK#2\nif(Number.prototype.toFixed.length !== 1){\n $ERROR('#2: The length property of the toFixed method is 1');\n}\n",
"id": "S15.7.4.5_A2_T01"
}
]
}
}
|