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