-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from tomoikey/v0.5.18
Release V0.5.18
- Loading branch information
Showing
14 changed files
with
667 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use crate::rule::composer::Not; | ||
use crate::rule::{ForAllRule, Rule}; | ||
use crate::Refined; | ||
use std::collections::{HashMap, HashSet, VecDeque}; | ||
|
||
/// A type that holds a value satisfying the `NothingRule` | ||
pub type Nothing<RULE, ITERABLE> = Refined<NothingRule<RULE, ITERABLE>>; | ||
|
||
/// A type that holds a `Vec` value satisfying the `NothingRule` | ||
pub type NothingVec<RULE> = Refined<NothingVecRule<RULE>>; | ||
|
||
/// A type that holds a `VecDeque` value satisfying the `NothingRule` | ||
pub type NothingVecDeque<RULE> = Refined<NothingVecDequeRule<RULE>>; | ||
|
||
/// A type that holds a `HashSet` value satisfying the `NothingRule` | ||
pub type NothingHashSet<RULE> = Refined<NothingHashSetRule<RULE>>; | ||
|
||
/// A type that holds a `HashMap` value satisfying the `NothingRule` | ||
pub type NothingHashMap<K, RULE> = Refined<NothingHashMapRule<K, RULE>>; | ||
|
||
/// A type that holds a `String` value satisfying the `NothingRule` | ||
pub type NothingString<RULE> = Refined<NothingStringRule<RULE>>; | ||
|
||
/// Rule where no data in the collection satisfies the condition | ||
pub type NothingRule<RULE, ITERABLE> = ForAllRule<Not<RULE>, ITERABLE>; | ||
|
||
/// Rule where no data in the `Vec` satisfies the condition | ||
pub type NothingVecRule<RULE> = NothingRule<RULE, Vec<<RULE as Rule>::Item>>; | ||
|
||
/// Rule where no data in the `VecDeque` satisfies the condition | ||
pub type NothingVecDequeRule<RULE> = NothingRule<RULE, VecDeque<<RULE as Rule>::Item>>; | ||
|
||
/// Rule where no data in the `HashSet` satisfies the condition | ||
pub type NothingHashSetRule<RULE> = NothingRule<RULE, HashSet<<RULE as Rule>::Item>>; | ||
|
||
/// Rule where no data in the `HashMap` satisfies the condition | ||
pub type NothingHashMapRule<K, RULE> = NothingRule<RULE, HashMap<K, <RULE as Rule>::Item>>; | ||
|
||
/// Rule where no data in the `String` satisfies the condition | ||
pub type NothingStringRule<RULE> = NothingRule<RULE, String>; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::result::Error; | ||
use crate::rule::{NonEmptyStringRule, NothingVec}; | ||
|
||
#[test] | ||
fn nothing_valid() -> Result<(), Error<Vec<String>>> { | ||
let table = vec![vec![], vec!["".to_string()]]; | ||
|
||
for value in table { | ||
let nothing = NothingVec::<NonEmptyStringRule>::new(value.clone())?; | ||
assert_eq!(nothing.into_value(), value); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn nothing_invalid() -> anyhow::Result<()> { | ||
let table = vec![ | ||
vec!["good morning".to_string(), "hello".to_string()], | ||
vec!["good morning".to_string()], | ||
]; | ||
|
||
for value in table { | ||
let nothing_result = NothingVec::<NonEmptyStringRule>::new(value.clone()); | ||
assert!(nothing_result.is_err()); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
mod and; | ||
mod equiv; | ||
mod if_else; | ||
mod imply; | ||
mod nand; | ||
mod nor; | ||
mod not; | ||
mod or; | ||
mod xor; | ||
|
||
pub use and::And; | ||
pub use equiv::Equiv; | ||
pub use if_else::IfElse; | ||
pub use imply::{If, Imply}; | ||
pub use nand::Nand; | ||
pub use nor::Nor; | ||
pub use not::Not; | ||
pub use or::Or; | ||
pub use xor::Xor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::rule::composer::imply::Imply; | ||
use crate::And; | ||
|
||
/// This is a type that represents logical equivalence in logic. | ||
/// | ||
/// # Example | ||
/// ```rust | ||
/// use refined_type::rule::composer::Equiv; | ||
/// use refined_type::rule::{EvenRuleI8, GreaterEqualRuleI8, Rule}; | ||
/// | ||
/// type Target = Equiv<GreaterEqualRuleI8<10>, EvenRuleI8>; | ||
/// | ||
/// for value in vec![1, 10] { | ||
/// assert!(Target::validate(value).is_ok()); | ||
/// } | ||
/// | ||
/// for value in vec![2, 4] { | ||
/// assert!(Target::validate(value).is_err()); | ||
/// } | ||
/// ``` | ||
pub type Equiv<RULE1, RULE2> = And![Imply<RULE1, RULE2>, Imply<RULE2, RULE1>]; | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::rule::composer::Equiv; | ||
use crate::rule::{EvenRuleI8, GreaterEqualRuleI8, Rule}; | ||
|
||
type Target = Equiv<GreaterEqualRuleI8<10>, EvenRuleI8>; | ||
|
||
#[test] | ||
fn test_rule_binder_ok() { | ||
let table = vec![1, 10]; | ||
|
||
for value in table { | ||
assert!(Target::validate(value).is_ok()); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_rule_binder_err() { | ||
let table = vec![2, 4]; | ||
|
||
for value in table { | ||
assert!(Target::validate(value).is_err()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use crate::rule::composer::Not; | ||
use crate::{And, Or}; | ||
|
||
/// This is a type that represents logical if-else in logic. | ||
/// # Example | ||
/// ```rust | ||
/// use refined_type::rule::composer::IfElse; | ||
/// | ||
/// use refined_type::rule::{EvenRuleI8, GreaterEqualRuleI8, OddRuleI8, Rule}; | ||
/// | ||
/// type Target = IfElse<GreaterEqualRuleI8<10>, EvenRuleI8, OddRuleI8>; | ||
/// | ||
/// for value in vec![1, 10] { | ||
/// assert!(Target::validate(value).is_ok()); | ||
/// } | ||
/// | ||
/// for value in vec![2, 11] { | ||
/// assert!(Target::validate(value).is_err()); | ||
/// } | ||
/// ``` | ||
pub type IfElse<CONDITION, THEN, ELSE> = Or![And![CONDITION, THEN], And![Not<CONDITION>, ELSE]]; | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::rule::composer::IfElse; | ||
use crate::rule::{EvenRuleI8, GreaterEqualRuleI8, OddRuleI8, Rule}; | ||
|
||
type Target = IfElse<GreaterEqualRuleI8<10>, EvenRuleI8, OddRuleI8>; | ||
|
||
#[test] | ||
fn test_rule_binder_ok() { | ||
let table = vec![1, 10]; | ||
|
||
for value in table { | ||
assert!(Target::validate(value).is_ok()); | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_rule_binder_err() { | ||
let table = vec![2, 11]; | ||
|
||
for value in table { | ||
assert!(Target::validate(value).is_err()); | ||
} | ||
} | ||
} |
Oops, something went wrong.