use multiobjective_search::{
Output, ZeroHeuristic, boa_star, boba_star, boba_star_parallel, boba_star_with_parallel,
};
use proptest::prelude::*;
use crate::check::{check, check_paths};
use crate::fixtures::{EdgeList, Problem, single_goal_problems};
fn costs(out: &Output<usize, [u32; 2]>) -> Vec<[u32; 2]> {
out.solutions.iter().map(|s| s.cost).collect()
}
fn larger() -> impl Strategy<Value = EdgeList<2>> {
let edge = (0..30_usize, 0..30_usize, prop::array::uniform(0..=20_u32));
prop::collection::vec(edge, 0..=120).prop_map(|edges| EdgeList { nodes: 30, edges })
}
proptest! {
#[test]
fn matches_sequential(p in single_goal_problems::<2>()) {
let goal = p.goals.iter().position(|&g| g).expect("one goal");
let sequential = costs(&boba_star(&p.graph, p.start, goal));
for _ in 0..4 {
let parallel = boba_star_parallel(&p.graph, p.start, goal);
check(&p, ¶llel)?;
prop_assert_eq!(&costs(¶llel), &sequential);
let blind = boba_star_with_parallel(&p.graph, p.start, goal, ZeroHeuristic, ZeroHeuristic);
check(&p, &blind)?;
}
}
#[test]
fn matches_boa_on_larger_graphs(graph in larger()) {
let expected = costs(&boa_star(&graph, ZeroHeuristic, 0, |v| *v == 29));
let problem = Problem { goals: (0..30).map(|v| v == 29).collect(), start: 0, graph };
for _ in 0..4 {
let out = boba_star_parallel(&problem.graph, 0, 29);
prop_assert_eq!(&costs(&out), &expected);
check_paths(&problem, &out)?;
}
}
}