refactor: minimize repetitions
This commit is contained in:
@@ -301,4 +301,67 @@ describe('generatePointCrawlMap', () => {
|
||||
|
||||
expect(nodesWithEncounter).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should minimize same-layer repetitions in wild layer pairs', () => {
|
||||
// Test that wild layers in pairs (1-2, 4-5, 7-8) have minimal duplicate types within each layer
|
||||
const map = generatePointCrawlMap(12345);
|
||||
const wildPairIndices = [
|
||||
[1, 2],
|
||||
[4, 5],
|
||||
[7, 8],
|
||||
];
|
||||
|
||||
for (const [layer1Idx, layer2Idx] of wildPairIndices) {
|
||||
const layer1 = map.layers[layer1Idx];
|
||||
const layer2 = map.layers[layer2Idx];
|
||||
|
||||
// Count repetitions in layer 1
|
||||
const layer1Types = layer1.nodeIds.map(id => map.nodes.get(id)!.type);
|
||||
const layer1Unique = new Set(layer1Types).size;
|
||||
const layer1Repetitions = layer1Types.length - layer1Unique;
|
||||
|
||||
// Count repetitions in layer 2
|
||||
const layer2Types = layer2.nodeIds.map(id => map.nodes.get(id)!.type);
|
||||
const layer2Unique = new Set(layer2Types).size;
|
||||
const layer2Repetitions = layer2Types.length - layer2Unique;
|
||||
|
||||
// With optimal selection, we expect fewer repetitions than pure random
|
||||
// On average, random would have ~1.5 repetitions per 3-node layer
|
||||
// With 3 attempts, we should typically get 0-1 repetitions
|
||||
expect(layer1Repetitions + layer2Repetitions).toBeLessThanOrEqual(2);
|
||||
}
|
||||
});
|
||||
|
||||
it('should minimize adjacent repetitions in wild→wild connections', () => {
|
||||
// Test that wild nodes connected by wild→wild edges have different types
|
||||
const map = generatePointCrawlMap(12345);
|
||||
const wildToWildPairs = [
|
||||
{ src: 1, tgt: 2 },
|
||||
{ src: 4, tgt: 5 },
|
||||
{ src: 7, tgt: 8 },
|
||||
];
|
||||
|
||||
let totalAdjacentRepetitions = 0;
|
||||
|
||||
for (const pair of wildToWildPairs) {
|
||||
const srcLayer = map.layers[pair.src];
|
||||
const tgtLayer = map.layers[pair.tgt];
|
||||
|
||||
// Each wild node connects to exactly 1 wild node in next layer (1-to-1)
|
||||
for (let i = 0; i < srcLayer.nodeIds.length; i++) {
|
||||
const srcNode = map.nodes.get(srcLayer.nodeIds[i])!;
|
||||
const tgtId = srcNode.childIds[0];
|
||||
const tgtNode = map.nodes.get(tgtId)!;
|
||||
|
||||
if (srcNode.type === tgtNode.type) {
|
||||
totalAdjacentRepetitions++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// With 3 wild pairs and 3 nodes each, that's 9 connections total
|
||||
// Random would have ~3 repetitions (1/3 chance per connection)
|
||||
// With optimal selection of 3 attempts, should be much lower (0-2)
|
||||
expect(totalAdjacentRepetitions).toBeLessThanOrEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user