You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/each-block-keyed-random-per.../_config.js

70 lines
1.6 KiB

const VALUES = Array.from('abcdefghijklmnopqrstuvwxyz');
function toObjects(array) {
return array.split('').map(x => ({ id: x }));
}
function permute() {
const values = VALUES.slice();
const number = Math.floor(Math.random() * VALUES.length);
const permuted = [];
for (let i = 0; i < number; i++) {
permuted.push(
...values.splice(Math.floor(Math.random() * (number - i)), 1)
);
}
return permuted.join('');
}
export default {
7 years ago
solo: true,
allowES2015: true,
data: {
7 years ago
values: toObjects('duqbmineapjhtlofrskcg'),
},
7 years ago
// html: `(a)(b)(c)`,
test(assert, component, target) {
function test(sequence) {
const previous = target.textContent;
7 years ago
console.group(`${previous.replace(/[()]/g, '')} -> ${sequence}`);
const expected = sequence.split('').map(x => `(${x})`).join('');
component.set({ values: toObjects(sequence) });
7 years ago
console.log(`result: ${target.textContent.replace(/[()]/g, '')}`);
assert.htmlEqual(
target.innerHTML,
expected,
`\n${previous} -> ${expected}\n${target.textContent}`
);
7 years ago
console.groupEnd();
}
// first, some fixed tests so that we can debug them
7 years ago
// test('abc');
// test('abcd');
// test('abecd');
// test('fabecd');
// test('fabed');
// test('beadf');
// test('ghbeadf');
// test('gf');
// test('gc');
// test('g');
// test('');
// test('abc');
// test('duqbmineapjhtlofrskcg');
test('hdnkjougmrvftewsqpailcb');
test('bidhfacge');
test('kgjnempcboaflidh');
7 years ago
test('fekbijachgd');
test('kdmlgfbicheja');
return;
// then, we party
7 years ago
for (let i = 0; i < 1000; i += 1) test(permute());
}
};