Joel Stevick

Appendix B · section 22 of 32

ask/widen.test.ts

From Once Found, Look It Up.

import test from "node:test";
import assert from "node:assert/strict";
import { LAWS } from "./corpus.js";
import { ROWS, penaltySentence } from "./schedule.js";
import { pagesLast, sectionOf, wholeSections, withPenalties } from "./sections.js";

const law = (id: string) => LAWS.find((each) => each.id === id)!;

test("a subsection keys to its section; a manual page keys to nothing", () => {
  assert.equal(sectionOf(law("MD-C-16-112-c")), "Md. Code, Transp. § 16-112");
  assert.equal(sectionOf(law("MD-S01")), "Md. Code, Transp. § 21-1003");
  assert.equal(sectionOf(law("MD-S10")), "Md. Code, Transp. § 21-801.1");
  assert.equal(sectionOf(law("MD-102")), null);
});

test("a chosen subsection brings the rest of its section, after it", () => {
  const given = wholeSections([law("MD-C-16-112-c")], LAWS);
  assert.deepEqual(
    given.map((each) => each.id),
    ["MD-C-16-112-c", "MD-C-16-112-b", "MD-C-16-112-d", "MD-C-16-112-e"],
  );
});

test("a manual law brings nothing", () => {
  assert.deepEqual(wholeSections([law("MD-102")], LAWS).map((each) => each.id), ["MD-102"]);
});

test("the schedule's row joins after the last law of its section, the matched subsection's row first", () => {
  const chosen = [law("MD-C-16-112-c")];
  const given = withPenalties(wholeSections(chosen, LAWS), ROWS, chosen);
  const ids = given.map((each) => each.id);
  assert.deepEqual(ids.slice(0, 4), ["MD-C-16-112-c", "MD-C-16-112-b", "MD-C-16-112-d", "MD-C-16-112-e"]);
  assert.deepEqual(ids.slice(4), ["MD-P-16-112-c", "MD-P-16-112-b"]);
  assert.equal(given[4].kind, "penalty");
  assert.equal(given[4].law, "Failure of individual driving on hwy. to display lic. to uniformed police on demand: $50, can be paid without going to court, no points.");
});

test("a row for a section not given stays out", () => {
  const given = withPenalties([law("MD-S01")], ROWS);
  assert.ok(!given.some((each) => each.kind === "penalty"));
});

test("a court-set fine names the range and never one figure", () => {
  assert.equal(
    penaltySentence({ ...ROWS[0], appear: "court-sets", fine_min_cents: 2500, fine_max_cents: 20000, points: null }),
    "Failure of individual driving on hwy. to have lic. with them: a fine set by the court within $25 to $200.",
  );
});

test("the state's own pages go last, in their order", () => {
  const given = pagesLast([law("MD-R-test-and-retake-1"), law("MD-S01"), law("MD-R-insurance-minimums-1")]);
  assert.deepEqual(given.map((each) => each.id), ["MD-S01", "MD-R-test-and-retake-1", "MD-R-insurance-minimums-1"]);
});