mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-23 07:36:33 +11:00
Fail test in extreme case test if we drop twice
This commit is contained in:
parent
9df79a16bd
commit
3f624ee87d
1 changed files with 41 additions and 3 deletions
|
@ -558,6 +558,41 @@ mod test {
|
|||
}
|
||||
}
|
||||
|
||||
struct NoisyDrop {
|
||||
i: i32,
|
||||
dropped: bool,
|
||||
}
|
||||
|
||||
impl NoisyDrop {
|
||||
fn new(i: i32) -> Self {
|
||||
Self { i, dropped: false }
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for NoisyDrop {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.i == other.i
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for NoisyDrop {}
|
||||
|
||||
impl Hash for NoisyDrop {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
hasher.write_i32(self.i);
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for NoisyDrop {
|
||||
fn drop(&mut self) {
|
||||
if self.dropped {
|
||||
panic!("NoisyDropped dropped twice");
|
||||
}
|
||||
|
||||
self.dropped = true;
|
||||
}
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn extreme_case(_gba: &mut Gba) {
|
||||
let mut map = HashMap::new();
|
||||
|
@ -574,18 +609,21 @@ mod test {
|
|||
0 => {
|
||||
// insert
|
||||
answers[key as usize] = Some(value);
|
||||
map.insert(key, value);
|
||||
map.insert(NoisyDrop::new(key), NoisyDrop::new(value));
|
||||
}
|
||||
1 => {
|
||||
// remove
|
||||
answers[key as usize] = None;
|
||||
map.remove(&key);
|
||||
map.remove(&NoisyDrop::new(key));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
for (i, answer) in answers.iter().enumerate() {
|
||||
assert_eq!(map.get(&(i as i32)), answer.as_ref());
|
||||
assert_eq!(
|
||||
map.get(&NoisyDrop::new(i as i32)).map(|nd| &nd.i),
|
||||
answer.as_ref()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue