'use strict'; const test=require('node:test'),assert=require('node:assert/strict'); require('../src/calculator-validation-data.js'); const validation=require('../src/calculator-validation.js'); const data=globalThis.CalculatorValidationData; test('precision thresholds are inclusive and never classify missing results',()=>{ for(const sign of [-1,1])for(const threshold of [1,3,5])assert.equal(validation.tier(sign*threshold),threshold); assert.equal(validation.tier(1.00001),3);assert.equal(validation.tier(5.00001),null); for(const value of [undefined,null,NaN,Infinity])assert.equal(validation.tier(value),null); }); test('summary intervals contain only jointly tested points that pass the selected output',()=>{ const pp=validation.summarize('buck','ripple',1),spectrum=validation.summarize('buck','spectrum',3); assert.equal(pp.total,64);assert.equal(pp.passed.length,63);assert.ok(!pp.passed.some(r=>r.id==='B02')); assert.equal(spectrum.passed.length,63);assert.equal(validation.summarize('buck','spectrum',5).passed.length,64); assert.equal(validation.summarize('pmsm','spectrum',1).passed.length,65); assert.equal(validation.summarize('pmsm','ripple',1).passed.length,70); assert.throws(()=>validation.summarize('buck','ripple',2)); for(const kind of ['buck','pmsm'])for(const [key] of validation.definitions[kind]){ let previous=0; for(const threshold of [1,3,5]){ const result=validation.summarize(kind,key,threshold);assert.ok(result.passed.length>=previous);previous=result.passed.length; result.passed.forEach(r=>assert.ok(Math.abs(r.errors[key])<=threshold)); } } }); test('changing one supply parameter does not preserve an exact verified match',()=>{ const input={...data.buck[1].input};assert.equal(validation.match('buck',input).id,'B02'); assert.equal(validation.match('buck',{...input,C:input.C*1.01}),null); assert.equal(validation.coverage('buck',{...input,fsw:2.1e6}).outside.length,1); assert.equal(validation.match('pmsm',data.pmsm[0].input).id,'M01'); assert.equal(validation.match('pmsm',{...data.pmsm[0].input,angle:.3}),null); }); test('Buck estimates use the periodic complete-circuit reference instead of nearest samples',()=>{ const exact=validation.estimate('buck',{input:data.buck[1].input}); assert.equal(exact.tier,3);assert.equal(exact.exact,false);assert.ok(exact.referencePp>0);assert.ok(Math.abs(exact.errorPercent+2.857)<.01); const nearby=validation.estimate('buck',{input:{vin:24,fsw:20000,L:75e-6,iavg:5,D:.5,R:.05,Ls:1e-6,C:.0015}}); assert.ok([1,3,5].includes(nearby.tier));assert.equal(nearby.exact,false);assert.ok(nearby.upper>nearby.lower); assert.match(nearby.reason,/完整周期电路/); assert.equal(validation.estimate('pmsm',{input:data.pmsm[0].input}).disabled,true); }); test('unsupported algorithm settings and distant/ideal-boundary inputs never get an accuracy band',()=>{ const input=data.buck[1].input; assert.equal(validation.estimate('buck',{input,eligible:false}).tier,null); assert.equal(validation.estimate('buck',{input:{...input,fsw:1e8}}).tier,null); assert.equal(validation.estimate('buck',{input:{...input,C:0}}).tier,null); assert.equal(validation.estimate('buck',{input:{...input,R:0}}).tier,null); assert.equal(validation.estimate('pmsm',{input:null}).tier,null); });