function atomize(s) { return Object.keys({[s]: 0})[0];
}
function codePoints() { return [empty, ascii, latin1, twoByte];
}
function toRope(s) { // Ropes have at least two characters. if (s.length < 2) { return s;
} if (s.length === 2) { return newRope(s[0], s[1]);
} return newRope(s[0], s.substring(1));
}
function testNegativeIndexConstant() {
let strings = makeStrings(); for (let i = 0; i < 200; ++i) {
let str = strings[i % strings.length];
let ch = str.charCodeAt(-1);
assertEq(ch, NaN);
}
} for (let i = 0; i < 2; ++i) {
testNegativeIndexConstant();
}
function testNegativeIndexVariable() {
let indices = [-1, -2];
let strings = makeStrings(); for (let i = 0; i < 200; ++i) {
let str = strings[i % strings.length];
let ch = str.charCodeAt(indices[i & 1]);
assertEq(ch, NaN);
}
} for (let i = 0; i < 2; ++i) {
testNegativeIndexVariable();
}
function testNegativeOrValidIndex() {
let indices = [-1, 0];
let strings = makeStrings();
// Number of string kinds created in makeStrings. const N = 4;
let cpoints = codePoints();
assertEq(strings.length, cpoints.length * N);
for (let i = 0; i < 200; ++i) {
let str = strings[i % strings.length];
let index = indices[i & 1];
let ch = str.charCodeAt(index);
let cp = cpoints[Math.trunc((i % strings.length) / N)];
assertEq(ch, (0 <= index && index < cp.length ? cp[index] : NaN));
}
} for (let i = 0; i < 2; ++i) {
testNegativeOrValidIndex();
}
function testTooLargeIndexConstant() {
let strings = makeStrings(); for (let i = 0; i < 200; ++i) {
let str = strings[i % strings.length];
let ch = str.charCodeAt(1000);
assertEq(ch, NaN);
}
} for (let i = 0; i < 2; ++i) {
testTooLargeIndexConstant();
}
function testTooLargeIndexVariable() {
let indices = [1000, 2000];
let strings = makeStrings(); for (let i = 0; i < 200; ++i) {
let str = strings[i % strings.length];
let ch = str.charCodeAt(indices[i & 1]);
assertEq(ch, NaN);
}
} for (let i = 0; i < 2; ++i) {
testTooLargeIndexVariable();
}
function testTooLargeOrValidIndex() {
let indices = [1000, 0];
let strings = makeStrings();
// Number of string kinds created in makeStrings. const N = 4;
let cpoints = codePoints();
assertEq(strings.length, cpoints.length * N);
for (let i = 0; i < 200; ++i) {
let str = strings[i % strings.length];
let index = indices[i & 1];
let ch = str.charCodeAt(index);
let cp = cpoints[Math.trunc((i % strings.length) / N)];
assertEq(ch, (0 <= index && index < cp.length ? cp[index] : NaN));
}
} for (let i = 0; i < 2; ++i) {
testTooLargeOrValidIndex();
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.