Parcourir la source

Fixing state command

 - Add unit tests (TODO factorise it)
 - More spying expression
 - list passed seems to be empty
Leo il y a 9 ans
Parent
commit
3f8279c8c1
4 fichiers modifiés avec 51 ajouts et 5 suppressions
  1. 7 3
      src/exec_cmd.ml
  2. 34 2
      src/test/exec_t.ml
  3. 9 0
      src/tools.ml
  4. 1 0
      src/tools.mli

+ 7 - 3
src/exec_cmd.ml

@@ -61,11 +61,15 @@ let less_launched (log : (string * int) list) =
 
 (* Function to get the number corresponding to the next command to launch (less
  * launched) *)
-(* TODO Test it *)
 let less_launched_num log =
-  less_launched log
+  (* Debug *)
+  Messages.debug "less_launched_num: LOG:";
+  Tools.spy1_log log
+  |> less_launched
     |> function
-      | Some cmd -> List.Assoc.find log cmd
+      | Some cmd ->
+          Messages.debug (sprintf "Less launched cmd (in num) %s" cmd);
+          List.Assoc.find log cmd
       | None -> None
 ;;
 

+ 34 - 2
src/test/exec_t.ml

@@ -44,6 +44,12 @@ let less_launched test solution () =
   OUnit.assert_equal actual solution
 ;;
 
+(* Function less_launched_num *)
+let less_launched_num test solution () =
+  let actual = Exec_cmd.less_launched_num test in
+  OUnit.assert_equal actual solution
+;;
+
 (* Data for above test *)
 let ll_data =
   let max = Const.default_launch in
@@ -54,13 +60,39 @@ let ll_data =
   ( [ ( "cmd1", max ) ; ( "cmd2", (max + 5) ) ], None, "Everything (strcitly) superior to max" );
   ( [ ( "cmd1", 4 ) ; ( "cmd2", 4 ) ], None, "Twice the same number" );
 ]
+;;
+let ll_data2 =
+  let max = Const.default_launch in
+  [
+  ( [ ( "cmd1", 4 ) ; ( "cmd2", 0 ) ], Some 0, "Canonical case 1" );
+  ( [ ( "cmd1", 0 ) ; ( "cmd2", 5 ) ], Some 1, "Canonical case 2" );
+  ( [ ( "cmd1", 0 ) ; ( "cmd2", 3 ) ; ( "cmd3", 4 )  ; ( "cmd4", 5 ) ], Some 1, "Canonical case 3" );
+  ( [ ( "cmd1", 0 ) ; ( "cmd2", 4 ) ; ( "cmd3", 4 )  ; ( "cmd5", 5 ) ], None,
+  "Twice the same number, with others" );
+  ( [], None, "Empty list" );
+  ( [ ( "cmd1", max ) ; ( "cmd2", (max + 5) ) ], None, "Everything (strcitly) superior to max" );
+  ( [ ( "cmd1", 4 ) ; ( "cmd2", 4 ) ], None, "Twice the same number" );
+]
+;;
 
 let llt_l =
-  List.map ll_data ~f:(fun (t, s, name) -> ( (less_launched t s), name))
+  let less_launched_suit =
+    List.map ll_data ~f:(fun (t, s, name) -> ( (less_launched t s), name))
+  in
+  less_launched_suit
+  |> List.map ~f:(fun ( f,name ) -> (name, `Quick, f))
+;;
+
+let llt_l2 =
+  let less_launched_num_suit =
+    List.map ll_data2 ~f:(fun (t, s, name) -> ( (less_launched_num t s), name))
+  in
+  less_launched_num_suit
   |> List.map ~f:(fun ( f,name ) -> (name, `Quick, f))
 ;;
 
 (* To be used in test.ml *)
-let alco = [( "Exec_cmd.ml", llt_l );];;
+let alco = [( "Exec_cmd.ml.less_launched", llt_l ) ;
+  ( "Exec_cmd.ml.less_launched_num", llt_l2 )];;
 
 

+ 9 - 0
src/tools.ml

@@ -64,6 +64,15 @@ let spy1_float f =
   sprintf "%f" f
   |> spy f
 ;;
+let spy1_log (log : (string * int) list) =
+  let log_str = List.map log ~f:(fun (s, i) ->
+    sprintf "( %s, %i )" s i)
+  in
+  "[ " ^ (String.concat log_str) ^ " ]"
+  |> spy
+  |> ignore;
+  log
+;;
 let spy1_rc rc =
   failwith "Not implemented"
 ;;

+ 1 - 0
src/tools.mli

@@ -41,4 +41,5 @@ val spy1_int : int -> int
 val spy1_int_option : int option -> int option
 val spy1_string : string -> string
 val spy1_float : float -> float
+val spy1_log : (string * int) list -> (string * int) list
 val spy1_rc : 'a -> 'a