Skip to content

Commit

Permalink
implement test
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoikey committed Feb 23, 2024
1 parent 51318f9 commit e1da831
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/rule/non_empty/non_empty_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,54 @@ mod test {
assert_eq!(set.len(), 1);
Ok(())
}

#[test]
fn test_is_empty() -> anyhow::Result<()> {
let mut set = HashSet::new();
set.insert(1);
let set = NonEmptyHashSet::new(set)?;
assert!(!set.is_empty());
Ok(())
}

#[test]
fn test_insert() -> anyhow::Result<()> {
let mut set_origin = HashSet::new();
set_origin.insert(1);

let set = NonEmptyHashSet::new(set_origin.clone())?.insert(2);

set_origin.insert(2);
assert_eq!(set.into_value(), set_origin);
Ok(())
}

#[test]
fn test_is_get() -> anyhow::Result<()> {
let mut set = HashSet::new();
set.insert(1);
let set = NonEmptyHashSet::new(set)?;
assert_eq!(set.get(&1), Some(&1));
Ok(())
}

#[test]
fn test_is_contains() -> anyhow::Result<()> {
let mut set_origin = HashSet::new();
set_origin.insert(1);
let set = NonEmptyHashSet::new(set_origin.clone())?.insert(2);
assert!(set.contains(&1));
Ok(())
}

#[test]
fn test_is_difference() -> anyhow::Result<()> {
let mut set_origin = HashSet::new();
set_origin.insert(1);
let set = NonEmptyHashSet::new(set_origin.clone())?.insert(2);
let difference = set.difference(&set_origin);
assert_eq!(difference.count(), 1);
assert_eq!(set.difference(&set_origin).next(), Some(&2));
Ok(())
}
}

0 comments on commit e1da831

Please sign in to comment.