| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
var gTestfile = 'regress-363040-01.js'; |
| 7 |
|
| 8 |
var BUGNUMBER = 363040; |
| 9 |
var summary = 'Array.prototype.reduce, Array.prototype.reduceRight'; |
| 10 |
var actual = ''; |
| 11 |
var expect = ''; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
test(); |
| 16 |
|
| 17 |
|
| 18 |
function test() |
| 19 |
{ |
| 20 |
enterFunc ('test'); |
| 21 |
printBugNumber(BUGNUMBER); |
| 22 |
printStatus (summary); |
| 23 |
|
| 24 |
function f(x,y) { return '(' + x + '+' + y + ')';} |
| 25 |
|
| 26 |
var testdesc; |
| 27 |
var arr0elms = []; |
| 28 |
var arr1elms = [1]; |
| 29 |
var arr2elms = [1, 2]; |
| 30 |
|
| 31 |
testdesc = 'Test reduce of empty array without initializer.'; |
| 32 |
try |
| 33 |
{ |
| 34 |
expect = 'TypeError: reduce of empty array with no initial value'; |
| 35 |
arr0elms.reduce(f); |
| 36 |
} |
| 37 |
catch(ex) |
| 38 |
{ |
| 39 |
actual = ex + ''; |
| 40 |
} |
| 41 |
reportCompare(expect + '', actual + '', testdesc + ' : ' + expect); |
| 42 |
|
| 43 |
testdesc = 'Test reduceRight of empty array without initializer.'; |
| 44 |
try |
| 45 |
{ |
| 46 |
expect = 'TypeError: reduce of empty array with no initial value'; |
| 47 |
arr0elms.reduceRight(f); |
| 48 |
} |
| 49 |
catch(ex) |
| 50 |
{ |
| 51 |
actual = ex + ''; |
| 52 |
} |
| 53 |
reportCompare(expect + '', actual + '', testdesc + ' : ' + expect); |
| 54 |
|
| 55 |
testdesc = 'Test reduce of empty array with initial value.'; |
| 56 |
expect = 'a'; |
| 57 |
actual = arr0elms.reduce(f, 'a'); |
| 58 |
reportCompare(expect + '', actual + '', testdesc + ' : ' + expect); |
| 59 |
|
| 60 |
testdesc = 'Test reduceRight of empty array with initial value.'; |
| 61 |
expect = 'a'; |
| 62 |
actual = arr0elms.reduceRight(f, 'a'); |
| 63 |
reportCompare(expect + '', actual + '', testdesc +' : ' + expect); |
| 64 |
|
| 65 |
testdesc = 'Test reduce of 1 element array with no initializer.'; |
| 66 |
expect = '1'; |
| 67 |
actual = arr1elms.reduce(f); |
| 68 |
reportCompare(expect + '', actual + '', testdesc + ' : ' + expect); |
| 69 |
|
| 70 |
testdesc = 'Test reduceRight of 1 element array with no initializer.'; |
| 71 |
expect = '1'; |
| 72 |
actual = arr1elms.reduceRight(f); |
| 73 |
reportCompare(expect + '', actual + '', testdesc + ' : ' + expect); |
| 74 |
|
| 75 |
testdesc = 'Test reduce of 2 element array with no initializer.'; |
| 76 |
expect = '(1+2)'; |
| 77 |
actual = arr2elms.reduce(f); |
| 78 |
reportCompare(expect + '', actual + '', testdesc + ' : ' + expect); |
| 79 |
|
| 80 |
testdesc = 'Test reduce of 2 element array with initializer.'; |
| 81 |
expect = '((a+1)+2)'; |
| 82 |
actual = arr2elms.reduce(f,'a'); |
| 83 |
reportCompare(expect + '', actual + '', testdesc + ' : ' + expect); |
| 84 |
|
| 85 |
testdesc = 'Test reduceRight of 2 element array with no initializer.'; |
| 86 |
expect = '(2+1)'; |
| 87 |
actual = arr2elms.reduceRight(f); |
| 88 |
reportCompare(expect + '', actual + '', testdesc + ' : ' + expect); |
| 89 |
|
| 90 |
testdesc = 'Test reduceRight of 2 element array with no initializer.'; |
| 91 |
expect = '((a+2)+1)'; |
| 92 |
actual = arr2elms.reduceRight(f,'a'); |
| 93 |
reportCompare(expect + '', actual + '', testdesc + ' : ' + expect); |
| 94 |
|
| 95 |
exitFunc ('test'); |
| 96 |
} |