forked from EvoMap/evolver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrategy.test.js
More file actions
133 lines (115 loc) · 4.83 KB
/
Copy pathstrategy.test.js
File metadata and controls
133 lines (115 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
const { describe, it, beforeEach, afterEach } = require('node:test');
const assert = require('node:assert/strict');
const { resolveStrategy, getStrategyNames, STRATEGIES } = require('../src/gep/strategy');
describe('STRATEGIES', function () {
it('defines all expected presets', function () {
const names = getStrategyNames();
assert.ok(names.includes('balanced'));
assert.ok(names.includes('innovate'));
assert.ok(names.includes('harden'));
assert.ok(names.includes('repair-only'));
assert.ok(names.includes('early-stabilize'));
assert.ok(names.includes('steady-state'));
});
it('all strategies have required fields', function () {
for (const [name, s] of Object.entries(STRATEGIES)) {
assert.equal(typeof s.repair, 'number', `${name}.repair`);
assert.equal(typeof s.optimize, 'number', `${name}.optimize`);
assert.equal(typeof s.innovate, 'number', `${name}.innovate`);
assert.equal(typeof s.repairLoopThreshold, 'number', `${name}.repairLoopThreshold`);
assert.equal(typeof s.label, 'string', `${name}.label`);
assert.equal(typeof s.description, 'string', `${name}.description`);
}
});
it('all strategy ratios sum to approximately 1.0', function () {
for (const [name, s] of Object.entries(STRATEGIES)) {
const sum = s.repair + s.optimize + s.innovate + (s.explore || 0);
assert.ok(Math.abs(sum - 1.0) < 0.01, `${name} ratios sum to ${sum}`);
}
});
});
describe('resolveStrategy', function () {
let origStrategy;
let origForceInnovation;
let origEvolveForceInnovation;
beforeEach(function () {
origStrategy = process.env.EVOLVE_STRATEGY;
origForceInnovation = process.env.FORCE_INNOVATION;
origEvolveForceInnovation = process.env.EVOLVE_FORCE_INNOVATION;
delete process.env.EVOLVE_STRATEGY;
delete process.env.FORCE_INNOVATION;
delete process.env.EVOLVE_FORCE_INNOVATION;
});
afterEach(function () {
if (origStrategy !== undefined) process.env.EVOLVE_STRATEGY = origStrategy;
else delete process.env.EVOLVE_STRATEGY;
if (origForceInnovation !== undefined) process.env.FORCE_INNOVATION = origForceInnovation;
else delete process.env.FORCE_INNOVATION;
if (origEvolveForceInnovation !== undefined) process.env.EVOLVE_FORCE_INNOVATION = origEvolveForceInnovation;
else delete process.env.EVOLVE_FORCE_INNOVATION;
});
it('defaults to balanced when no env var set', function () {
const s = resolveStrategy({});
assert.ok(['balanced', 'early-stabilize'].includes(s.name));
});
it('respects explicit EVOLVE_STRATEGY', function () {
process.env.EVOLVE_STRATEGY = 'harden';
const s = resolveStrategy({});
assert.equal(s.name, 'harden');
assert.equal(s.label, 'Hardening');
});
it('respects innovate strategy', function () {
process.env.EVOLVE_STRATEGY = 'innovate';
const s = resolveStrategy({});
assert.equal(s.name, 'innovate');
assert.ok(s.innovate >= 0.8);
});
it('respects repair-only strategy', function () {
process.env.EVOLVE_STRATEGY = 'repair-only';
const s = resolveStrategy({});
assert.equal(s.name, 'repair-only');
assert.equal(s.innovate, 0);
});
it('FORCE_INNOVATION=true maps to innovate', function () {
process.env.FORCE_INNOVATION = 'true';
const s = resolveStrategy({});
assert.equal(s.name, 'innovate');
});
it('EVOLVE_FORCE_INNOVATION=true maps to innovate', function () {
process.env.EVOLVE_FORCE_INNOVATION = 'true';
const s = resolveStrategy({});
assert.equal(s.name, 'innovate');
});
it('explicit EVOLVE_STRATEGY takes precedence over FORCE_INNOVATION', function () {
process.env.EVOLVE_STRATEGY = 'harden';
process.env.FORCE_INNOVATION = 'true';
const s = resolveStrategy({});
assert.equal(s.name, 'harden');
});
it('saturation signal triggers steady-state', function () {
const s = resolveStrategy({ signals: ['evolution_saturation'] });
assert.equal(s.name, 'steady-state');
});
it('force_steady_state signal triggers steady-state', function () {
const s = resolveStrategy({ signals: ['force_steady_state'] });
assert.equal(s.name, 'steady-state');
});
it('falls back to balanced for unknown strategy name', function () {
process.env.EVOLVE_STRATEGY = 'nonexistent';
const s = resolveStrategy({});
const fallback = STRATEGIES['balanced'];
assert.equal(s.repair, fallback.repair);
assert.equal(s.optimize, fallback.optimize);
assert.equal(s.innovate, fallback.innovate);
});
it('auto maps to balanced or heuristic', function () {
process.env.EVOLVE_STRATEGY = 'auto';
const s = resolveStrategy({});
assert.ok(['balanced', 'early-stabilize'].includes(s.name));
});
it('returned strategy has name property', function () {
process.env.EVOLVE_STRATEGY = 'harden';
const s = resolveStrategy({});
assert.equal(s.name, 'harden');
});
});