Skip to content

Commit

Permalink
Restore commented tests (#665)
Browse files Browse the repository at this point in the history
These seem to have been commented by accident in #298, and are still
passing.
  • Loading branch information
braddunbar authored Feb 6, 2024
1 parent d2e7abd commit 8bcac21
Showing 1 changed file with 41 additions and 38 deletions.
79 changes: 41 additions & 38 deletions src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,56 +1409,59 @@ fn original_capacity_from_repr(repr: usize) -> usize {
1 << (repr + (MIN_ORIGINAL_CAPACITY_WIDTH - 1))
}

/*
#[test]
fn test_original_capacity_to_repr() {
assert_eq!(original_capacity_to_repr(0), 0);
#[cfg(test)]
mod tests {
use super::*;

let max_width = 32;
#[test]
fn test_original_capacity_to_repr() {
assert_eq!(original_capacity_to_repr(0), 0);

for width in 1..(max_width + 1) {
let cap = 1 << width - 1;
let max_width = 32;

let expected = if width < MIN_ORIGINAL_CAPACITY_WIDTH {
0
} else if width < MAX_ORIGINAL_CAPACITY_WIDTH {
width - MIN_ORIGINAL_CAPACITY_WIDTH
} else {
MAX_ORIGINAL_CAPACITY_WIDTH - MIN_ORIGINAL_CAPACITY_WIDTH
};
for width in 1..(max_width + 1) {
let cap = 1 << width - 1;

assert_eq!(original_capacity_to_repr(cap), expected);
let expected = if width < MIN_ORIGINAL_CAPACITY_WIDTH {
0
} else if width < MAX_ORIGINAL_CAPACITY_WIDTH {
width - MIN_ORIGINAL_CAPACITY_WIDTH
} else {
MAX_ORIGINAL_CAPACITY_WIDTH - MIN_ORIGINAL_CAPACITY_WIDTH
};

if width > 1 {
assert_eq!(original_capacity_to_repr(cap + 1), expected);
}
assert_eq!(original_capacity_to_repr(cap), expected);

// MIN_ORIGINAL_CAPACITY_WIDTH must be bigger than 7 to pass tests below
if width == MIN_ORIGINAL_CAPACITY_WIDTH + 1 {
assert_eq!(original_capacity_to_repr(cap - 24), expected - 1);
assert_eq!(original_capacity_to_repr(cap + 76), expected);
} else if width == MIN_ORIGINAL_CAPACITY_WIDTH + 2 {
assert_eq!(original_capacity_to_repr(cap - 1), expected - 1);
assert_eq!(original_capacity_to_repr(cap - 48), expected - 1);
if width > 1 {
assert_eq!(original_capacity_to_repr(cap + 1), expected);
}

// MIN_ORIGINAL_CAPACITY_WIDTH must be bigger than 7 to pass tests below
if width == MIN_ORIGINAL_CAPACITY_WIDTH + 1 {
assert_eq!(original_capacity_to_repr(cap - 24), expected - 1);
assert_eq!(original_capacity_to_repr(cap + 76), expected);
} else if width == MIN_ORIGINAL_CAPACITY_WIDTH + 2 {
assert_eq!(original_capacity_to_repr(cap - 1), expected - 1);
assert_eq!(original_capacity_to_repr(cap - 48), expected - 1);
}
}
}
}

#[test]
fn test_original_capacity_from_repr() {
assert_eq!(0, original_capacity_from_repr(0));
#[test]
fn test_original_capacity_from_repr() {
assert_eq!(0, original_capacity_from_repr(0));

let min_cap = 1 << MIN_ORIGINAL_CAPACITY_WIDTH;
let min_cap = 1 << MIN_ORIGINAL_CAPACITY_WIDTH;

assert_eq!(min_cap, original_capacity_from_repr(1));
assert_eq!(min_cap * 2, original_capacity_from_repr(2));
assert_eq!(min_cap * 4, original_capacity_from_repr(3));
assert_eq!(min_cap * 8, original_capacity_from_repr(4));
assert_eq!(min_cap * 16, original_capacity_from_repr(5));
assert_eq!(min_cap * 32, original_capacity_from_repr(6));
assert_eq!(min_cap * 64, original_capacity_from_repr(7));
assert_eq!(min_cap, original_capacity_from_repr(1));
assert_eq!(min_cap * 2, original_capacity_from_repr(2));
assert_eq!(min_cap * 4, original_capacity_from_repr(3));
assert_eq!(min_cap * 8, original_capacity_from_repr(4));
assert_eq!(min_cap * 16, original_capacity_from_repr(5));
assert_eq!(min_cap * 32, original_capacity_from_repr(6));
assert_eq!(min_cap * 64, original_capacity_from_repr(7));
}
}
*/

unsafe impl Send for BytesMut {}
unsafe impl Sync for BytesMut {}
Expand Down

0 comments on commit 8bcac21

Please sign in to comment.