Browse Source

Status command working!

 + Rewrite more semantically to avoid the issue of preceding code: return the
 number of launch, instead of the number of the command in config file
 + Adapted test cases, didn't match the purpose
Leo 9 years ago
parent
commit
cd0ba5fbbb
2 changed files with 20 additions and 14 deletions
  1. 16 10
      src/exec_cmd.ml
  2. 4 4
      src/test/exec_t.ml

+ 16 - 10
src/exec_cmd.ml

@@ -66,17 +66,23 @@ let less_launched_num log =
   Messages.debug "less_launched_num: LOG:";
   Tools.spy1_log log
 
-  (* Find the less launched by sorting and taking he first *)
-  |> List.sort ~cmp:(fun ( _, i1 ) ( _, i2 ) -> Int.compare i1 i2)
+  (* Function to return nothing (None) when max launch number is reached, Some
+   * number otherwise *)
+  |> List.filter_mapi ~f:(fun entry_number ( _, launch_number ) ->
+      if launch_number >= Const.default_launch
+      then None
+      else Some ( entry_number, launch_number ))
+  (* Find the less launched by sorting and taking the first *)
+  |> List.sort ~cmp:(fun ( _, launch_number1 ) ( _, launch_number2 ) -> Int.compare launch_number1 launch_number2)
   |> List.hd
-    |> function
-      | Some ( cmd, launch_number) ->
-          Messages.debug (sprintf "Less launched cmd (in num) %s" cmd);
-          Messages.debug "Return launch number (printed bellow):";
-          Some ( Tools.spy1_int launch_number )
-      | None ->
-          Messages.debug "No less launched cmd.";
-          None
+  |> function
+    | Some ( entry_number, launch_number) ->
+        launch_number |> sprintf "Launch number found: %i" |> Messages.debug;
+        Messages.debug "Return launch number (printed bellow):";
+        Some ( Tools.spy1_int entry_number )
+    | None ->
+        Messages.debug "No less launched cmd.";
+        None
 ;;
 
 (* Function to determinate what is the next command to

+ 4 - 4
src/test/exec_t.ml

@@ -64,10 +64,10 @@ let ll_data =
 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,
+  ( [ ( "cmd1", 0 ) ; ( "cmd2", 5 ) ], Some 0, "Canonical case 1" );
+  ( [ ( "cmd1", 4 ) ; ( "cmd2", 0 ) ], Some 1, "Canonical case 2" );
+  ( [ ( "cmd1", 0 ) ; ( "cmd2", 3 ) ; ( "cmd3", 4 )  ; ( "cmd4", 5 ) ], Some 0, "Canonical case 3" );
+  ( [ ( "cmd1", 0 ) ; ( "cmd2", 4 ) ; ( "cmd3", 4 )  ; ( "cmd5", 5 ) ], Some 0,
   "Twice the same number, with others" );
   ( [], None, "Empty list" );
   ( [ ( "cmd1", max ) ; ( "cmd2", (max + 5) ) ], None, "Everything (strcitly) superior to max" );