Skip to content

Commit a984ff6

Browse files
Fix regression with supplying multiple matrices via cli
1 parent a462f81 commit a984ff6

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

vrp-cli/src/commands/solve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn get_solve_app() -> Command {
9292
.help("Specifies path to file with routing matrix")
9393
.short('m')
9494
.long(MATRIX_ARG_NAME)
95-
.num_args(1..)
95+
.action(ArgAction::Append)
9696
.required(false)
9797
)
9898
.arg(

vrp-cli/tests/unit/commands/solve_test.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::*;
22

33
const PRAGMATIC_PROBLEM_PATH: &str = "../examples/data/pragmatic/simple.basic.problem.json";
4+
const PRAGMATIC_MATRIX_PATH: &str = "../examples/data/pragmatic/simple.basic.matrix.json";
45
const SOLOMON_PROBLEM_PATH: &str = "../examples/data/scientific/solomon/C101.25.txt";
56
const LILIM_PROBLEM_PATH: &str = "../examples/data/scientific/lilim/LC101.txt";
67

@@ -16,7 +17,7 @@ impl Write for DummyWrite {
1617
}
1718
}
1819

19-
fn run_solve_with_out_writer(matches: &ArgMatches) {
20+
fn run_solve_without_writer(matches: &ArgMatches) {
2021
run_solve(matches, |_| BufWriter::new(Box::new(DummyWrite {}))).unwrap();
2122
}
2223

@@ -31,20 +32,41 @@ fn can_solve_pragmatic_problem_with_generation_limit() {
3132
let args = vec!["solve", "pragmatic", PRAGMATIC_PROBLEM_PATH, "--max-generations", "1"];
3233
let matches = get_solve_app().try_get_matches_from(args).unwrap();
3334

34-
run_solve_with_out_writer(&matches);
35+
run_solve_without_writer(&matches);
36+
}
37+
38+
#[test]
39+
fn can_solve_pragmatic_problem_with_matrix() {
40+
let args = vec!["solve", "pragmatic", PRAGMATIC_PROBLEM_PATH, "--matrix", PRAGMATIC_MATRIX_PATH];
41+
let matches = get_solve_app().try_get_matches_from(args).unwrap();
42+
43+
run_solve_without_writer(&matches);
44+
}
45+
46+
#[test]
47+
fn can_solve_pragmatic_problem_with_multiple_matrices() {
48+
const PRAGMATIC_BASICS_PATH: &str = "../examples/data/pragmatic/basics/";
49+
let problem_path = format!("{PRAGMATIC_BASICS_PATH}profiles.basic.problem.json");
50+
let car_matrix_path = format!("{PRAGMATIC_BASICS_PATH}profiles.basic.matrix.car.json");
51+
let truck_matrix_path = format!("{PRAGMATIC_BASICS_PATH}profiles.basic.matrix.truck.json");
52+
53+
let args = vec!["solve", "pragmatic", &problem_path, "--matrix", &car_matrix_path, "--matrix", &truck_matrix_path];
54+
let matches = get_solve_app().try_get_matches_from(args).unwrap();
55+
56+
run_solve_without_writer(&matches);
3557
}
3658

3759
#[test]
3860
fn can_solve_lilim_problem_with_multiple_limits() {
3961
let args = vec!["solve", "lilim", LILIM_PROBLEM_PATH, "--max-time", "300", "--max-generations", "1"];
4062
let matches = get_solve_app().try_get_matches_from(args).unwrap();
4163

42-
run_solve_with_out_writer(&matches);
64+
run_solve_without_writer(&matches);
4365
}
4466

4567
#[test]
4668
fn can_solve_solomon_problem_with_generation_limit() {
47-
run_solve_with_out_writer(&get_solomon_matches(&["--max-generations", "1"]));
69+
run_solve_without_writer(&get_solomon_matches(&["--max-generations", "1"]));
4870
}
4971

5072
#[test]

0 commit comments

Comments
 (0)