From 616f574d6403824d1f2be2c0833fa7d3813f5f8a Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Wed, 25 Nov 2020 10:16:18 +0100 Subject: [PATCH] improve tests --- Makefile | 2 +- README.md | 2 +- src/circulationfile.ml | 2 +- src/ftest.ml | 61 +++++++++++++++++++++--------------------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 01ab017..fea1ef9 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 69f764e..64e6117 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/circulationfile.ml b/src/circulationfile.ml index 4152f29..c4a916b 100644 --- a/src/circulationfile.ml +++ b/src/circulationfile.ml @@ -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 diff --git a/src/ftest.ml b/src/ftest.ml index eb508d1..26b3afd 100644 --- a/src/ftest.ml +++ b/src/ftest.ml @@ -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 *) + ()