pub const IDENTITY: &str = "equals";
pub const BUILTIN_ARITHMETIC: &[&str] = &["product", "sum", "quotient"];
pub const NUMERIC_COMPARISONS: &[&str] = &["greater", "less", "num_equal"];
pub const REFERENCE_EXTERNAL_COMPUTE: &[&str] = &["exponential", "logarithm"];
pub fn is_identity(rel: &str) -> bool {
rel == IDENTITY
}
pub fn is_builtin_arithmetic(rel: &str) -> bool {
BUILTIN_ARITHMETIC.contains(&rel)
}
pub fn is_numeric_comparison(rel: &str) -> bool {
NUMERIC_COMPARISONS.contains(&rel)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn helper_membership() {
assert!(is_identity("equals"));
assert!(!is_identity("greater"));
for r in BUILTIN_ARITHMETIC {
assert!(is_builtin_arithmetic(r));
assert!(!is_numeric_comparison(r));
}
for r in NUMERIC_COMPARISONS {
assert!(is_numeric_comparison(r));
assert!(!is_builtin_arithmetic(r));
}
}
#[test]
fn python_backend_mirrors_the_compute_names() {
let src = std::fs::read_to_string(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../python/nibli_backend.py"
))
.expect("python/nibli_backend.py is committed");
for name in BUILTIN_ARITHMETIC.iter().chain(REFERENCE_EXTERNAL_COMPUTE) {
assert!(
src.contains(&format!("\"{name}\"")) || src.contains(&format!("'{name}'")),
"python backend HANDLERS must serve {name:?} (the reference \
mirror of the compute-name sets)"
);
}
}
}