/** * llmindex.io — scoring package unit tests * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * License: Proprietary — © Simon-Pierre Boucher, all rights reserved */ import { describe, expect, it } from 'vitest'; import { DOMAINS, DOMAIN_WEIGHTS, SUBMETRIC_WEIGHTS, abilityToUnit, contaminationResistance, domainComposite, domainScore, globalIndex, paretoFrontier, thetaToIndex, } from './index'; describe('weights invariants', () => { it('domain weights sum to 1', () => { const sum = Object.values(DOMAIN_WEIGHTS).reduce((a, b) => a + b, 0); expect(sum).toBeCloseTo(1, 10); }); it('sub-metric weights sum to 1 and exclude latency/cost', () => { const sum = Object.values(SUBMETRIC_WEIGHTS).reduce((a, b) => a + b, 0); expect(sum).toBeCloseTo(1, 10); expect(Object.keys(SUBMETRIC_WEIGHTS)).not.toContain('latency_p50'); expect(Object.keys(SUBMETRIC_WEIGHTS)).not.toContain('cost_per_1k_items'); }); it('has the 12 v0.2 domains', () => { expect(DOMAINS).toHaveLength(12); expect(DOMAINS).toContain('agentic'); expect(DOMAINS).toContain('terminal'); expect(DOMAINS).toContain('svg_design'); expect(DOMAINS).toContain('vision_ocr'); }); }); describe('thetaToIndex', () => { it('maps θ=0 to center with symmetric CI', () => { const s = thetaToIndex(0, 0.2); expect(s.score).toBe(500); expect(s.score - s.scoreLow).toBe(s.scoreHigh - s.score); }); it('is monotonic in θ and clamps to [0,1000]', () => { expect(thetaToIndex(1, 0.1).score).toBeGreaterThan(thetaToIndex(-1, 0.1).score); expect(thetaToIndex(10, 0.1).score).toBe(1000); expect(thetaToIndex(-10, 0.1).score).toBe(0); }); }); describe('domain composite', () => { it('renormalizes over missing metrics (accuracy-only equals ability)', () => { const c = domainComposite({ theta: 0.8, thetaSe: 0.1 }); expect(c).toBeCloseTo(abilityToUnit(0.8), 10); }); it('penalizes contamination', () => { const clean = domainComposite({ theta: 0.5, thetaSe: 0.1, contaminationDelta: 0 }); const dirty = domainComposite({ theta: 0.5, thetaSe: 0.1, contaminationDelta: 0.2 }); expect(clean).toBeGreaterThan(dirty); }); it('contamination resistance floors at 0 for gaps ≥ 20 points', () => { expect(contaminationResistance(0.25)).toBe(0); expect(contaminationResistance(0)).toBe(1); }); it('domainScore CI widens with θ SE', () => { const narrow = domainScore({ theta: 0, thetaSe: 0.05 }); const wide = domainScore({ theta: 0, thetaSe: 0.5 }); expect(wide.scoreHigh - wide.scoreLow).toBeGreaterThan(narrow.scoreHigh - narrow.scoreLow); }); }); describe('globalIndex', () => { it('returns null with no domains', () => { expect(globalIndex({})).toBeNull(); }); it('averages with renormalized weights', () => { const g = globalIndex({ math: { score: 600, scoreLow: 580, scoreHigh: 620 }, code: { score: 400, scoreLow: 380, scoreHigh: 420 }, }); expect(g?.score).toBe(500); }); }); describe('paretoFrontier', () => { it('keeps only non-dominated points', () => { const frontier = paretoFrontier([ { slug: 'cheap-weak', score: 400, costPer1kItems: 1 }, { slug: 'dominated', score: 390, costPer1kItems: 2 }, { slug: 'mid', score: 600, costPer1kItems: 5 }, { slug: 'best-expensive', score: 800, costPer1kItems: 30 }, ]); expect(frontier.map((p) => p.slug)).toEqual(['cheap-weak', 'mid', 'best-expensive']); }); });