Skip to content

Commit

Permalink
feat(bool fn trait): began impl BooleanFunction for Expression with i…
Browse files Browse the repository at this point in the history
…ter methods
  • Loading branch information
AurumTheEnd committed Apr 25, 2024
1 parent 68c68f7 commit a030f42
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/expressions/traits/boolean_function.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use crate::expressions::iterators::{
ExpressionDomainIterator, ExpressionImageIterator, ExpressionRelationIterator,
ExpressionSupportIterator,
};
use crate::expressions::Expression;
use crate::traits::{BooleanFunction, BooleanValuation, Evaluate, GatherLiterals};
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Debug;

impl<T: Debug + Clone + Eq + Ord> BooleanFunction<T> for Expression<T> {
type DomainIterator = ExpressionDomainIterator;
type RangeIterator = ExpressionImageIterator<T>;
type RelationIterator = ExpressionRelationIterator<T>;
type SupportIterator = ExpressionSupportIterator<T>;

fn inputs(&self) -> BTreeSet<T> {
self.gather_literals()

Check warning on line 17 in src/expressions/traits/boolean_function.rs

View check run for this annotation

Codecov / codecov/patch

src/expressions/traits/boolean_function.rs#L16-L17

Added lines #L16 - L17 were not covered by tests
}

fn essential_inputs(&self) -> BTreeSet<T> {
self.inputs()

Check warning on line 21 in src/expressions/traits/boolean_function.rs

View check run for this annotation

Codecov / codecov/patch

src/expressions/traits/boolean_function.rs#L20-L21

Added lines #L20 - L21 were not covered by tests
.into_iter()
.filter(|input| {
let true_valuation = BTreeMap::from([(input.clone(), true)]);
let false_valuation = BTreeMap::from([(input.clone(), false)]);
self.evaluate(&true_valuation) != self.evaluate(&false_valuation)

Check warning on line 26 in src/expressions/traits/boolean_function.rs

View check run for this annotation

Codecov / codecov/patch

src/expressions/traits/boolean_function.rs#L23-L26

Added lines #L23 - L26 were not covered by tests
})
.collect()
}

fn domain(&self) -> Self::DomainIterator {
self.into()
}

fn image(&self) -> Self::RangeIterator {
self.into()
}

fn relation(&self) -> Self::RelationIterator {
self.into()
}

fn support(&self) -> Self::SupportIterator {
self.into()
}

fn restrict(&self, _valuation: &BooleanValuation<T>) -> Self {

Check warning on line 47 in src/expressions/traits/boolean_function.rs

View check run for this annotation

Codecov / codecov/patch

src/expressions/traits/boolean_function.rs#L47

Added line #L47 was not covered by tests
todo!()
}

fn substitute(&self, _mapping: BTreeMap<T, Self>) -> Self {

Check warning on line 51 in src/expressions/traits/boolean_function.rs

View check run for this annotation

Codecov / codecov/patch

src/expressions/traits/boolean_function.rs#L51

Added line #L51 was not covered by tests
todo!()
}

fn existential_quantification(&self, _variables: BTreeSet<T>) -> Self {

Check warning on line 55 in src/expressions/traits/boolean_function.rs

View check run for this annotation

Codecov / codecov/patch

src/expressions/traits/boolean_function.rs#L55

Added line #L55 was not covered by tests
todo!()
}

fn universal_quantification(&self, _variables: BTreeSet<T>) -> Self {

Check warning on line 59 in src/expressions/traits/boolean_function.rs

View check run for this annotation

Codecov / codecov/patch

src/expressions/traits/boolean_function.rs#L59

Added line #L59 was not covered by tests
todo!()
}

fn derivative(&self, _variables: BTreeSet<T>) -> Self {

Check warning on line 63 in src/expressions/traits/boolean_function.rs

View check run for this annotation

Codecov / codecov/patch

src/expressions/traits/boolean_function.rs#L63

Added line #L63 was not covered by tests
todo!()
}

fn is_equivalent(&self, _other: Self) -> bool {

Check warning on line 67 in src/expressions/traits/boolean_function.rs

View check run for this annotation

Codecov / codecov/patch

src/expressions/traits/boolean_function.rs#L67

Added line #L67 was not covered by tests
todo!()
}

fn is_implied_by(&self, _other: Self) -> bool {

Check warning on line 71 in src/expressions/traits/boolean_function.rs

View check run for this annotation

Codecov / codecov/patch

src/expressions/traits/boolean_function.rs#L71

Added line #L71 was not covered by tests
todo!()
}
}
1 change: 1 addition & 0 deletions src/expressions/traits/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod bit;
mod boolean_function;
mod display;
mod evaluate;
mod gather_literals;
Expand Down

0 comments on commit a030f42

Please sign in to comment.