Debian Codegraph @

rhino/testsrc/tests/js1_2/Array/general2.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = 'general2.js';
7
8 /**
9 Filename: general2.js
10 Description: 'This tests out some of the functionality on methods on the Array objects'
11
12 Author: Nick Lerissa
13 Date: Fri Feb 13 09:58:28 PST 1998
14 */
15
16 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"';
17 var VERSION = 'no version';
18 startTest();
19 var TITLE = 'String:push,splice,concat,unshift,sort';
20
21 writeHeaderToLog('Executing script: general2.js');
22 writeHeaderToLog( SECTION + " "+ TITLE);
23
24 array1 = new Array();
25 array2 = [];
26 size = 10;
27
28 // this for loop populates array1 and array2 as follows:
29 // array1 = [0,1,2,3,4,....,size - 2,size - 1]
30 // array2 = [size - 1, size - 2,...,4,3,2,1,0]
31 for (var i = 0; i < size; i++)
32 {
33 array1.push(i);
34 array2.push(size - 1 - i);
35 }
36
37 // the following for loop reverses the order of array1 so
38 // that it should be similarly ordered to array2
39 for (i = array1.length; i > 0; i--)
40 {
41 array3 = array1.slice(1,i);
42 array1.splice(1,i-1);
43 array1 = array3.concat(array1);
44 }
45
46 // the following for loop reverses the order of array1
47 // and array2
48 for (i = 0; i < size; i++)
49 {
50 array1.push(array1.shift());
51 array2.unshift(array2.pop());
52 }
53
54 new TestCase( SECTION, "Array.push,pop,shift,unshift,slice,splice", true,String(array1) == String(array2));
55 array1.sort();
56 array2.sort();
57 new TestCase( SECTION, "Array.sort", true,String(array1) == String(array2));
58
59 test();
60