File size: 1,734 Bytes
9d57416
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import {metric, populationText} from '../src/format.ts';
import type {MetricUnits} from '../src/contract.ts';

test('显式契约单位决定整数、秒、百分比;缺失和错误计数拒绝', () => {
  const units: MetricUnits = {opaqueA: 'count', opaqueB: 's', opaqueC: 'ratio'};
  assert.equal(metric(5, 'opaqueA', units), '5');
  assert.equal(metric(-2, 'opaqueA', units), '-2'); // A count difference may be negative.
  assert.equal(metric(5, 'opaqueB', units), '5.0 s');
  assert.equal(metric(.25, 'opaqueC', units), '25.0%');
  assert.throws(() => metric(5.1, 'opaqueA', units));
  assert.throws(() => metric(5, 'notDeclared', units));
  assert.throws(() => populationText({total: 401, generated: 401, not_generated: 4, ready: 401, pending: 0, failed: 0}));
});

test('真实v5声明405格含4失败,删除失败不能沿用原分母', {skip: !process.env.CONSOLE_FIXTURE_ROOT || !fs.existsSync(path.join(process.env.CONSOLE_FIXTURE_ROOT, 'slice1-v5/raw-index.json')) ? '缺少原始slice1-v5/raw-index.json,不使用其他批次替代' : false}, () => {
  const raw = JSON.parse(fs.readFileSync(path.join(process.env.CONSOLE_FIXTURE_ROOT!, 'slice1-v5/raw-index.json'), 'utf8'));
  const generated = raw.rows.filter((r: {status: string}) => r.status === 'generated').length;
  const omitted = raw.rows.length - generated;
  const p = {total: raw.declared_count, generated, not_generated: omitted, ready: 0, pending: generated, failed: 0};
  assert.equal(populationText(p), '405 格:401 生成、4 未生成');
  assert.throws(() => populationText({...p, total: raw.rows.length - 1}));
});