Description
ClassHub relies on exact integer arithmetic (target * total - 100 * attended) / (100 - target) in src/lib/utils/attendance.ts to calculate attendance metrics, safe bunks, and required classes without floating-point IEEE 754 precision issues.
To ensure future enhancements (such as configurable attendance targets and academic calendar integrations) do not cause mathematical regressions, we need a dedicated, comprehensive regression test suite covering the entire calculation and prediction engine across multiple target thresholds.
Relevant files
src/lib/utils/attendance.ts (Core attendance formulas, safe bunk calculations, boost/bunk simulator)
src/lib/utils/attendancePrediction.ts (Recovery projection engine with timetable frequency & academic calendar linkage)
tests/unit/attendanceCalculations.test.ts (Existing unit test suite)
Requirements and acceptance criteria
-
Threshold variation coverage:
- Verify calculation correctness across standard target percentages:
75%, 80%, 85%, and 90%.
- Verify integer rounding behavior for safe bunks (
Math.floor) and required classes (Math.ceil).
-
Boundary and edge case matrix:
0 attended / 0 held (Initial state: should return 0% without NaN or division by zero).
100% attendance (e.g. 20/20: safe bunk calculation must return exact positive integer).
0% attendance (e.g. 0/10: required classes calculation must return exact number needed to recover).
- Exact threshold match (e.g. 15/20 = 75%: safe bunk = 0, needed = 0).
- Single class away from threshold (boundary transitions).
-
Simulator and recovery prediction assertions:
- Verify
simulateBoost(current, additionalAttended) and simulateBunk(current, additionalMissed).
- Verify
calculateAttendancePrediction projects recovery dates based on subject timetable frequencies and institutional break dates.
-
Testing framework:
- Add new test cases to
tests/unit/attendanceCalculations.test.ts using Vitest (describe, it, expect).
- All tests must pass with
npm test.
Testing locally
npm test tests/unit/attendanceCalculations.test.ts
Description
ClassHub relies on exact integer arithmetic
(target * total - 100 * attended) / (100 - target)insrc/lib/utils/attendance.tsto calculate attendance metrics, safe bunks, and required classes without floating-point IEEE 754 precision issues.To ensure future enhancements (such as configurable attendance targets and academic calendar integrations) do not cause mathematical regressions, we need a dedicated, comprehensive regression test suite covering the entire calculation and prediction engine across multiple target thresholds.
Relevant files
src/lib/utils/attendance.ts(Core attendance formulas, safe bunk calculations, boost/bunk simulator)src/lib/utils/attendancePrediction.ts(Recovery projection engine with timetable frequency & academic calendar linkage)tests/unit/attendanceCalculations.test.ts(Existing unit test suite)Requirements and acceptance criteria
Threshold variation coverage:
75%,80%,85%, and90%.Math.floor) and required classes (Math.ceil).Boundary and edge case matrix:
0attended /0held (Initial state: should return 0% withoutNaNor division by zero).100%attendance (e.g. 20/20: safe bunk calculation must return exact positive integer).0%attendance (e.g. 0/10: required classes calculation must return exact number needed to recover).Simulator and recovery prediction assertions:
simulateBoost(current, additionalAttended)andsimulateBunk(current, additionalMissed).calculateAttendancePredictionprojects recovery dates based on subject timetable frequencies and institutional break dates.Testing framework:
tests/unit/attendanceCalculations.test.tsusing Vitest (describe,it,expect).npm test.Testing locally
npm test tests/unit/attendanceCalculations.test.ts