module Decode = Hito_web.Decode module Form = Dream_html.Form let exercise id = match Exercise.find_id id with | Some exercise -> exercise | None -> Alcotest.failf "catalog is missing %S" id let single = Prescription.Stimulus.make ~delivery:(Prescription.Stimulus.Single (exercise "laterals")) ~rep_range:(Prescription.Rep_range.make ~min:6 ~max:10) ~allowed_substitutes:[] let stimulus_tests = [ ( "decoder", [ ( "accepts a single working stimulus", `Quick, fun () -> match Form.validate (Decode.stimulus single) [ ("load", "30"); ("reps", "8"); ("extension", "") ] with | Ok _ -> () | Error errors -> Alcotest.failf "unexpected validation errors: %a" Form.pp_error errors ); ( "rejects an unknown extension", `Quick, fun () -> match Form.validate (Decode.stimulus single) [ ("load", "30"); ("reps", "8"); ("extension", "invented") ] with | Error [ ("extension", "error.extension") ] -> () | Error errors -> Alcotest.failf "unexpected errors: %a" Form.pp_error errors | Ok _ -> Alcotest.fail "expected extension validation failure" ); ( "accepts a zero load for bodyweight effort", `Quick, fun () -> match Form.validate (Decode.stimulus single) [ ("load", "0"); ("reps", "8"); ("extension", "") ] with | Ok stimulus -> let effort = List.hd (Evidence.Stimulus.efforts stimulus) in Alcotest.(check (float 0.001)) "zero load" 0. (Evidence.Stimulus.Effort.load effort) | Error errors -> Alcotest.failf "unexpected validation errors: %a" Form.pp_error errors ); ( "rejects a negative load", `Quick, fun () -> match Form.validate (Decode.stimulus single) [ ("load", "-1"); ("reps", "8"); ("extension", "") ] with | Error [ ("load", "error.load") ] -> () | Error errors -> Alcotest.failf "unexpected errors: %a" Form.pp_error errors | Ok _ -> Alcotest.fail "expected load validation failure" ); ] ); ] let suite = stimulus_tests