From ff45d68cd136c6250e2ad16f9aced1b9a3cf094d Mon Sep 17 00:00:00 2001 From: AurumTheEnd <47597303+aurumtheend@users.noreply.github.com> Date: Mon, 13 May 2024 23:56:36 +0200 Subject: [PATCH] feat(test): bdd.relation --- src/bdd/traits/boolean_function.rs | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/bdd/traits/boolean_function.rs b/src/bdd/traits/boolean_function.rs index fa6e0d9..b602543 100644 --- a/src/bdd/traits/boolean_function.rs +++ b/src/bdd/traits/boolean_function.rs @@ -258,6 +258,47 @@ mod tests { assert_eq!(actual, expected); } + #[test] + fn test_relation_ok() { + let input = Bdd::try_from(var("d") & var("b") | var("a")).expect("Should not panic here"); + + let mut actual = input.relation(); + let expected = vec![ + vec![false, false, false], + vec![false, false, true], + vec![false, true, false], + vec![false, true, true], + vec![true, false, false], + vec![true, false, true], + vec![true, true, false], + vec![true, true, true], + ] + .into_iter() + .map(|point| { + Some(( + point.clone(), + input.evaluate(&BTreeMap::from_iter(vec![ + ("a".to_string(), point[0]), + ("b".to_string(), point[1]), + ("d".to_string(), point[2]), + ])), + )) + }) + .collect::>(); + + assert_eq!(actual.next(), expected[0]); + assert_eq!(actual.next(), expected[1]); + assert_eq!(actual.next(), expected[2]); + assert_eq!(actual.next(), expected[3]); + assert_eq!(actual.next(), expected[4]); + assert_eq!(actual.next(), expected[5]); + assert_eq!(actual.next(), expected[6]); + assert_eq!(actual.next(), expected[7]); + + assert_eq!(actual.next(), None); + assert_eq!(actual.next(), None); + } + #[test] fn test_restrict_ok() { let input = Bdd::try_from((var("a") | var("b")) & var("c")).expect("Should not panic here");