Skip to content

Commit

Permalink
Fix bad test_replace for LinkedHashSet
Browse files Browse the repository at this point in the history
The test was supposed to check for *real* equality with the replaced
value but it wasn't due to the overridden `Eq`. Also fixes an unused
variable warning due to not checking the second field for equality.
  • Loading branch information
kyren committed Dec 6, 2024
1 parent 006dc69 commit 29bf1c5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/linked_hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,23 @@ fn test_replace() {
}
}

impl Foo {
fn really_eq(&self, other: &Self) -> bool {
self.0 == other.0 && self.1 == other.1
}
}

let mut s = LinkedHashSet::new();
assert_eq!(s.replace(Foo("a", 1)), None);
assert_eq!(s.len(), 1);
assert_eq!(s.replace(Foo("a", 2)), Some(Foo("a", 1)));
assert_eq!(
s.replace(Foo("a", 2)).map(|f| f.really_eq(&Foo("a", 1))),
Some(true)
);
assert_eq!(s.len(), 1);

let mut it = s.iter();
assert_eq!(it.next(), Some(&Foo("a", 2)));
assert_eq!(it.next().map(|f| f.really_eq(&Foo("a", 2))), Some(true));
assert_eq!(it.next(), None);
}

Expand Down

0 comments on commit 29bf1c5

Please sign in to comment.