js/src/tests/js1_2/Array/general2.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_2/Array/general2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 +   Filename:     general2.js
    1.12 +   Description:  'This tests out some of the functionality on methods on the Array objects'
    1.13 +
    1.14 +   Author:       Nick Lerissa
    1.15 +   Date:         Fri Feb 13 09:58:28 PST 1998
    1.16 +*/
    1.17 +
    1.18 +var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
    1.19 +var VERSION = 'no version';
    1.20 +startTest();
    1.21 +var TITLE = 'String:push,splice,concat,unshift,sort';
    1.22 +
    1.23 +writeHeaderToLog('Executing script: general2.js');
    1.24 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.25 +
    1.26 +array1 = new Array();
    1.27 +array2 = [];
    1.28 +size   = 10;
    1.29 +
    1.30 +// this for loop populates array1 and array2 as follows:
    1.31 +// array1 = [0,1,2,3,4,....,size - 2,size - 1]
    1.32 +// array2 = [size - 1, size - 2,...,4,3,2,1,0]
    1.33 +for (var i = 0; i < size; i++)
    1.34 +{
    1.35 +  array1.push(i);
    1.36 +  array2.push(size - 1 - i);
    1.37 +}
    1.38 +
    1.39 +// the following for loop reverses the order of array1 so
    1.40 +// that it should be similarly ordered to array2
    1.41 +for (i = array1.length; i > 0; i--)
    1.42 +{
    1.43 +  array3 = array1.slice(1,i);
    1.44 +  array1.splice(1,i-1);
    1.45 +  array1 = array3.concat(array1);
    1.46 +}
    1.47 +
    1.48 +// the following for loop reverses the order of array1
    1.49 +// and array2
    1.50 +for (i = 0; i < size; i++)
    1.51 +{
    1.52 +  array1.push(array1.shift());
    1.53 +  array2.unshift(array2.pop());
    1.54 +}
    1.55 +
    1.56 +new TestCase( SECTION, "Array.push,pop,shift,unshift,slice,splice", true,String(array1) == String(array2));
    1.57 +array1.sort();
    1.58 +array2.sort();
    1.59 +new TestCase( SECTION, "Array.sort", true,String(array1) == String(array2));
    1.60 +
    1.61 +test();
    1.62 +

mercurial