Skip to content

Commit

Permalink
test: add test case for copy function
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS committed Oct 15, 2024
1 parent d8e155c commit 2aeda39
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
32 changes: 32 additions & 0 deletions test/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { describe, it, before } = require('node:test');
const assert = require('node:assert');
const copyBench = require('./fixtures/copy');

describe('Same benchmark function', () => {
let results;

before(async () => {
results = await copyBench.run();
});

it('must have a similar benchmark result', () => {
for (let i = 0; i < results.length; i++) {
for (let j = 0; j < results.length; j++) {
if (i !== j) {
const opsSec1 = results[i].opsSec;
const opsSec2 = results[j].opsSec;

// Calculate the percentage difference
const difference = Math.abs(opsSec1 - opsSec2);
const percentageDifference = (difference / Math.min(opsSec1, opsSec2)) * 100;

// Check if the percentage difference is less than or equal to 10%
assert.ok(
percentageDifference <= 10,
`${opsSec1} too different from ${opsSec2} - ${results[i].name}`
);
}
}
}
});
});
11 changes: 7 additions & 4 deletions test/fixtures/copy.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const { Suite } = require('../../lib');

const suite = new Suite();
const suite = new Suite({ reporter: false });

suite
.add('Using includes', function () {
const text = 'text/html,application/xhtml+xml,application/xml;application/json;q=0.9,image/avif,image/webp,*/*;q=0.8'
const r = text.includes('application/json')
return r;
})
.add('Using includes 2', function () {
const text = 'text/html,application/xhtml+xml,application/xml;application/json;q=0.9,image/avif,image/webp,*/*;q=0.8'
const r = text.includes('application/json')
return r;
})
.run({ reporter: true });
.add('Using includes 3', function () {
const text = 'text/html,application/xhtml+xml,application/xml;application/json;q=0.9,image/avif,image/webp,*/*;q=0.8'
const r = text.includes('application/json')
})

module.exports = suite;

0 comments on commit 2aeda39

Please sign in to comment.