26 lines
874 B
JavaScript
26 lines
874 B
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { listToubiao, computeDist, QUESTIONS } from '../src/toubiao.js';
|
|
|
|
test('题库:每题两选项 + 双证揭晓带cite', () => {
|
|
const list = listToubiao();
|
|
assert.ok(list.length >= 4);
|
|
for (const q of list) {
|
|
assert.ok(q.qid && q.title && q.situ && q.options?.length === 2);
|
|
}
|
|
for (const q of Object.values(QUESTIONS)) {
|
|
assert.ok(q.real && /《.+》/.test(q.cite), `${q.qid} 揭晓须有正史 cite`);
|
|
}
|
|
});
|
|
|
|
test('computeDist:占比正确、零票不除零', () => {
|
|
const opts = [{ id: 'a' }, { id: 'b' }];
|
|
const r = computeDist({ a: 87, b: 13 }, opts);
|
|
assert.equal(r.total, 100);
|
|
assert.equal(r.dist.a.pct, 87);
|
|
assert.equal(r.dist.b.pct, 13);
|
|
const z = computeDist({}, opts);
|
|
assert.equal(z.total, 0);
|
|
assert.equal(z.dist.a.pct, 0); // 不除零
|
|
});
|