Fix unit tests

This commit is contained in:
Patrick Lühne 2020-05-03 18:05:45 +02:00
parent 8d474fa489
commit 30c28c2bc4
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
1 changed files with 24 additions and 24 deletions

View File

@ -22,7 +22,6 @@ enum LogicalConnective
Or, Or,
} }
// TODO: rename to logic infix connective
impl LogicalConnective impl LogicalConnective
{ {
fn level(&self) -> usize fn level(&self) -> usize
@ -184,7 +183,8 @@ impl<'i> FormulaStr<'i>
// Parse logical infix connectives // Parse logical infix connectives
if let Some(top_level_logical_connective) = self.top_level_logical_connective()? if let Some(top_level_logical_connective) = self.top_level_logical_connective()?
{ {
println!("{} parsing “{:?}” infix formula", indentation, top_level_logical_connective); println!("{} parsing “{:?}” logical connective", indentation,
top_level_logical_connective);
// Parse arguments of n-ary logical infix connectives // Parse arguments of n-ary logical infix connectives
let arguments_n_ary = || let arguments_n_ary = ||
@ -466,59 +466,59 @@ mod tests
use super::*; use super::*;
#[test] #[test]
fn tokenize_formula_infix_operators() fn tokenize_formula_logical_connectives()
{ {
let f = FormulaStr::new("((forall X exists Y (p(X) -> q(Y)) and false) or p) -> false"); let f = FormulaStr::new("((forall X exists Y (p(X) -> q(Y)) and false) or p) -> false");
assert_eq!(f.top_level_infix_operator().unwrap(), assert_eq!(f.top_level_logical_connective().unwrap(),
Some(FormulaInfixOperator::ImpliesLeftToRight)); Some(LogicalConnective::ImpliesLeftToRight));
let mut i = f.iter_infix_operators(); let mut i = f.logical_connectives();
assert_eq!(i.next().unwrap().unwrap().2, FormulaInfixOperator::ImpliesLeftToRight); assert_eq!(i.next().unwrap().unwrap().1, LogicalConnective::ImpliesLeftToRight);
assert!(i.next().is_none()); assert!(i.next().is_none());
let f = FormulaStr::new("forall X exists Y (p(X) -> q(Y)) and false or p -> false"); let f = FormulaStr::new("forall X exists Y (p(X) -> q(Y)) and false or p -> false");
assert_eq!(f.top_level_infix_operator().unwrap(), assert_eq!(f.top_level_logical_connective().unwrap(),
Some(FormulaInfixOperator::ImpliesLeftToRight)); Some(LogicalConnective::ImpliesLeftToRight));
let mut i = f.iter_infix_operators(); let mut i = f.logical_connectives();
assert_eq!(i.next().unwrap().unwrap().2, FormulaInfixOperator::And); assert_eq!(i.next().unwrap().unwrap().1, LogicalConnective::And);
assert_eq!(i.next().unwrap().unwrap().2, FormulaInfixOperator::Or); assert_eq!(i.next().unwrap().unwrap().1, LogicalConnective::Or);
assert_eq!(i.next().unwrap().unwrap().2, FormulaInfixOperator::ImpliesLeftToRight); assert_eq!(i.next().unwrap().unwrap().1, LogicalConnective::ImpliesLeftToRight);
assert!(i.next().is_none()); assert!(i.next().is_none());
let f = FormulaStr::new(" p -> forall X exists Y (p(X) -> q(Y)) and false or p -> false "); let f = FormulaStr::new(" p -> forall X exists Y (p(X) -> q(Y)) and false or p -> false ");
assert_eq!(f.top_level_infix_operator().unwrap(), assert_eq!(f.top_level_logical_connective().unwrap(),
Some(FormulaInfixOperator::ImpliesLeftToRight)); Some(LogicalConnective::ImpliesLeftToRight));
let mut i = f.split_at_infix_operator(FormulaInfixOperator::ImpliesLeftToRight); let mut i = f.split_at_logical_connective(LogicalConnective::ImpliesLeftToRight);
assert_eq!(i.next().unwrap().unwrap(), "p"); assert_eq!(i.next().unwrap().unwrap(), "p");
assert_eq!(i.next().unwrap().unwrap(), "forall X exists Y (p(X) -> q(Y)) and false or p"); assert_eq!(i.next().unwrap().unwrap(), "forall X exists Y (p(X) -> q(Y)) and false or p");
assert_eq!(i.next().unwrap().unwrap(), "false"); assert_eq!(i.next().unwrap().unwrap(), "false");
assert!(i.next().is_none()); assert!(i.next().is_none());
let f = FormulaStr::new(" p -> forall X exists Y (p(X) -> q(Y)) and false or p -> false "); let f = FormulaStr::new(" p -> forall X exists Y (p(X) -> q(Y)) and false or p -> false ");
assert_eq!(f.top_level_infix_operator().unwrap(), assert_eq!(f.top_level_logical_connective().unwrap(),
Some(FormulaInfixOperator::ImpliesLeftToRight)); Some(LogicalConnective::ImpliesLeftToRight));
let mut i = f.split_at_infix_operator(FormulaInfixOperator::And); let mut i = f.split_at_logical_connective(LogicalConnective::And);
assert_eq!(i.next().unwrap().unwrap(), "p -> forall X exists Y (p(X) -> q(Y))"); assert_eq!(i.next().unwrap().unwrap(), "p -> forall X exists Y (p(X) -> q(Y))");
assert_eq!(i.next().unwrap().unwrap(), "false or p -> false"); assert_eq!(i.next().unwrap().unwrap(), "false or p -> false");
assert!(i.next().is_none()); assert!(i.next().is_none());
let f = FormulaStr::new(" p and forall X exists Y (p(X) -> q(Y)) and false or p or false "); let f = FormulaStr::new(" p and forall X exists Y (p(X) -> q(Y)) and false or p or false ");
assert_eq!(f.top_level_infix_operator().unwrap(), Some(FormulaInfixOperator::Or)); assert_eq!(f.top_level_logical_connective().unwrap(), Some(LogicalConnective::Or));
let mut i = f.split_at_infix_operator(FormulaInfixOperator::Or); let mut i = f.split_at_logical_connective(LogicalConnective::Or);
assert_eq!(i.next().unwrap().unwrap(), "p and forall X exists Y (p(X) -> q(Y)) and false"); assert_eq!(i.next().unwrap().unwrap(), "p and forall X exists Y (p(X) -> q(Y)) and false");
assert_eq!(i.next().unwrap().unwrap(), "p"); assert_eq!(i.next().unwrap().unwrap(), "p");
assert_eq!(i.next().unwrap().unwrap(), "false"); assert_eq!(i.next().unwrap().unwrap(), "false");
assert!(i.next().is_none()); assert!(i.next().is_none());
let f = FormulaStr::new(" (p and q) "); let f = FormulaStr::new(" (p and q) ");
assert!(f.top_level_infix_operator().unwrap().is_none()); assert!(f.top_level_logical_connective().unwrap().is_none());
let mut i = f.split_at_infix_operator(FormulaInfixOperator::And); let mut i = f.split_at_logical_connective(LogicalConnective::And);
assert_eq!(i.next().unwrap().unwrap(), "(p and q)"); assert_eq!(i.next().unwrap().unwrap(), "(p and q)");
assert!(i.next().is_none()); assert!(i.next().is_none());
assert!(FormulaStr::new(" a -> b -> c ").parse(0).is_ok()); assert!(FormulaStr::new(" a -> b -> c ").parse(0).is_ok());
assert!(FormulaStr::new(" a -> b <- c ").parse(0).is_err()); assert!(FormulaStr::new(" a -> b <- c ").parse(0).is_err());
assert!(!FormulaStr::new(" p -> forall X exists Y (p(X) -> q(Y)) and false or p -> false ") assert!(FormulaStr::new(" p -> forall X exists Y (p(X) -> q(Y)) and false or p -> false ")
.parse(0).is_ok()); .parse(0).is_ok());
} }
} }