mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
make tests compile (they fail on a panic!
This commit is contained in:
parent
e899ca289a
commit
bdd9df0960
2 changed files with 33 additions and 30 deletions
|
@ -14,19 +14,19 @@ pub enum Bool {
|
|||
use self::Bool::*;
|
||||
|
||||
// TODO add inline pragma
|
||||
fn not(nested: Bool) -> Bool {
|
||||
pub fn not(nested: Bool) -> Bool {
|
||||
Not(Box::new(nested))
|
||||
}
|
||||
|
||||
fn and(left: Bool, right: Bool) -> Bool {
|
||||
pub fn and(left: Bool, right: Bool) -> Bool {
|
||||
And(Box::new(left), Box::new(right))
|
||||
}
|
||||
|
||||
fn or(left: Bool, right: Bool) -> Bool {
|
||||
pub fn or(left: Bool, right: Bool) -> Bool {
|
||||
Or(Box::new(left), Box::new(right))
|
||||
}
|
||||
|
||||
fn any<I>(mut it: I) -> Bool
|
||||
pub fn any<I>(mut it: I) -> Bool
|
||||
where
|
||||
I: Iterator<Item = Bool>,
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn all(terms: Product<Bool>) -> Bool {
|
||||
pub fn all(terms: Product<Bool>) -> Bool {
|
||||
let mut it = terms.into_iter();
|
||||
|
||||
if let Some(first) = it.next() {
|
||||
|
@ -105,6 +105,19 @@ impl Bool {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO add inline pragma
|
||||
pub fn not(nested: Bool) -> Bool {
|
||||
not(nested)
|
||||
}
|
||||
|
||||
pub fn and(left: Bool, right: Bool) -> Bool {
|
||||
and(left, right)
|
||||
}
|
||||
|
||||
pub fn or(left: Bool, right: Bool) -> Bool {
|
||||
or(left, right)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn simplify(term: Bool) -> Bool {
|
||||
|
@ -354,11 +367,11 @@ type Pos = Product<Sum<Bool>>;
|
|||
type Sop = Sum<Product<Bool>>;
|
||||
|
||||
fn term_to_pos(term: Bool) -> Pos {
|
||||
ImSet::default()
|
||||
panic!("TODO term_to_pos");
|
||||
}
|
||||
|
||||
fn term_to_sop(term: Bool) -> Sop {
|
||||
ImSet::default()
|
||||
panic!("TODO term_to_sop");
|
||||
}
|
||||
|
||||
fn normalize_pos(pos: Pos) -> Pos {
|
||||
|
@ -443,6 +456,7 @@ fn normalize_conj(mut product: Product<Bool>) -> Product<Bool> {
|
|||
product
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
fn cnf(term: &Bool) -> Bool {
|
||||
match term {
|
||||
|
@ -486,3 +500,4 @@ fn nnf(term: &Bool) -> Bool {
|
|||
Variable(current) => Variable(*current),
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -10,11 +10,11 @@ mod helpers;
|
|||
mod test_boolean_algebra {
|
||||
use roc::subs::VarStore;
|
||||
use roc::uniqueness::boolean_algebra;
|
||||
use roc::uniqueness::boolean_algebra::BooleanAlgebra::{self, *};
|
||||
use roc::uniqueness::boolean_algebra::Bool::{self, *};
|
||||
|
||||
// HELPERS
|
||||
fn simplify_eq(mut a: BooleanAlgebra, mut b: BooleanAlgebra) {
|
||||
assert_eq!(a.simplify(), b.simplify());
|
||||
fn simplify_eq(a: Bool, b: Bool) {
|
||||
assert_eq!(boolean_algebra::simplify(a), boolean_algebra::simplify(b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -22,10 +22,7 @@ mod test_boolean_algebra {
|
|||
let var_store = VarStore::default();
|
||||
let var = var_store.fresh();
|
||||
|
||||
simplify_eq(
|
||||
Disjunction(Box::new(Ground(true)), Box::new(Variable(var))),
|
||||
Ground(true),
|
||||
);
|
||||
simplify_eq(Bool::or(One, Variable(var)), One);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -33,10 +30,7 @@ mod test_boolean_algebra {
|
|||
let var_store = VarStore::default();
|
||||
let var = var_store.fresh();
|
||||
|
||||
simplify_eq(
|
||||
Disjunction(Box::new(Ground(false)), Box::new(Variable(var))),
|
||||
Variable(var),
|
||||
);
|
||||
simplify_eq(Bool::or(Zero, Variable(var)), Variable(var));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -44,10 +38,7 @@ mod test_boolean_algebra {
|
|||
let var_store = VarStore::default();
|
||||
let var = var_store.fresh();
|
||||
|
||||
simplify_eq(
|
||||
Conjunction(Box::new(Ground(false)), Box::new(Variable(var))),
|
||||
Ground(false),
|
||||
);
|
||||
simplify_eq(Bool::and(Zero, Variable(var)), Zero);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -55,10 +46,10 @@ mod test_boolean_algebra {
|
|||
let var_store = VarStore::default();
|
||||
let var = var_store.fresh();
|
||||
|
||||
let result = boolean_algebra::unify(&Variable(var), &Ground(true));
|
||||
let result = boolean_algebra::try_unify(Variable(var), One);
|
||||
|
||||
if let Some(sub) = result {
|
||||
assert_eq!(Some(&Ground(false)), sub.get(var));
|
||||
assert_eq!(Some(&Zero), sub.get(&var));
|
||||
} else {
|
||||
panic!("result is None");
|
||||
}
|
||||
|
@ -70,14 +61,11 @@ mod test_boolean_algebra {
|
|||
let a = var_store.fresh();
|
||||
let b = var_store.fresh();
|
||||
|
||||
let result = boolean_algebra::unify(
|
||||
&Disjunction(Box::new(Variable(a)), Box::new(Variable(b))),
|
||||
&Ground(true),
|
||||
);
|
||||
let result = boolean_algebra::try_unify(Bool::or(Variable(a), Variable(b)), One);
|
||||
|
||||
if let Some(sub) = result {
|
||||
assert_eq!(Some(&Variable(b)), sub.get(a));
|
||||
assert_eq!(Some(&Ground(false)), sub.get(b));
|
||||
assert_eq!(Some(&Variable(b)), sub.get(&a));
|
||||
assert_eq!(Some(&Zero), sub.get(&b));
|
||||
} else {
|
||||
panic!("result is None");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue