michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: * Contributor: Blake Kaplan michael@0: */ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: var BUGNUMBER = 386030; michael@0: var summary = 'Array.reduce should ignore holes'; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: function add(a, b) { return a + b; } michael@0: function testreduce(v) { return v == 3 ? "PASS" : "FAIL"; } michael@0: michael@0: expect = 'PASS'; michael@0: michael@0: try { michael@0: a = new Array(2); michael@0: a[1] = 3; michael@0: actual = testreduce(a.reduce(add)); michael@0: } catch (e) { michael@0: actual = "FAIL, reduce"; michael@0: } michael@0: reportCompare(expect, actual, summary + ': 1'); michael@0: michael@0: try { michael@0: a = new Array(2); michael@0: a[0] = 3; michael@0: actual = testreduce(a.reduceRight(add)); michael@0: } catch (e) { michael@0: actual = "FAIL, reduceRight"; michael@0: } michael@0: reportCompare(expect, actual, summary + ': 2'); michael@0: michael@0: try { michael@0: a = new Array(2); michael@0: a.reduce(add); michael@0: actual = "FAIL, empty reduce"; michael@0: } catch (e) { michael@0: actual = "PASS"; michael@0: } michael@0: reportCompare(expect, actual, summary + ': 3'); michael@0: michael@0: try { michael@0: a = new Array(2); michael@0: print(a.reduceRight(add)); michael@0: actual = "FAIL, empty reduceRight"; michael@0: } catch (e) { michael@0: actual = "PASS"; michael@0: } michael@0: reportCompare(expect, actual, summary + ': 4'); michael@0: michael@0: exitFunc ('test'); michael@0: }