improve tests
This commit is contained in:
parent
53246b1598
commit
616f574d64
4 changed files with 34 additions and 33 deletions
2
Makefile
2
Makefile
|
@ -17,7 +17,7 @@ format:
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
@echo $(EXECUTING)
|
@echo $(EXECUTING)
|
||||||
./ftest.native graphs/graph1 1 2 test/outfile
|
./ftest.native
|
||||||
@echo $(BUILDING_SVG)
|
@echo $(BUILDING_SVG)
|
||||||
@echo "outfile..."
|
@echo "outfile..."
|
||||||
@dot -Tsvg test/outfile > test/outfile.svg
|
@dot -Tsvg test/outfile > test/outfile.svg
|
||||||
|
|
|
@ -27,7 +27,7 @@ Then open VSCode in the root directory of this repository.
|
||||||
|
|
||||||
A makefile provides some useful commands:
|
A makefile provides some useful commands:
|
||||||
- `make build` to compile the base ff algorithm. This creates an ftest.native executable
|
- `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 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 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.
|
- `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.
|
||||||
|
|
|
@ -84,7 +84,7 @@ let circulation_from_file path =
|
||||||
(* Ignore empty lines *)
|
(* Ignore empty lines *)
|
||||||
if line = "" then graph
|
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
|
else match line.[0] with
|
||||||
| 'f' -> read_factory graph line
|
| 'f' -> read_factory graph line
|
||||||
| 'v' -> read_village graph line
|
| 'v' -> read_village graph line
|
||||||
|
|
61
src/ftest.ml
61
src/ftest.ml
|
@ -43,41 +43,42 @@ let test_ffalgo gr =
|
||||||
let () =
|
let () =
|
||||||
|
|
||||||
(* Check the number of command-line arguments *)
|
(* 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
|
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
|
exit 0
|
||||||
end ;
|
end ;
|
||||||
|
|
||||||
|
|
||||||
(* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *)
|
(* Arguments are : infile(1) source-id(2) sink-id(3) outfile(4) *)
|
||||||
|
|
||||||
let infile = Sys.argv.(1)
|
if Array.length Sys.argv <> 0 then
|
||||||
and outfile = Sys.argv.(4)
|
let infile = Sys.argv.(1)
|
||||||
and source = int_of_string Sys.argv.(2)
|
and outfile = Sys.argv.(4)
|
||||||
and sink = int_of_string Sys.argv.(3)
|
and source = int_of_string Sys.argv.(2)
|
||||||
in
|
and sink = int_of_string Sys.argv.(3)
|
||||||
|
in
|
||||||
(* Open file *)
|
(* Open file *)
|
||||||
let graph = from_file infile in
|
let graph = from_file infile in
|
||||||
(* Convert graph *)
|
(* Convert graph *)
|
||||||
let int_graph = (gmap graph int_of_string) in
|
let int_graph = (gmap graph int_of_string) in
|
||||||
(* Execute FF *)
|
(* Execute FF *)
|
||||||
let flow_network = run_ff {graph = int_graph; origin = source; destination = sink} in
|
let flow_network = run_ff {graph = int_graph; origin = source; destination = sink} in
|
||||||
(* Print max flow *)
|
(* Print max flow *)
|
||||||
let () = Printf.printf "Max flow: %d\n%!" (get_max_flow flow_network) in
|
let () = Printf.printf "Max flow: %d\n%!" (get_max_flow flow_network) in
|
||||||
(* Convert to string for export *)
|
(* Convert to string for export *)
|
||||||
let final_graph = flow_to_string flow_network.graph in
|
let final_graph = flow_to_string flow_network.graph in
|
||||||
|
(* Rewrite the graph that has been read. *)
|
||||||
(* TESTS *)
|
let () = export outfile final_graph in ()
|
||||||
(* let () = test_ffalgo (gmap graph int_of_string) in *)
|
else
|
||||||
(* let graph2 = clone_nodes graph in *)
|
(* TESTS *)
|
||||||
(* let graph2 = gmap (gmap (gmap graph int_of_string) (fun x -> x + 1)) string_of_int in *)
|
(* Open file *)
|
||||||
(* let graph2 = gmap (add_arc (gmap graph int_of_string) 2 1 13) string_of_int in *)
|
let graph = from_file "graph1" in
|
||||||
(* END TESTS *)
|
let () = test_ffalgo (gmap graph int_of_string) in
|
||||||
|
(* let graph2 = clone_nodes graph in *)
|
||||||
(* Rewrite the graph that has been read. *)
|
(* let graph2 = gmap (gmap (gmap graph int_of_string) (fun x -> x + 1)) string_of_int in *)
|
||||||
let () = export outfile final_graph in
|
(* let graph2 = gmap (add_arc (gmap graph int_of_string) 2 1 13) string_of_int in *)
|
||||||
|
(* END TESTS *)
|
||||||
()
|
()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue