Skip to content

Commit cb19f53

Browse files
committed
implement CountGreaterEqual
1 parent 9a2a813 commit cb19f53

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

src/rule/collection/count.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
mod equal;
2+
mod grater_equal;
23
mod greater;
34
mod less;
45

56
pub use equal::*;
7+
pub use grater_equal::*;
68
pub use greater::*;
79
pub use less::*;
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
use crate::rule::{CountEqualRule, CountGreaterRule};
2+
use crate::{Or, Refined};
3+
4+
/// A type that holds a value satisfying the `GreaterEqualRule`
5+
pub type CountGreaterEqual<const N: usize, RULE, ITERABLE> =
6+
Refined<CountGreaterEqualRule<N, RULE, ITERABLE>>;
7+
8+
/// A type that holds a `Vec` value satisfying the `CountGreaterEqualRule`
9+
pub type CountGreaterEqualVec<const N: usize, RULE> = Refined<CountGreaterEqualVecRule<N, RULE>>;
10+
11+
/// A type that holds a `VecDeque` value satisfying the `CountGreaterEqualRule`
12+
pub type CountGreaterEqualVecDeque<const N: usize, RULE> =
13+
Refined<CountGreaterEqualVecDequeRule<N, RULE>>;
14+
15+
/// A type that holds a `HashMap` value satisfying the `CountGreaterEqualRule`
16+
pub type CountGreaterEqualHashMap<const N: usize, RULE, K> =
17+
Refined<CountGreaterEqualHashMapRule<N, RULE, K>>;
18+
19+
/// A type that holds a `HashSet` value satisfying the `CountGreaterEqualRule`
20+
pub type CountGreaterEqualHashSet<const N: usize, RULE, K> =
21+
Refined<CountGreaterEqualHashSetRule<N, RULE, K>>;
22+
23+
/// A type that holds a `String` value satisfying the `CountGreaterEqualRule`
24+
pub type CountGreaterEqualString<const N: usize, RULE> =
25+
Refined<CountGreaterEqualStringRule<N, RULE>>;
26+
27+
/// A type that holds a `&'a str` value satisfying the `CountGreaterEqualRule`
28+
pub type CountGreaterEqualStr<'a, const N: usize, RULE> =
29+
Refined<CountGreaterEqualStrRule<'a, N, RULE>>;
30+
31+
/// Rule where the count of items in the collection that satisfy the condition is greater than or equal to `N`.
32+
pub type CountGreaterEqualRule<const N: usize, RULE, ITERABLE> =
33+
Or![CountGreaterRule<N, RULE, ITERABLE>, CountEqualRule<N, RULE, ITERABLE>];
34+
35+
/// Rule where the count of items in the `Vec` that satisfy the condition is greater than or equal to `N`.
36+
pub type CountGreaterEqualVecRule<const N: usize, RULE> =
37+
CountGreaterEqualRule<N, RULE, Vec<<RULE as crate::rule::Rule>::Item>>;
38+
39+
/// Rule where the count of items in the `VecDeque` that satisfy the condition is greater than or equal to `N`.
40+
pub type CountGreaterEqualVecDequeRule<const N: usize, RULE> =
41+
CountGreaterEqualRule<N, RULE, std::collections::VecDeque<<RULE as crate::rule::Rule>::Item>>;
42+
43+
/// Rule where the count of items in the `HashMap` that satisfy the condition is greater than or equal to `N`.
44+
pub type CountGreaterEqualHashMapRule<const N: usize, RULE, K> =
45+
CountGreaterEqualRule<N, RULE, std::collections::HashMap<K, <RULE as crate::rule::Rule>::Item>>;
46+
47+
/// Rule where the count of items in the `HashSet` that satisfy the condition is greater than or equal to `N`.
48+
pub type CountGreaterEqualHashSetRule<const N: usize, RULE, K> =
49+
CountGreaterEqualRule<N, RULE, std::collections::HashSet<K>>;
50+
51+
/// Rule where the count of items in the `String` that satisfy the condition is greater than or equal to `N`.
52+
pub type CountGreaterEqualStringRule<const N: usize, RULE> = CountGreaterEqualRule<N, RULE, String>;
53+
54+
/// Rule where the count of items in the `&'a str` that satisfy the condition is greater than or equal to `N`.
55+
pub type CountGreaterEqualStrRule<'a, const N: usize, RULE> =
56+
CountGreaterEqualRule<N, RULE, &'a str>;
57+
58+
#[cfg(test)]
59+
mod tests {
60+
use crate::result::Error;
61+
use crate::rule::{CountGreaterEqualVec, NonEmptyStringRule};
62+
63+
#[test]
64+
fn count_greater_equal_1() -> Result<(), Error<Vec<String>>> {
65+
let value = vec!["good morning".to_string(), "hello".to_string()];
66+
let count_greater_equal: CountGreaterEqualVec<2, NonEmptyStringRule> =
67+
CountGreaterEqualVec::new(value.clone())?;
68+
assert_eq!(count_greater_equal.into_value(), value);
69+
Ok(())
70+
}
71+
72+
#[test]
73+
fn count_greater_equal_2() -> anyhow::Result<()> {
74+
let value = vec!["".to_string(), "".to_string()];
75+
let count_greater_equal_result =
76+
CountGreaterEqualVec::<2, NonEmptyStringRule>::new(value.clone());
77+
assert!(count_greater_equal_result.is_err());
78+
Ok(())
79+
}
80+
}

0 commit comments

Comments
 (0)