Skip to content

Commit cd4c837

Browse files
committed
make corrections to the test
1 parent bdd2461 commit cd4c837

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/map.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8045,31 +8045,35 @@ mod test_map {
80458045
use crate::TryReserveError::{AllocError, CapacityOverflow};
80468046

80478047
const MAX_ISIZE: usize = isize::MAX as usize;
8048+
const GROUP_WIDTH: usize = 128;
80488049

80498050
let mut empty_bytes: HashMap<u8, u8> = HashMap::new();
80508051

80518052
if let Err(CapacityOverflow) = empty_bytes.try_reserve(usize::MAX) {
80528053
} else {
8053-
panic!("usize::MAX should trigger an overflow!");
8054+
panic!("isize::MAX should trigger an overflow!");
80548055
}
80558056

80568057
if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_ISIZE) {
80578058
} else {
8058-
panic!("usize::MAX should trigger an overflow!");
8059+
panic!("isize::MAX should trigger an overflow!");
80598060
}
80608061

8061-
if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_ISIZE / 16) {
8062+
if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_ISIZE / 24 - (GROUP_WIDTH + 1))
8063+
{
80628064
} else {
80638065
// This may succeed if there is enough free memory. Attempt to
80648066
// allocate a few more hashmaps to ensure the allocation will fail.
80658067
let mut empty_bytes2: HashMap<u8, u8> = HashMap::new();
8066-
let _ = empty_bytes2.try_reserve(MAX_ISIZE / 16);
8068+
let _ = empty_bytes2.try_reserve(MAX_ISIZE / 24 - (GROUP_WIDTH + 1));
80678069
let mut empty_bytes3: HashMap<u8, u8> = HashMap::new();
8068-
let _ = empty_bytes3.try_reserve(MAX_ISIZE / 16);
8070+
let _ = empty_bytes3.try_reserve(MAX_ISIZE / 24 - (GROUP_WIDTH + 1));
80698071
let mut empty_bytes4: HashMap<u8, u8> = HashMap::new();
8070-
if let Err(AllocError { .. }) = empty_bytes4.try_reserve(MAX_ISIZE / 16) {
8072+
if let Err(AllocError { .. }) =
8073+
empty_bytes4.try_reserve(MAX_ISIZE / 24 - (GROUP_WIDTH + 1))
8074+
{
80718075
} else {
8072-
panic!("usize::MAX / 8 should trigger an OOM!");
8076+
panic!("isize::MAX / 24 should trigger an OOM!");
80738077
}
80748078
}
80758079
}

0 commit comments

Comments
 (0)