Baseline: tree as shared

This commit is contained in:
alexm committed 2026-10-05 03:03:38 +00:00
commit 31f2fb8a5a
1679 files changed
+1024562

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
// Every exercise file is checked here, so adding one is safe.
import test from 'node:test';
import assert from 'node:assert/strict';
import { EXERCISES } from '../dist/exercises/index.js';
import { PROBLEMS, stateForProblem } from '../dist/core/catalog.js';
import { Session } from '../dist/core/session.js';
import template from '../dist/exercises/_template.js';
globalThis.localStorage = { getItem() { return null; }, setItem() { }, removeItem() { } };
test('exercise ids are unique, URL-safe, and the template is not registered', () => {
const ids = EXERCISES.map((e) => e.id);
assert.equal(new Set(ids).size, ids.length);
for (const id of ids) assert.match(id, /^[a-z0-9]+(-[a-z0-9]+)*$/, id);
assert.ok(!ids.includes(template.id));
});
test('every exercise with an expected answer produces it', () => {
for (const p of PROBLEMS) {
if (!p.expect) continue;
const st = stateForProblem(p);
if (st.sources.pseudo) st.lang = 'pseudo';
const s = new Session(st);
const tr = s.trace();
assert.ok(tr && !tr.error, `${p.id}: ${s.runError || tr?.error?.message}`);
const last = tr.output.at(-1);
assert.ok(last.endsWith(` returned ${p.expect}`), `${p.id}: expected …returned ${p.expect}, got ${last}`);
}
});
test('the template itself is a valid exercise', () => {
const s = new Session(stateForProblem({ ...template, lang: 'pseudo' }));
const tr = s.trace();
assert.ok(tr && !tr.error, s.runError || tr?.error?.message);
assert.ok(tr.output.at(-1).endsWith(`returned ${template.expect}`));
assert.equal(s.proof().report.counts.open + s.proof().report.counts.broken, 0);
});