Skip to content

Commit

Permalink
feat: port tst test to node test runner (nodejs#2595)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsctx authored and crysmags committed Feb 27, 2024
1 parent dafcd49 commit b2c975d
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions test/tree.js → test/node-test/tree.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
'use strict'

const { TernarySearchTree, tree } = require('../lib/core/tree')
const { wellknownHeaderNames, headerNameLowerCasedRecord } = require('../lib/core/constants')
const { test } = require('tap')

test('Ternary Search Tree', (t) => {
t.plan(4)

t.test('The empty key cannot be added.', (t) => {
t.plan(2)
t.throws(() => new TernarySearchTree().insert(Buffer.from(''), ''))
const { TernarySearchTree, tree } = require('../../lib/core/tree')
const { wellknownHeaderNames, headerNameLowerCasedRecord } = require('../../lib/core/constants')
const { describe, test } = require('node:test')
const assert = require('node:assert')

describe('Ternary Search Tree', () => {
test('The empty key cannot be added.', () => {
assert.throws(() => new TernarySearchTree().insert(Buffer.from(''), ''))
const tst = new TernarySearchTree()
tst.insert(Buffer.from('a'), 'a')
t.throws(() => tst.insert(Buffer.from(''), ''))
assert.throws(() => tst.insert(Buffer.from(''), ''))
})

t.test('duplicate key', (t) => {
t.plan(2)
test('duplicate key', () => {
const tst = new TernarySearchTree()
const key = Buffer.from('a')
tst.insert(key, 'a')
t.equal(tst.lookup(key), 'a')
assert.strictEqual(tst.lookup(key), 'a')
tst.insert(key, 'b')
t.equal(tst.lookup(key), 'b')
assert.strictEqual(tst.lookup(key), 'b')
})

t.test('tree', (t) => {
t.plan(wellknownHeaderNames.length)
test('tree', () => {
for (let i = 0; i < wellknownHeaderNames.length; ++i) {
const key = wellknownHeaderNames[i]
t.equal(tree.lookup(Buffer.from(key)), headerNameLowerCasedRecord[key])
assert.strictEqual(tree.lookup(Buffer.from(key)), headerNameLowerCasedRecord[key])
}
})

t.test('fuzz', (t) => {
test('fuzz', () => {
const LENGTH = 2000
t.plan(LENGTH)
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const charactersLength = characters.length

Expand All @@ -61,7 +56,7 @@ test('Ternary Search Tree', (t) => {
}

for (let i = 0; i < LENGTH; ++i) {
t.equal(tst.lookup(randomBuffer[i]), random[i])
assert.strictEqual(tst.lookup(randomBuffer[i]), random[i])
}
})
})

0 comments on commit b2c975d

Please sign in to comment.