convergence.test.ts
1,694 bytes
| 1 | import { describe, expect, it } from 'vitest'; |
|---|---|
| 2 | import { shouldStop } from './convergence'; |
| 3 | |
| 4 | describe('shouldStop', () => { |
| 5 | const base = { threshold: 85, round: 1, maxRounds: 3, activeCount: 3 }; |
| 6 | |
| 7 | it('stops when the convergence score meets the threshold', () => { |
| 8 | expect(shouldStop({ ...base, score: 85 })).toEqual({ stop: true, reason: 'converged' }); |
| 9 | expect(shouldStop({ ...base, score: 92 })).toEqual({ stop: true, reason: 'converged' }); |
| 10 | }); |
| 11 | |
| 12 | it('continues when below threshold and rounds remain', () => { |
| 13 | expect(shouldStop({ ...base, score: 70 })).toEqual({ stop: false, reason: 'continue' }); |
| 14 | }); |
| 15 | |
| 16 | it('stops at max rounds even if not converged', () => { |
| 17 | expect(shouldStop({ ...base, score: 40, round: 3, maxRounds: 3 })).toEqual({ |
| 18 | stop: true, |
| 19 | reason: 'max_rounds', |
| 20 | }); |
| 21 | }); |
| 22 | |
| 23 | it('stops with insufficient_models when fewer than two remain - even if converged', () => { |
| 24 | expect(shouldStop({ ...base, score: 99, activeCount: 1 })).toEqual({ |
| 25 | stop: true, |
| 26 | reason: 'insufficient_models', |
| 27 | }); |
| 28 | expect(shouldStop({ ...base, score: 10, activeCount: 0 })).toEqual({ |
| 29 | stop: true, |
| 30 | reason: 'insufficient_models', |
| 31 | }); |
| 32 | }); |
| 33 | |
| 34 | it('prioritizes insufficient_models over convergence and max_rounds', () => { |
| 35 | // Converged AND at max rounds AND too few models -> insufficient wins. |
| 36 | expect(shouldStop({ score: 100, threshold: 85, round: 3, maxRounds: 3, activeCount: 1 }).reason).toBe( |
| 37 | 'insufficient_models', |
| 38 | ); |
| 39 | }); |
| 40 | |
| 41 | it('treats exactly two active models as enough to continue', () => { |
| 42 | expect(shouldStop({ ...base, score: 50, activeCount: 2 })).toEqual({ stop: false, reason: 'continue' }); |
| 43 | }); |
| 44 | }); |
| 45 | |