use super::*;
#[test]
fn test_unknown_gismu_defaults_to_arity_2() {
let predicates = vec![Predicate::Root("xyzzy".into())];
let arguments = vec![Argument::Pronoun(Pronoun::Me)];
let proposition = Proposition {
relation: 0,
terms: vec![0],
x1_present: true,
negated: false,
tense: None,
deontic: None,
};
let (form, compiler) = compile_one(predicates, arguments, proposition);
assert!(
matches!(&form, IrForm::Exists(_, _)),
"expected Exists, got {:?}",
form
);
assert!(
has_pred(&form, "xyzzy", &compiler),
"expected xyzzy type predicate"
);
assert!(
has_pred(&form, "xyzzy_x1", &compiler),
"expected xyzzy_x1 role"
);
assert!(
has_pred(&form, "xyzzy_x2", &compiler),
"expected xyzzy_x2 role"
);
assert!(
!has_pred(&form, "xyzzy_x3", &compiler),
"unknown word should default to arity 2, but found xyzzy_x3"
);
}
#[test]
fn test_fresh_vars_are_unique() {
let mut compiler = SemanticCompiler::new();
let v1 = compiler.fresh_var();
let v2 = compiler.fresh_var();
let v3 = compiler.fresh_var();
assert_ne!(v1, v2);
assert_ne!(v2, v3);
assert_ne!(v1, v3);
assert_eq!(compiler.interner.resolve(&v1), "_v0");
assert_eq!(compiler.interner.resolve(&v2), "_v1");
assert_eq!(compiler.interner.resolve(&v3), "_v2");
}
#[test]
fn test_inject_variable_into_and() {
let mut compiler = SemanticCompiler::new();
let rel1 = compiler.interner.get_or_intern("dog");
let rel2 = compiler.interner.get_or_intern("big");
let var = compiler.interner.get_or_intern("_v0");
let form = IrForm::And(
Box::new(IrForm::Predicate {
relation: rel1,
args: vec![IrTerm::Unspecified],
}),
Box::new(IrForm::Predicate {
relation: rel2,
args: vec![IrTerm::Unspecified],
}),
);
let injected = SemanticCompiler::inject_variable(form, var, &compiler.interner);
match injected {
IrForm::And(left, right) => {
match left.as_ref() {
IrForm::Predicate { args, .. } => {
assert!(matches!(args[0], IrTerm::Variable(_)));
}
other => panic!("expected Predicate, got {:?}", other),
}
match right.as_ref() {
IrForm::Predicate { args, .. } => {
assert!(matches!(args[0], IrTerm::Variable(_)));
}
other => panic!("expected Predicate, got {:?}", other),
}
}
other => panic!("expected And, got {:?}", other),
}
}