module Calendar = Hito_web.Calendar let invalid_month f = try ignore (f ()); false with Invalid_argument _ -> true let suite = [ ( "calendar", [ ( "recognizes Gregorian leap years", `Quick, fun () -> Alcotest.(check bool) "1900 is not leap" false (Calendar.is_leap 1900); Alcotest.(check bool) "2000 is leap" true (Calendar.is_leap 2000); Alcotest.(check bool) "2024 is leap" true (Calendar.is_leap 2024) ); ( "counts every month", `Quick, fun () -> let expected = [ 31; 29; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31 ] in List.iteri (fun index days -> Alcotest.(check int) (Printf.sprintf "month %d" (index + 1)) days (Calendar.days_in_month ~year:2024 ~month:(index + 1))) expected ); ( "rejects an invalid month", `Quick, fun () -> Alcotest.(check bool) "month 13" true (invalid_month (fun () -> Calendar.days_in_month ~year:2024 ~month:13)) ); ( "converts Gregorian dates to UTC seconds", `Quick, fun () -> Alcotest.(check int) "Unix epoch" 0 (Calendar.unix_seconds_of_date ~year:1970 ~month:1 ~day:1); Alcotest.(check int) "day after epoch" 86_400 (Calendar.unix_seconds_of_date ~year:1970 ~month:1 ~day:2) ); ( "returns Monday-first weekdays", `Quick, fun () -> Alcotest.(check int) "1970-01-01 was Thursday" 3 (Calendar.monday_first_weekday ~year:1970 ~month:1 ~day:1); Alcotest.(check int) "2024-01-01 was Monday" 0 (Calendar.monday_first_weekday ~year:2024 ~month:1 ~day:1) ); ] ); ]