49 lines
2.4 KiB
JavaScript
49 lines
2.4 KiB
JavaScript
const d = require('../questions.json');
|
|
let total = 0, bad = [];
|
|
for (const set of d.sets) {
|
|
for (const q of set.questions) {
|
|
total++;
|
|
if (!q.q || !Array.isArray(q.opts) || q.opts.length < 2) { bad.push(`[${set.name} #${q.id}] 选项不足`); continue; }
|
|
if (!Number.isInteger(q.ans) || q.ans < 0 || q.ans >= q.opts.length) { bad.push(`[${set.name} #${q.id}] ans 越界`); continue; }
|
|
if (!q.exp) { bad.push(`[${set.name} #${q.id}] 缺解析`); continue; }
|
|
if (!Number.isInteger(q.lv) || q.lv < 1 || q.lv > 6) { bad.push(`[${set.name} #${q.id}] lv 非法`); continue; }
|
|
const dup = q.opts.findIndex((o, i) => q.opts.indexOf(o) !== i);
|
|
if (dup !== -1) { bad.push(`[${set.name} #${q.id}] 选项重复: "${q.opts[dup]}"`); }
|
|
}
|
|
}
|
|
console.log('总题数:', total);
|
|
if (bad.length) { console.log('问题:'); bad.forEach(b => console.log(' -', b)); }
|
|
else console.log('结构校验全部通过');
|
|
|
|
const checks = [
|
|
['Dart 开发实战', 'var x = 10', 1],
|
|
['Dart 开发实战', 'orders = 60', 1],
|
|
['Dart 开发实战', 'remove(3)', 0],
|
|
['Dart 开发实战', '不存在的 key', 1],
|
|
['Dart 开发实战', 'if (isVip) 3', 0],
|
|
['Dart 开发实战', 'reduce((a, b)', 1],
|
|
['Dart 开发实战', 'factory 构造函数', 0],
|
|
['Dart 开发实战', 'mixin', 2],
|
|
['Dart 开发实战', 's!', 1],
|
|
['Dart 开发实战', 'late String token', 0],
|
|
['Flutter 开发实战', 'runApp(MyApp())', 0],
|
|
['Flutter 开发实战', 'crossAxisAlignment', 0],
|
|
['Flutter 开发实战', 'TextOverflow.ellipsis', 0],
|
|
['Flutter 开发实战', 'RefreshIndicator', 0],
|
|
['Flutter 开发实战', 'Navigator.pop(context, result)', 0],
|
|
['Flutter 开发实战', 'jsonDecode(text)', 0],
|
|
['Flutter 开发实战', '.timeout(Duration', 0],
|
|
['Flutter 开发实战', 'cacheWidth', 0],
|
|
['Flutter 开发实战', 'RichText', 0],
|
|
['Flutter 开发实战', 'dispose()', 0]
|
|
];
|
|
let fail = 0;
|
|
for (const [setName, keyword, expect] of checks) {
|
|
const set = d.sets.find(s => s.name === setName);
|
|
const q = set.questions.find(x => (x.q + x.opts.join('') + x.exp).includes(keyword));
|
|
if (!q) { console.log('✗ 未找到题:', setName, keyword); fail++; continue; }
|
|
const ok = q.ans === expect;
|
|
if (!ok) { console.log(`✗ [${setName}] ${keyword} → ans=${q.ans} 期望 ${expect},正确选项内容: "${q.opts[q.ans]}"`); fail++; }
|
|
}
|
|
console.log(fail ? `抽查 ${checks.length} 题,${fail} 题不符` : `抽查 ${checks.length} 道关键题答案全部正确`);
|