Files
modules/indexes-search/hyper-p2p-trie-prefix/test/test.js
T
Raven ScottandCursor e43e2e83f1 Deepen indexes-search: APIs, tests, and category docs
Extend all eight index/search packages with practical helpers for app
development and fix semantic-vector getStats() to expose real metrics.

Per-module code:
- bloom-gossip: listKeys(), clear()
- inverted-index: searchAll(and|or), getDocTerms()
- fulltext-lite: search(and|or), suggest(prefix)
- trie-prefix: countPrefix(), autocomplete(limit)
- graph-index: removeEdge(), outDegree(), edgeCount()
- similarity-lsh: nearVector(), bucketCount()
- semantic-vector-index: getStats() delegates to getMetrics() + PROTOCOL export
- spatial-index: listLocalPoints(), pointCount(), protocol in getStats()

Tests added for new APIs across six packages; all indexes-search npm test
suites pass (8/8).

Docs:
- Rewrite indexes-search category README (module table, composition)
- Expand bloom-gossip and semantic-vector architecture notes
- modules/README.md: link indexes-search doc hub

Parent workspace docs/indexes-search/README.md and MODULE_DOC_PASS.md
updated separately (outside this git root).

Co-authored-by: Cursor <[email protected]>
2026-05-21 00:20:56 -04:00

49 lines
1.1 KiB
JavaScript

require('bare-process/global')
const test = require('brittle')
const { HyperP2PTriePrefix, PROTOCOL } = require('../index.js')
test('exports', (t) => {
t.ok(HyperP2PTriePrefix)
t.is(PROTOCOL, 'trie-prefix/v1')
})
test('insert prefixSearch', async (t) => {
const m = new HyperP2PTriePrefix()
m.insert('pear')
m.insert('peer')
t.alike(m.prefixSearch('pe'), ['pear', 'peer'])
await m.close()
})
test('validation', async (t) => {
const m = new HyperP2PTriePrefix()
try { m.insert('') } catch (e) { t.ok(e) }
await m.close()
})
test('remove', async (t) => {
const m = new HyperP2PTriePrefix()
m.insert('cat')
t.ok(m.remove('cat'))
t.is(m.prefixSearch('ca').length, 0)
await m.close()
})
test('getStats', async (t) => {
const m = new HyperP2PTriePrefix()
m.insert('z')
t.is(m.getStats().protocol, 'trie-prefix/v1')
t.is(m.getStats().inserted, 1)
await m.close()
})
test('autocomplete countPrefix', async (t) => {
const m = new HyperP2PTriePrefix()
m.insert('cat')
m.insert('car')
m.insert('dog')
t.is(m.countPrefix('ca'), 2)
t.is(m.autocomplete('ca', 1).length, 1)
await m.close()
})