File size: 3,951 Bytes
c140718
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d624b50
 
 
 
 
 
 
4ccac56
 
 
6055ba8
4ccac56
 
 
 
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
import test from 'node:test';
import assert from 'node:assert/strict';
import {readFileSync,existsSync} from 'node:fs';
const data=JSON.parse(readFileSync(new URL('../data.json',import.meta.url),'utf8'));
test('snapshot covers all World Bank economies with every indicator key present',()=>{
  assert.ok(data.countries.length>=190,'economy count');
  const keys=Object.keys(data.indicators);
  assert.ok(keys.includes('sao')&&keys.includes('volume')&&keys.includes('catastrophic')&&keys.includes('impoverishing'),'LCoGS indicators present');
  for(const c of data.countries){assert.match(c.id,/^[A-Z]{3}$/);assert.deepEqual(Object.keys(c.series).sort(),keys.slice().sort(),c.id);
    for(const [k,s] of Object.entries(c.series)){let prev=-1;for(const [y,v] of s){assert.ok(y>prev&&y>=data.yearRange[0]&&y<=data.yearRange[1],`${c.id} ${k} year order`);assert.ok(Number.isFinite(v),`${c.id} ${k} finite`);prev=y;}}}
});
test('indicator groups only reference defined indicators and LCoGS targets are the Commission values',()=>{
  for(const g of data.indicatorGroups)for(const k of g.indicators)assert.ok(data.indicators[k],k);
  assert.equal(data.indicators.sao.target,20);assert.equal(data.indicators.volume.target,5000);assert.equal(data.indicators.catastrophic.target,0);assert.equal(data.indicators.impoverishing.target,0);
});
test('no value is fabricated: every non-empty series belongs to a source with a URL and licence note',()=>{
  const sourceIds=new Set(data.sources.map(s=>s.id));
  for(const [k,d] of Object.entries(data.indicators))assert.ok(sourceIds.has(d.sourceId),k+' source '+d.sourceId);
  for(const s of data.sources){assert.match(s.url,/^https:\/\//);assert.ok(s.licenseNote);}
});
test('built index.html embeds the same snapshot version as data.json',{skip:!existsSync(new URL('../index.html',import.meta.url))},()=>{
  const html=readFileSync(new URL('../index.html',import.meta.url),'utf8');
  assert.ok(html.includes(`window.ASCEND_DATA={"version":"${data.version}"`),'embedded data version');
  assert.ok(!html.includes('<script type="module" src="app.mjs">'),'module script was inlined');
});

test('modelled access indicators, when present, are percentages within 0–100 with a 2020 reference year and the 80% LCoGS target',{skip:!data.indicators.access2h},()=>{
  assert.equal(data.indicators.access2h.target,80);
  let n=0;for(const c of data.countries)for(const k of ['access1h','access2h','access1h_walk','access2h_walk'])for(const [y,v] of c.series[k]||[]){assert.equal(y,2020);assert.ok(v>=0&&v<=100,`${c.id} ${k} ${v}`);n++;}
  assert.ok(n>700,'access observations present');
  for(const c of data.countries){const a1=c.series.access1h?.[0]?.[1],a2=c.series.access2h?.[0]?.[1];if(a1!==undefined&&a2!==undefined)assert.ok(a2>=a1-1e-6,c.id+' 2h share ≥ 1h share');}
});

test('UN Data Commons cross-checks: mapped indicators carry a DCID, latest values are stored per economy, agreement summary is present',()=>{
  const mapped=Object.entries(data.indicators).filter(([k,d])=>d.undc?.variable);
  assert.ok(mapped.length>=7,'mapped indicators');assert.ok(data.indicators.sao.undc?.derived&&data.indicators.sao.undc.agreement.economiesCompared>100,'derived SAO cross-check');for(const k of ['volume','catastrophic','impoverishing','spending_ppp'])assert.equal(data.indicators[k].undc?.status,'no-counterpart',k);
  for(const [k,d] of mapped){assert.match(d.undc.variable,/^undata\//);assert.ok(d.undc.agreement?.economiesCompared>100,k+' compared');assert.ok(d.undc.agreement.withinFivePercent/d.undc.agreement.economiesCompared>0.85,k+' agreement rate');}
  let n=0;for(const c of data.countries)for(const [k,v] of Object.entries(c.crosscheck||{})){assert.ok(data.indicators[k].undc,k);const [[y,val],count]=v;assert.ok(y>=1985&&y<=2026&&Number.isFinite(val)&&count>=1,c.id+' '+k);n++;}
  assert.ok(n>400,'crosscheck entries');assert.ok(data.undc.rest.startsWith('https://unsd-datacommons.gcp.un-icc.cloud/'));
});