Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: test/mjsunit/array-shift.js

Issue 63100: Increase coverage testing of sparse arrays. Add a set... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/array-splice-webkit.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/array-shift.js
===================================================================
--- test/mjsunit/array-shift.js (revision 0)
+++ test/mjsunit/array-shift.js (revision 0)
@@ -0,0 +1,114 @@
+// Copyright 2008 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Verify preservation of the hole when shifting
+arr = [1, 2, 3, 4, 5];
+assertTrue(2 in arr);
+assertTrue(delete arr[2]);
+assertFalse(2 in arr);
+assertArrayEquals([1,2,,4,5], arr);
+assertEquals(1, arr.shift());
+assertArrayEquals([2,,4,5], arr);
+assertTrue(0 in arr);
+assertFalse(1 in arr);
+assertEquals(4, arr.length);
+assertTrue(delete arr[3]);
+assertEquals(4, arr.length);
+assertArrayEquals([2,,4,,], arr);
+assertEquals(2, arr.shift());
+assertEquals(undefined, arr.shift());
+assertEquals(4, arr.shift());
+assertEquals(undefined, arr.shift());
+assertEquals(0, arr.length);
+
+// Verify shifting over sparse arrays
+arr = [];
+arr[5000] = 5000;
+assertEquals(5001, arr.length);
+for (var i = 0; i < 5000; i++) {
+ assertFalse(0 in arr);
+ var element = arr.shift();
+ assertEquals(undefined, element);
+ assertEquals(5000 - i, arr.length);
+}
+assertEquals(5000, arr.shift());
+assertEquals(0, arr.length);
+
+// A bigger sparse array. Uses splice too.
+arr = [];
+for (var i = 0; i < 50000; i+= 500) {
+ arr[i] = 1;
+}
+for (var i = 0; i < 50000; i+=500) {
+ assertTrue(0 in arr);
+ assertFalse(1 in arr);
+ assertFalse(499 in arr);
+ assertEquals(1, arr.shift());
+ arr.splice(0,499);
+}
+assertEquals(0, arr.length);
+
+// Another sparse array with a couple of filled blocks.
+arr = [];
+for (var i = 2000; i < 2100; i++) {
+ arr[i] = i;
+}
+for (var i = 10000; i < 10100; i++) {
+ arr[i] = i;
+}
+assertEquals(10100, arr.length);
+
+// Splice off the first empty chunk 0-1999
+assertFalse(0 in arr);
+assertFalse(1999 in arr);
+arr2 = arr.splice(0,2000);
+assertFalse(0 in arr2);
+assertFalse(1999 in arr2);
+assertEquals(8100, arr.length);
+
+// Verify the first filled chunk 2000-2099
+assertTrue(0 in arr);
+assertTrue(99 in arr);
+for (var i = 0; i < 100; i++) {
+ assertTrue(0 in arr);
+ assertEquals(2000 + i, arr.shift());
+}
+
+// Splice off the next chunk 2100-9999
+assertFalse(0 in arr);
+assertFalse(7899 in arr);
+assertTrue(7900 in arr);
+arr2 = arr.splice(0,7900);
+assertEquals(100, arr.length);
+
+// Verify the second filled chunk 10000-10099
+assertTrue(0 in arr);
+assertTrue(99 in arr);
+for (var i = 0; i < 100; i++) {
+ assertTrue(0 in arr);
+ assertEquals(10000 + i, arr.shift());
+}
« no previous file with comments | « no previous file | test/mjsunit/array-splice-webkit.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698