29 lines
878 B
JavaScript
29 lines
878 B
JavaScript
|
|
import { describe, test } from 'node:test';
|
||
|
|
import assert from 'node:assert/strict';
|
||
|
|
import fc from 'fast-check';
|
||
|
|
import { Arbiter } from '../../src/core/Arbiter.js';
|
||
|
|
|
||
|
|
describe('Fast-check: node id mapping invariants', () => {
|
||
|
|
test('resolveNodeId/resolveKey round-trip', () => {
|
||
|
|
fc.assert(
|
||
|
|
fc.property(
|
||
|
|
fc.set(fc.string({ minLength: 1, maxLength: 12 }), { minLength: 1, maxLength: 20 }),
|
||
|
|
(keys) => {
|
||
|
|
const arbiter = new Arbiter();
|
||
|
|
for (const key of keys) {
|
||
|
|
arbiter.addNode(key, 'generic');
|
||
|
|
}
|
||
|
|
|
||
|
|
for (const key of keys) {
|
||
|
|
const id = arbiter.resolveNodeId(key);
|
||
|
|
assert.ok(id !== undefined && id !== null);
|
||
|
|
const roundTrip = arbiter.resolveKey(id);
|
||
|
|
assert.strictEqual(roundTrip, key);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
),
|
||
|
|
{ numRuns: 50 }
|
||
|
|
);
|
||
|
|
});
|
||
|
|
});
|