// Run: node --test opt_counter.test.js (Node 18+, from this folder) // Expected values are the brief's T1-T11, the same cases as test_opt_counter.py. const test = require("node:test"); const assert = require("node:assert"); const { countUnemployment } = require("./opt_counter.js"); const job = (start, end = null, qualifying = true) => ({ start, end, qualifying }); const STEM_JOB = job("2025-09-19", "2026-06-30"); const PAST_JOB = job("2025-06-01", "2026-04-30"); const CASES = [ // [id, [eadStart, authEnd, asOf, jobs, stemStart], [used, limit, remaining, firstOver]] ["T1 Priya", ["2026-06-01", "2027-05-31", "2026-09-30", [job("2026-07-01", "2026-08-14"), job("2026-09-01")]], [47, 90, 43, null]], ["T2 no job", ["2026-06-01", "2027-05-31", "2026-06-30", []], [30, 90, 60, null]], ["T3 weekend gap", ["2026-06-01", "2027-05-31", "2026-07-31", [job("2026-06-01", "2026-07-10"), job("2026-07-13")]], [2, 90, 88, null]], ["T4 non-qualifying", ["2026-06-01", "2027-05-31", "2026-06-30", [job("2026-06-01", null, false)]], [30, 90, 60, null]], ["T5 overlap", ["2026-06-01", "2027-05-31", "2026-06-30", [job("2026-06-05", "2026-06-20"), job("2026-06-10", "2026-06-25")]], [9, 90, 81, null]], ["T6 job before EAD", ["2026-06-01", "2027-05-31", "2026-06-30", [job("2026-05-01", "2026-06-10")]], [20, 90, 70, null]], ["T7a STEM before start", ["2025-07-01", "2028-06-30", "2026-06-30", [STEM_JOB], "2026-07-01"], [80, 90, 10, null]], ["T7b STEM after start", ["2025-07-01", "2028-06-30", "2026-07-31", [STEM_JOB], "2026-07-01"], [111, 150, 39, null]], ["T8 over limit", ["2026-06-01", "2027-05-31", "2026-08-31", []], [92, 90, -2, "2026-08-30"]], ["T9 as_of after auth end", ["2025-06-01", "2026-05-31", "2026-09-30", [PAST_JOB]], [31, 90, 59, null]], ["T10 cap-gap", ["2025-06-01", "2026-09-30", "2026-07-15", [PAST_JOB]], [76, 90, 14, null]], ["T11 leap day", ["2028-02-01", "2029-01-31", "2028-02-29", []], [29, 90, 61, null]], ]; for (const [name, args, expected] of CASES) { test(name, () => { const r = countUnemployment(...args); assert.deepStrictEqual([r.days_used, r.limit, r.days_remaining, r.first_day_over_limit], expected); assert.strictEqual(r.unemployed_dates.length, r.days_used); }); } test("weekend gap dates are Sat and Sun", () => { const r = countUnemployment(...CASES[2][1]); assert.deepStrictEqual(r.unemployed_dates, ["2026-07-11", "2026-07-12"]); }); test("rejects impossible dates", () => { assert.throws(() => countUnemployment("2026-02-30", "2027-05-31", "2026-06-30", [])); });