Skip to content

Commit

Permalink
Fix regression with supplying multiple matrices via cli
Browse files Browse the repository at this point in the history
  • Loading branch information
reinterpretcat committed Nov 16, 2024
1 parent a462f81 commit a984ff6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion vrp-cli/src/commands/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn get_solve_app() -> Command {
.help("Specifies path to file with routing matrix")
.short('m')
.long(MATRIX_ARG_NAME)
.num_args(1..)
.action(ArgAction::Append)
.required(false)
)
.arg(
Expand Down
30 changes: 26 additions & 4 deletions vrp-cli/tests/unit/commands/solve_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;

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

Expand All @@ -16,7 +17,7 @@ impl Write for DummyWrite {
}
}

fn run_solve_with_out_writer(matches: &ArgMatches) {
fn run_solve_without_writer(matches: &ArgMatches) {
run_solve(matches, |_| BufWriter::new(Box::new(DummyWrite {}))).unwrap();
}

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

run_solve_with_out_writer(&matches);
run_solve_without_writer(&matches);
}

#[test]
fn can_solve_pragmatic_problem_with_matrix() {
let args = vec!["solve", "pragmatic", PRAGMATIC_PROBLEM_PATH, "--matrix", PRAGMATIC_MATRIX_PATH];
let matches = get_solve_app().try_get_matches_from(args).unwrap();

run_solve_without_writer(&matches);
}

#[test]
fn can_solve_pragmatic_problem_with_multiple_matrices() {
const PRAGMATIC_BASICS_PATH: &str = "../examples/data/pragmatic/basics/";
let problem_path = format!("{PRAGMATIC_BASICS_PATH}profiles.basic.problem.json");
let car_matrix_path = format!("{PRAGMATIC_BASICS_PATH}profiles.basic.matrix.car.json");
let truck_matrix_path = format!("{PRAGMATIC_BASICS_PATH}profiles.basic.matrix.truck.json");

let args = vec!["solve", "pragmatic", &problem_path, "--matrix", &car_matrix_path, "--matrix", &truck_matrix_path];
let matches = get_solve_app().try_get_matches_from(args).unwrap();

run_solve_without_writer(&matches);
}

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

run_solve_with_out_writer(&matches);
run_solve_without_writer(&matches);
}

#[test]
fn can_solve_solomon_problem_with_generation_limit() {
run_solve_with_out_writer(&get_solomon_matches(&["--max-generations", "1"]));
run_solve_without_writer(&get_solomon_matches(&["--max-generations", "1"]));
}

#[test]
Expand Down

0 comments on commit a984ff6

Please sign in to comment.