pub(super) mod multikeymultivaluemap;
use crate::Domain;
use crate::Goal;
use crate::Query;
use crate::ReifyIn;
use crate::State;
use itertools::Itertools;
use std::fmt::Debug;
pub(crate) fn all_permutations<'a, D>(
goals: Vec<Goal<'a, D>>,
) -> impl Iterator<Item = Vec<Goal<'a, D>>> + 'a
where
D: Domain<'a> + 'a,
{
let goals_len = goals.len();
goals.into_iter().permutations(goals_len)
}
pub(crate) fn goals_resolve_to<'a, D, Q>(goals: &[Goal<'a, D>], query: Q) -> Vec<Q::Reified>
where
D: Domain<'a> + 'a,
Q: ReifyIn<'a, D> + 'a,
{
let goal = Goal::all(goals.to_owned());
goal_resolves_to(goal, query)
}
pub(crate) fn goal_resolves_to<'a, D, Q>(goal: Goal<'a, D>, query: Q) -> Vec<Q::Reified>
where
D: Domain<'a> + 'a,
Q: ReifyIn<'a, D> + 'a,
{
let state = goal.apply(State::new());
state.query(query).collect()
}
pub fn assert_permutations_resolve_to<'a, D, Q>(
goals: Vec<Goal<'a, D>>,
query: Q,
expected: Vec<Q::Reified>,
) where
D: Domain<'a> + Debug + 'a,
Q: ReifyIn<'a, D> + Clone + 'a,
Q::Reified: PartialEq + Clone + Debug,
{
for permutation in all_permutations(goals) {
let results: Vec<Q::Reified> = goals_resolve_to(&permutation, query.clone());
if !expected
.clone()
.into_iter()
.permutations(expected.len())
.any(|e: Vec<Q::Reified>| e == results)
{
dbg!(permutation, results, expected);
panic!("The permutation of the goals printed above failed!");
}
}
}