improve tests

This commit is contained in:
Arnaud Vergnet 2020-11-25 10:16:18 +01:00
parent 53246b1598
commit 616f574d64
4 changed files with 34 additions and 33 deletions

View file

@ -17,7 +17,7 @@ format:
test: build
@echo $(EXECUTING)
./ftest.native graphs/graph1 1 2 test/outfile
./ftest.native
@echo $(BUILDING_SVG)
@echo "outfile..."
@dot -Tsvg test/outfile > test/outfile.svg

View file

@ -27,7 +27,7 @@ Then open VSCode in the root directory of this repository.
A makefile provides some useful commands:
- `make build` to compile the base ff algorithm. This creates an ftest.native executable
- `make test` to run the `ftest` program with some arguments and generate svg files for each tests. You must first uncomment the tests in the `ftest` file. This uses graphs in the `graphs` folder and outputs in the `test` folder.
- `make test` to run the `ftest` program without arguments (executes tests) and generate svg files for each tests. This uses the `graph1` in the `graphs` folder and outputs in the `test` folder.
- `make demo` to run the `ftest` program with some arguments and generate the final svg file. This uses graphs in the `graphs` folder and outputs in the `run` folder.
- `make build_circulation` to compile the circulation-demand problem resolution. This creates a circulationtest.native executable
- `make demo_circulation` to run the `circulationtest` program with some arguments and generate the final svg file. This uses graphs in the `circulation_input_graphs` folder and outputs in the `run` folder.

View file

@ -84,7 +84,7 @@ let circulation_from_file path =
(* Ignore empty lines *)
if line = "" then graph
(* The first character of a line determines its content : n or e. *)
(* The first character of a line determines its content *)
else match line.[0] with
| 'f' -> read_factory graph line
| 'v' -> read_village graph line

View file

@ -43,41 +43,42 @@ let test_ffalgo gr =
let () =
(* Check the number of command-line arguments *)
if Array.length Sys.argv <> 5 then
if Array.length Sys.argv <> 5 && Array.length Sys.argv <> 0 then
begin
Printf.printf "\nUsage: %s infile source sink outfile\n\n%!" Sys.argv.(0) ;
Printf.printf "\nUsage: %s infile source sink outfile\n%!" Sys.argv.(0) ;
Printf.printf "Or no parameters to run tests\n\n%!" ;
exit 0
end ;
(* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *)
let infile = Sys.argv.(1)
and outfile = Sys.argv.(4)
and source = int_of_string Sys.argv.(2)
and sink = int_of_string Sys.argv.(3)
in
(* Open file *)
let graph = from_file infile in
(* Convert graph *)
let int_graph = (gmap graph int_of_string) in
(* Execute FF *)
let flow_network = run_ff {graph = int_graph; origin = source; destination = sink} in
(* Print max flow *)
let () = Printf.printf "Max flow: %d\n%!" (get_max_flow flow_network) in
(* Convert to string for export *)
let final_graph = flow_to_string flow_network.graph in
(* TESTS *)
(* let () = test_ffalgo (gmap graph int_of_string) in *)
(* let graph2 = clone_nodes graph in *)
(* let graph2 = gmap (gmap (gmap graph int_of_string) (fun x -> x + 1)) string_of_int in *)
(* let graph2 = gmap (add_arc (gmap graph int_of_string) 2 1 13) string_of_int in *)
(* END TESTS *)
(* Rewrite the graph that has been read. *)
let () = export outfile final_graph in
()
if Array.length Sys.argv <> 0 then
let infile = Sys.argv.(1)
and outfile = Sys.argv.(4)
and source = int_of_string Sys.argv.(2)
and sink = int_of_string Sys.argv.(3)
in
(* Open file *)
let graph = from_file infile in
(* Convert graph *)
let int_graph = (gmap graph int_of_string) in
(* Execute FF *)
let flow_network = run_ff {graph = int_graph; origin = source; destination = sink} in
(* Print max flow *)
let () = Printf.printf "Max flow: %d\n%!" (get_max_flow flow_network) in
(* Convert to string for export *)
let final_graph = flow_to_string flow_network.graph in
(* Rewrite the graph that has been read. *)
let () = export outfile final_graph in ()
else
(* TESTS *)
(* Open file *)
let graph = from_file "graph1" in
let () = test_ffalgo (gmap graph int_of_string) in
(* let graph2 = clone_nodes graph in *)
(* let graph2 = gmap (gmap (gmap graph int_of_string) (fun x -> x + 1)) string_of_int in *)
(* let graph2 = gmap (add_arc (gmap graph int_of_string) 2 1 13) string_of_int in *)
(* END TESTS *)
()