Initial Commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import * as fc from "fast-check";
|
||||
import {
|
||||
AssignmentEngine,
|
||||
MeshCapacityTracker,
|
||||
type MeshDescriptor,
|
||||
type PeerInfo,
|
||||
} from "../../src/index.js";
|
||||
|
||||
describe("AssignmentEngine scoring is deterministic", () => {
|
||||
it("same input twice produces identical scores", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.array(
|
||||
fc.tuple(
|
||||
fc.string({ minLength: 1, maxLength: 6 }),
|
||||
fc.integer({ min: 1, max: 100 }),
|
||||
fc.integer({ min: 0, max: 5 })
|
||||
),
|
||||
{ minLength: 1, maxLength: 5 }
|
||||
),
|
||||
fc.integer({ min: 0, max: 5 }),
|
||||
(entries, tierEligibility) => {
|
||||
const seen = new Set<string>();
|
||||
const meshes: MeshDescriptor[] = [];
|
||||
const latencyMap = new Map<string, number>();
|
||||
for (const [name, latency, tierFloor] of entries) {
|
||||
if (seen.has(name)) continue;
|
||||
seen.add(name);
|
||||
meshes.push({ meshId: name, tierFloor });
|
||||
latencyMap.set(name, latency);
|
||||
}
|
||||
if (meshes.length === 0) return;
|
||||
const peer: PeerInfo = {
|
||||
peerId: "p",
|
||||
latencyMap,
|
||||
tierEligibility,
|
||||
capabilities: "STANDARD",
|
||||
};
|
||||
const tracker = new MeshCapacityTracker();
|
||||
for (const m of meshes) tracker.recordMesh(m.meshId, 10);
|
||||
const engine = new AssignmentEngine({ tracker });
|
||||
const a = engine.score(peer, meshes);
|
||||
const b = engine.score(peer, meshes);
|
||||
expect(a.map((s) => s.score)).toEqual(
|
||||
b.map((s) => s.score)
|
||||
);
|
||||
}
|
||||
),
|
||||
{ numRuns: 50 }
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user