Skip to content

Commit

Permalink
add unit tests for nested expressions
Browse files Browse the repository at this point in the history
closes #2
  • Loading branch information
rfuzzo committed Dec 8, 2023
1 parent 1547991 commit 64c8b68
Showing 1 changed file with 64 additions and 3 deletions.
67 changes: 64 additions & 3 deletions tests/unit_expression_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ mod unit_expressions_tests {
.map(|e| (*e).into())
.collect();

// check that a and b exist in my load order
let mut expr = ALL::new(vec![
Box::new(Atomic::from("a")),
Box::new(Atomic::from("b")),
]);
assert!(expr.eval(&mods));

// check that a and x exist in my load order
expr = ALL::new(vec![
Box::new(Atomic::from("a")),
Box::new(Atomic::from("x")),
]);
assert!(!expr.eval(&mods));
assert!(!expr.eval(&mods)); // should fail
}

#[test]
Expand All @@ -29,17 +31,19 @@ mod unit_expressions_tests {
.map(|e| (*e).into())
.collect();

// check that a or x exist in my load order
let mut expr = ANY::new(vec![
Box::new(Atomic::from("a")),
Box::new(Atomic::from("x")),
]);
assert!(expr.eval(&mods));

// check that x or y exist in my load order
expr = ANY::new(vec![
Box::new(Atomic::from("y")),
Box::new(Atomic::from("x")),
]);
assert!(!expr.eval(&mods));
assert!(!expr.eval(&mods)); // should fail
}

#[test]
Expand All @@ -49,10 +53,67 @@ mod unit_expressions_tests {
.map(|e| (*e).into())
.collect();

// check that x is not present in my load order
let mut expr = NOT::new(Box::new(Atomic::from("x")));
assert!(expr.eval(&mods));

// check that a is not present in my load order
expr = NOT::new(Box::new(Atomic::from("a")));
assert!(!expr.eval(&mods));
assert!(!expr.eval(&mods)); // should fail
}

#[test]
fn evaluate_nested() {
let mods: Vec<String> = ["a", "b", "c", "d", "e", "f", "g"]
.iter()
.map(|e| (*e).into())
.collect();

// check that (a and x) are not present in the modlist
{
let nested = ALL::new(vec![
Box::new(Atomic::from("a")),
Box::new(Atomic::from("x")),
]);
let expr = NOT::new(Box::new(nested));
assert!(expr.eval(&mods));
}
// check that (a and b) are not present in the modlist
{
let nested = ALL::new(vec![
Box::new(Atomic::from("a")),
Box::new(Atomic::from("b")),
]);
let expr = NOT::new(Box::new(nested));
assert!(!expr.eval(&mods)); // should fail
}

// check that (a and b) are present and that either (x and y) are not present
{
let nested1 = ALL::new(vec![
Box::new(Atomic::from("a")),
Box::new(Atomic::from("b")),
]);
let nested2 = NOT::new(Box::new(ANY::new(vec![
Box::new(Atomic::from("x")),
Box::new(Atomic::from("y")),
])));
let expr = ALL::new(vec![Box::new(nested1), Box::new(nested2)]);
assert!(expr.eval(&mods));
}

// check that (a and b) are present and that either (f and y) are present
{
let nested1 = ALL::new(vec![
Box::new(Atomic::from("a")),
Box::new(Atomic::from("b")),
]);
let nested2 = ANY::new(vec![
Box::new(Atomic::from("f")),
Box::new(Atomic::from("y")),
]);
let expr = ALL::new(vec![Box::new(nested1), Box::new(nested2)]);
assert!(expr.eval(&mods));
}
}
}

0 comments on commit 64c8b68

Please sign in to comment.