diff --git a/scrape/utils/parseAbsence.js b/scrape/utils/parseAbsence.js index 4a14569..f4f7529 100644 --- a/scrape/utils/parseAbsence.js +++ b/scrape/utils/parseAbsence.js @@ -100,7 +100,7 @@ export default function parseAbsence(input, teacherMap = {}) { // 1. Teachers with specific hours (e.g. "Ab 1-4") const teacherListThenSpecRe = - /([A-Za-z]+(?:[,;]\s?[A-Za-z]+)*)(?:\s*)(\d+(?:\+|-\d+|,\d+)?)(?![A-Za-z])/g; + /([A-Za-z]+(?:[,;]\s?[A-Za-z]+)*)(?:\s*)(\d+(?:\+|-\d+|,\d+)?)(?:\.\s*h)?(?![A-Za-z])/g; let m; while ((m = teacherListThenSpecRe.exec(s)) !== null) { diff --git a/tests/test.js b/tests/test.js index 419e96d..ac0e3cb 100644 --- a/tests/test.js +++ b/tests/test.js @@ -12,19 +12,18 @@ * GNU General Public License for more details. */ -import fs from "fs" +import fs from "fs"; import parseAbsence from "../scrape/utils/parseAbsence.js"; -const teachermap = JSON.parse(fs.readFileSync("./teachermap.json")) - +const teachermap = JSON.parse(fs.readFileSync("./teachermap.json")); test("Me", [ { teacher: "Michaela Meitnerová", teacherCode: "me", type: "wholeDay", - hours: null - } + hours: null, + }, ]); test("ad", [ @@ -32,8 +31,8 @@ test("ad", [ teacher: "Bc. Daniel Adámek", teacherCode: "ad", type: "wholeDay", - hours: null - } + hours: null, + }, ]); test("me ad", [ @@ -41,14 +40,14 @@ test("me ad", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "wholeDay", - hours: null + hours: null, }, { teacher: "Bc. Daniel Adámek", teacherCode: "ad", type: "wholeDay", - hours: null - } + hours: null, + }, ]); test("me 3", [ @@ -56,8 +55,8 @@ test("me 3", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "single", - hours: 3 - } + hours: 3, + }, ]); test("ad 1", [ @@ -65,8 +64,8 @@ test("ad 1", [ teacher: "Bc. Daniel Adámek", teacherCode: "ad", type: "single", - hours: 1 - } + hours: 1, + }, ]); test("me 2-4", [ @@ -74,8 +73,8 @@ test("me 2-4", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "range", - hours: { from: 2, to: 4 } - } + hours: { from: 2, to: 4 }, + }, ]); test("ad 5,6", [ @@ -83,8 +82,8 @@ test("ad 5,6", [ teacher: "Bc. Daniel Adámek", teacherCode: "ad", type: "range", - hours: { from: 5, to: 6 } - } + hours: { from: 5, to: 6 }, + }, ]); test("me 7+", [ @@ -92,8 +91,8 @@ test("me 7+", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "range", - hours: { from: 7, to: 10 } - } + hours: { from: 7, to: 10 }, + }, ]); test("me,ad 3-5", [ @@ -101,14 +100,14 @@ test("me,ad 3-5", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "range", - hours: { from: 3, to: 5 } + hours: { from: 3, to: 5 }, }, { teacher: "Bc. Daniel Adámek", teacherCode: "ad", type: "range", - hours: { from: 3, to: 5 } - } + hours: { from: 3, to: 5 }, + }, ]); test("me;ad 4", [ @@ -116,14 +115,14 @@ test("me;ad 4", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "wholeDay", - hours: null + hours: null, }, { teacher: "Bc. Daniel Adámek", teacherCode: "ad", type: "single", - hours: 4 - } + hours: 4, + }, ]); test("me;ad;bo 2-3", [ @@ -131,20 +130,20 @@ test("me;ad;bo 2-3", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "wholeDay", - hours: null + hours: null, }, { teacher: "Bc. Daniel Adámek", teacherCode: "ad", type: "wholeDay", - hours: null + hours: null, }, { teacher: "Ing. Anna Bodnárová", teacherCode: "bo", type: "range", - hours: { from: 2, to: 3 } - } + hours: { from: 2, to: 3 }, + }, ]); test("me 2 ad 4-5", [ @@ -152,14 +151,14 @@ test("me 2 ad 4-5", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "single", - hours: 2 + hours: 2, }, { teacher: "Bc. Daniel Adámek", teacherCode: "ad", type: "range", - hours: { from: 4, to: 5 } - } + hours: { from: 4, to: 5 }, + }, ]); test("3", [ @@ -168,8 +167,8 @@ test("3", [ teacher: null, teacherCode: null, hours: null, - original: "3" - } + original: "3", + }, ]); test("2-4", [ @@ -178,8 +177,8 @@ test("2-4", [ teacher: null, teacherCode: null, hours: null, - original: "2-4" - } + original: "2-4", + }, ]); test("me Xx 3", [ @@ -187,9 +186,9 @@ test("me Xx 3", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "wholeDay", - hours: null + hours: null, }, - { teacher: null, teacherCode: 'xx', type: 'single', hours: 3 }, + { teacher: null, teacherCode: "xx", type: "single", hours: 3 }, ]); test("me,ad;bo 1-2 ad 5+", [ @@ -197,26 +196,26 @@ test("me,ad;bo 1-2 ad 5+", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "wholeDay", - hours: null + hours: null, }, { teacher: "Bc. Daniel Adámek", teacherCode: "ad", type: "wholeDay", - hours: null + hours: null, }, { teacher: "Ing. Anna Bodnárová", teacherCode: "bo", type: "range", - hours: { from: 1, to: 2 } + hours: { from: 1, to: 2 }, }, { teacher: "Bc. Daniel Adámek", teacherCode: "ad", type: "range", - hours: { from: 5, to: 10 } - } + hours: { from: 5, to: 10 }, + }, ]); test("Me-exk", [ @@ -224,9 +223,9 @@ test("Me-exk", [ teacher: "Michaela Meitnerová", teacherCode: "me", type: "exkurze", - hours: null - } -]) + hours: null, + }, +]); test("za Vn zastupuje Jk", [ { @@ -235,10 +234,19 @@ test("za Vn zastupuje Jk", [ type: "zastoupen", zastupuje: { teacher: "David Janoušek", - teacherCode: "jk" + teacherCode: "jk", }, - } -]) + }, +]); + +test("Vc 1. h", [ + { + teacher: "Ing. Antonín Vobecký", + teacherCode: "vc", + type: "single", + hours: 1, + }, +]); function test(input, expectedOutput) { const res = parseAbsence(input, teachermap); @@ -254,7 +262,12 @@ function test(input, expectedOutput) { function deepEqual(a, b) { if (a === b) return true; - if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) { + if ( + typeof a !== "object" || + a === null || + typeof b !== "object" || + b === null + ) { return false; } @@ -264,15 +277,15 @@ function deepEqual(a, b) { const used = new Array(b.length).fill(false); - return a.every(itemA => + return a.every((itemA) => b.some((itemB, i) => { - if (used[i]) return false; // don't reuse elements + if (used[i]) return false; // don't reuse elements if (deepEqual(itemA, itemB)) { - used[i] = true; // mark element as used + used[i] = true; // mark element as used return true; } return false; - }) + }), ); } @@ -283,5 +296,5 @@ function deepEqual(a, b) { if (keysA.length !== keysB.length) return false; - return keysA.every(key => keysB.includes(key) && deepEqual(a[key], b[key])); + return keysA.every((key) => keysB.includes(key) && deepEqual(a[key], b[key])); }