v8/test/mjsunit/lexicographic-compare.js
Sigurd Schneider 2a01ff8e93 [mjsunit] Split slow test out of array-sort and skip it on certain builds
The slow test tests SmiLexicographicCompare on a large number of Smi comparisons;
we can disable this test for some debug/noopt builds without losing much coverage.

Bug: v8:7783
Change-Id: Iab40e596604bb957b4d3312073ad85dbac08c6a0
Reviewed-on: https://chromium-review.googlesource.com/1068190
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53333}
2018-05-24 12:36:48 +00:00

63 lines
1.4 KiB
JavaScript

// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
(function () {
assertFalse(%IsSmi(2147483648), 'Update test for >32 bit Smi');
// Collect a list of interesting Smis.
const seen = {};
const smis = [];
function add(x) {
if (x | 0 == x) {
x = x | 0; // Canonicalizes to Smi if 32-bit signed and fits in Smi.
}
if (%_IsSmi(x) && !seen[x]) {
seen[x] = 1;
smis.push(x);
}
}
function addSigned(x) {
add(x);
add(-x);
}
var BIGGER_THAN_ANY_SMI = 10 * 1000 * 1000 * 1000;
for (var xb = 1; xb <= BIGGER_THAN_ANY_SMI; xb *= 10) {
for (var xf = 0; xf <= 9; xf++) {
for (var xo = -1; xo <= 1; xo++) {
addSigned(xb * xf + xo);
}
}
}
console.log("A")
for (var yb = 1; yb <= BIGGER_THAN_ANY_SMI; yb *= 2) {
for (var yo = -2; yo <= 2; yo++) {
addSigned(yb + yo);
}
}
function test(x,y) {
const lex = %SmiLexicographicCompare(x, y);
const expected = (x == y) ? 0 : (("" + x) < ("" + y) ? -1 : 1);
return lex == expected;
}
console.log(smis.length);
for (var i = 0; i < smis.length; i++) {
for (var j = 0; j < smis.length; j++) {
const x = smis[i];
const y = smis[j];
assertTrue(test(x, y), x + " < " + y);;
}
}
console.log("C")
})();