let print_event e = Printf.printf "%dh->%dh: %s" e.start e.finish e.info; print_newline ();; let print_day d = List.iter (fun (s,e) -> Printf.printf "%s:" s; print_event e) d;; let f_get_day n () = print_day (get_day n);; let f_get_agenda () = let a = get_agenda () in for i = 0 to Array.length a - 1 do Printf.printf "[%d]:\n" i; print_day a.(i) done; flush Pervasives.stdout;; let f_add_event name day start finish info ()= add_event name day start finish info ; Printf.printf "[%d] event %s added : " day name; print_event { start=start ; finish=finish ; info=info};; let f_delete_event name day () = delete_event name day; Printf.printf "[%d] event %s deleted " day name; print_newline ();; let suites = [| [ f_get_agenda ; f_add_event "salon" 2 9 17 "salon de l'agriculture à Paris" ; f_get_day 2 ; ] ; [ f_get_day 2 ; f_delete_event "salon" 2 ; f_get_agenda ; ] ; |] ;; let exec_f f = try f () with Assert_failure _ as e -> raise e | e -> Printf.eprintf "Exception %s\n" (Printexc.to_string e) let main () = if Array.length Sys.argv < 2 then begin Printf.eprintf "usage : %s <n>\n" Sys.argv.(0); flush Pervasives.stderr ; exit 1 end else try List.iter exec_f suites.(int_of_string Sys.argv.(1)) with _ -> ( prerr_endline "suite de commandes non définie."; exit 2 );; handle_unix_error main ();; |