<?php
declare(strict_types=1);

require_once dirname(__DIR__) . '/includes/functions.php';

$failures = [];
$check = static function (bool $condition, string $message) use (&$failures): void {
    if (!$condition) {
        $failures[] = $message;
    }
};

$check(validDate('2026-07-20'), 'validDate should accept a valid ISO date');
$check(!validDate('2026-02-30'), 'validDate should reject an impossible date');
$check(attendanceStatusByMinutes(40) === 'present', '40 minutes must be present');
$check(attendanceStatusByMinutes(20) === 'late', '20 minutes must be late');
$check(attendanceStatusByMinutes(19) === 'absent', '19 minutes must be absent');
$check(attendanceStatusByArrival(10) === 'present', 'arrival at 10 minutes must be present');
$check(attendanceStatusByArrival(11) === 'late', 'arrival after 10 minutes must be late');
$check(gradeLetter(95) === 'A+', '95 must be A+');
$check(gradeLetter(59) === 'F', '59 must be F');
$check(getPassStatus(60) === 'passed', '60 must pass');
$check(getPassStatus(59.99) === 'failed', 'below 60 must fail');
$check(strlen(generateToken(32)) === 32, 'generateToken(32) must return 32 hexadecimal characters');

if ($failures !== []) {
    fwrite(STDERR, "FAILED\n- " . implode("\n- ", $failures) . "\n");
    exit(1);
}

echo "Pure function tests passed.\n";
