Skip to content

[FEATURE]: Build comprehensive regression test suite for attendance calculations & prediction engine #24

Description

@Hanu2908

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

  1. 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).
  2. 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).
  3. 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.
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: attendanceAttendance calculation engine and simulatorsarea: testsTest suites and verificationenhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions