Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 10, 2021
1 parent abb78c1 commit 8e3ca5a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions test.js
Expand Up @@ -35,30 +35,42 @@ test('end', t => {

test('main - does not have exponential performance', t => {
for (let index = 0; index < 45000; index += 1000) {
const string = String(Array.from({length: index}).fill('\n').join('')) + 'a' + String(Array.from({length: index}).fill('\n').join(''));
const string = 'a' + String(Array.from({length: index}).fill('\n').join('')) + String(Array.from({length: index}).fill('\n').join('')) + 'a';
const start = Date.now();
trimNewlines(string);
const difference = Date.now() - start;
t.true(difference < 10, `Execution time: ${difference}`);

if (difference > 10) {
throw new Error(); // eslint-disable-line unicorn/error-message
}
}
});

test('start - does not have exponential performance', t => {
for (let index = 0; index < 45000; index += 1000) {
const string = String(Array.from({length: index}).fill('\n').join('')) + 'a';
const string = 'a' + String(Array.from({length: index}).fill('\n').join(''));
const start = Date.now();
trimNewlines.start(string);
const difference = Date.now() - start;
t.true(difference < 10, `Execution time: ${difference}`);

if (difference > 10) {
throw new Error(); // eslint-disable-line unicorn/error-message
}
}
});

test('end - does not have exponential performance', t => {
for (let index = 0; index < 45000; index += 1000) {
const string = 'a' + String(Array.from({length: index}).fill('\n').join(''));
const string = String(Array.from({length: index}).fill('\n').join('')) + 'a';
const start = Date.now();
trimNewlines.end(string);
const difference = Date.now() - start;
t.true(difference < 10, `Execution time: ${difference}`);

if (difference > 10) {
throw new Error(); // eslint-disable-line unicorn/error-message
}
}
});

0 comments on commit 8e3ca5a

Please sign in to comment.