use crate::{
goals::{map_2, Goal},
Unify, Value,
};
use std::ops::{Div, Mul};
pub fn mul<T, A, B, C>(a: A, b: B, c: C) -> impl Goal
where
T: Unify + Mul<Output = T> + Div<Output = T> + Copy,
A: Into<Value<T>>,
B: Into<Value<T>>,
C: Into<Value<T>>,
{
map_2(a, b, c, |a, b| *a * *b, |a, c| *c / *a, |b, c| *c / *b)
}
#[cfg(test)]
mod tests {
use super::mul;
use crate::{goal_vec, unify, LVar};
#[test]
fn succeeds() {
let (x, y, z) = (LVar::new(), LVar::new(), LVar::new());
let goals = goal_vec![unify(x, 2), unify(y, 3), unify(z, 6), mul(x, y, z)];
goals.assert_permutations_resolve_to(&(x, y, z), vec![(2, 3, 6)]);
}
#[test]
fn fails() {
let (x, y, z) = (LVar::new(), LVar::new(), LVar::new());
let goals = goal_vec![unify(x, 2), unify(y, 3), unify(z, 5), mul(x, y, z)];
goals.assert_permutations_resolve_to(&(x, y, z), vec![]);
}
}