-
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.
- Loading branch information
Showing
7 changed files
with
79 additions
and
12 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
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()); | ||
} | ||
} | ||
} |
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