|
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 |
|
7 /** |
|
8 Filename: general2.js |
|
9 Description: 'This tests out some of the functionality on methods on the Array objects' |
|
10 |
|
11 Author: Nick Lerissa |
|
12 Date: Fri Feb 13 09:58:28 PST 1998 |
|
13 */ |
|
14 |
|
15 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; |
|
16 var VERSION = 'no version'; |
|
17 startTest(); |
|
18 var TITLE = 'String:push,splice,concat,unshift,sort'; |
|
19 |
|
20 writeHeaderToLog('Executing script: general2.js'); |
|
21 writeHeaderToLog( SECTION + " "+ TITLE); |
|
22 |
|
23 array1 = new Array(); |
|
24 array2 = []; |
|
25 size = 10; |
|
26 |
|
27 // this for loop populates array1 and array2 as follows: |
|
28 // array1 = [0,1,2,3,4,....,size - 2,size - 1] |
|
29 // array2 = [size - 1, size - 2,...,4,3,2,1,0] |
|
30 for (var i = 0; i < size; i++) |
|
31 { |
|
32 array1.push(i); |
|
33 array2.push(size - 1 - i); |
|
34 } |
|
35 |
|
36 // the following for loop reverses the order of array1 so |
|
37 // that it should be similarly ordered to array2 |
|
38 for (i = array1.length; i > 0; i--) |
|
39 { |
|
40 array3 = array1.slice(1,i); |
|
41 array1.splice(1,i-1); |
|
42 array1 = array3.concat(array1); |
|
43 } |
|
44 |
|
45 // the following for loop reverses the order of array1 |
|
46 // and array2 |
|
47 for (i = 0; i < size; i++) |
|
48 { |
|
49 array1.push(array1.shift()); |
|
50 array2.unshift(array2.pop()); |
|
51 } |
|
52 |
|
53 new TestCase( SECTION, "Array.push,pop,shift,unshift,slice,splice", true,String(array1) == String(array2)); |
|
54 array1.sort(); |
|
55 array2.sort(); |
|
56 new TestCase( SECTION, "Array.sort", true,String(array1) == String(array2)); |
|
57 |
|
58 test(); |
|
59 |