Adds test for SortedStorages::new_with_slots() (#31471)

This commit is contained in:
Brooks 2023-05-04 06:13:08 -04:00 committed by GitHub
parent ed4cc52250
commit 22d4c6abf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 77 additions and 1 deletions

View File

@ -191,7 +191,7 @@ impl<'a> SortedStoragesIter<'a> {
}
#[cfg(test)]
pub mod tests {
mod tests {
use {
super::*,
crate::{
@ -201,6 +201,7 @@ pub mod tests {
},
std::sync::Arc,
};
impl<'a> SortedStorages<'a> {
pub fn new_debug(
source: &[(&'a Arc<AccountStorageEntry>, Slot)],
@ -327,6 +328,81 @@ pub mod tests {
);
}
#[test]
fn test_sorted_storages_new_with_slots() {
let store = create_sample_store(1);
let start = 33;
let end = 44;
// ┌───────────────────────────────────────┐
// │ ■ storages ■ │
// └──────┃──────────────────────────┃─────┘
// min┣ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─┃max
// ■ ■
{
let min = start + 1;
let max = end - 1;
let storages = SortedStorages::new_with_slots(
[(&store, end), (&store, start)].iter().cloned(),
Some(min),
Some(max),
);
assert_eq!(storages.storages.len(), 2);
assert_eq!(storages.range, start..end + 1);
}
// ┌───────────────────────────────────────┐
// │ storages ■ │ ■
// └──────────────────────────────┃────────┘ ┃
// min┣ ─ ─ ─ ─ ─ ─ ┫max
// ■ ■
{
let min = start + 1;
let max = end + 1;
let storages = SortedStorages::new_with_slots(
[(&store, end), (&store, start)].iter().cloned(),
Some(min),
Some(max),
);
assert_eq!(storages.storages.len(), 2);
assert_eq!(storages.range, start..max + 1);
}
// ┌───────────────────────────────────────┐
// ■ │ ■ storages │
// ┃ └─────┃─────────────────────────────────┘
// min┣ ─ ─ ─ ─ ┫max
// ■ ■
{
let min = start - 1;
let max = end - 1;
let storages = SortedStorages::new_with_slots(
[(&store, end), (&store, start)].iter().cloned(),
Some(min),
Some(max),
);
assert_eq!(storages.storages.len(), 2);
assert_eq!(storages.range, min..end + 1);
}
// ┌───────────────────────────────────────┐
// ■ │ storages │ ■
// ┃ └───────────────────────────────────────┘ ┃
// min┣ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┫max
// ■ ■
{
let min = start - 1;
let max = end + 1;
let storages = SortedStorages::new_with_slots(
[(&store, end), (&store, start)].iter().cloned(),
Some(min),
Some(max),
);
assert_eq!(storages.storages.len(), 2);
assert_eq!(storages.range, min..max + 1);
}
}
#[test]
#[should_panic(expected = "slots are not unique")]
fn test_sorted_storages_duplicate_slots() {