Skip to content

Commit

Permalink
more test
Browse files Browse the repository at this point in the history
  • Loading branch information
tsctx committed Feb 16, 2024
1 parent c8ee102 commit ad80667
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion benchmarks/headers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function generateAsciiString (length) {
}

const headers = new Headers(
Array.from(Array(100), () => generateAsciiString(5)).map((v) => [v, ''])
Array.from(Array(100), () => generateAsciiString(7)).map((v) => [v, ''])
)

const headersList = headers[symbols.kHeadersList]
Expand Down
2 changes: 2 additions & 0 deletions lib/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,8 @@ module.exports = {
readableStreamClose,
headerNamesSort,
sort,
binaryInsertionSort,
heapSort,
isomorphicEncode,
urlIsLocal,
urlHasHttpsScheme,
Expand Down
39 changes: 29 additions & 10 deletions test/fetch/sort.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
'use strict'

const { test } = require('node:test')
const { describe, test } = require('node:test')
const assert = require('node:assert')
const { sort } = require('../../lib/fetch/util')
const { sort, heapSort, binaryInsertionSort } = require('../../lib/fetch/util')

function generateRandomNumberArray (length) {
const array = new Int32Array(length)
const array = new Uint16Array(length)
for (let i = 0; i < length; ++i) {
array[i] = length * Math.random() + 1
array[i] = (65535 * Math.random()) | 0
}
return array
}

test('sort', () => {
describe('sort', () => {
const compare = (a, b) => a - b
for (let i = 0; i <= 100; ++i) {
const array = generateRandomNumberArray(10000)
const expected = array.slice().sort(compare)
assert.deepStrictEqual(sort(array, compare), expected)
}

test('binary insertion sort', () => {
for (let i = 0; i <= 100; ++i) {
const array = generateRandomNumberArray(32)
const expected = array.slice().sort(compare)
assert.deepStrictEqual(binaryInsertionSort(array, compare), expected)
}
})

test('heap sort', () => {
for (let i = 0; i <= 1000; ++i) {
const array = generateRandomNumberArray(1000)
const expected = array.slice().sort(compare)
assert.deepStrictEqual(heapSort(array, 0, array.length, compare), expected)
}
})

test('intro sort', () => {
for (let i = 0; i <= 1000; ++i) {
const array = generateRandomNumberArray(1000)
const expected = array.slice().sort(compare)
assert.deepStrictEqual(sort(array, compare), expected)
}
})
})

0 comments on commit ad80667

Please sign in to comment.