Updates
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
require('bare-process/global')
|
||||
const test = require('brittle')
|
||||
const { HyperP2PContradictionGraph } = require('../index.js')
|
||||
|
||||
test('contradiction-graph: conflict set', async (t) => {
|
||||
const g = new HyperP2PContradictionGraph()
|
||||
const a = g.claim('node', 'status', 'up')
|
||||
const b = g.claim('node', 'status', 'down')
|
||||
t.ok(g.contradicts(a, b))
|
||||
t.is(g.conflictSet().length, 1)
|
||||
await g.close()
|
||||
})
|
||||
|
||||
test('contradiction-graph: merge', async (t) => {
|
||||
const a = new HyperP2PContradictionGraph()
|
||||
const b = new HyperP2PContradictionGraph()
|
||||
a.claim('s', 'p', 1)
|
||||
b.merge(a.toJSON())
|
||||
t.is(b._claims.length, 1)
|
||||
await a.close()
|
||||
await b.close()
|
||||
})
|
||||
test('hyper-p2p-contradiction-graph: close without leak', async (t) => {
|
||||
const m = new HyperP2PContradictionGraph()
|
||||
await m.close()
|
||||
t.pass()
|
||||
})
|
||||
test('hyper-p2p-contradiction-graph: validation rejects invalid input', async (t) => {
|
||||
const m = new HyperP2PContradictionGraph()
|
||||
try {
|
||||
if (typeof m.addNeighbor === 'function') m.addNeighbor(null)
|
||||
else if (typeof m.buildCircuit === 'function') m.buildCircuit([])
|
||||
else if (typeof m.grant === 'function') m.grant(null, -1)
|
||||
else if (typeof m.enqueue === 'function') m.enqueue('bad', null)
|
||||
else if (typeof m.reportSample === 'function') m.reportSample(null, -1, -1)
|
||||
else if (typeof m.fanout === 'function') m.fanout(null, 0)
|
||||
else if (typeof m.probe === 'function') m.probe(null)
|
||||
else if (typeof m.resolve === 'function') m.resolve(null)
|
||||
else if (typeof m.acquire === 'function') m.acquire(null)
|
||||
else throw new Error('no validation hook')
|
||||
t.fail('expected throw')
|
||||
} catch (err) {
|
||||
t.ok(err instanceof Error)
|
||||
}
|
||||
await m.close()
|
||||
})
|
||||
Reference in New Issue
Block a user