Skip to content

Commit

Permalink
Optimize test case
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Sep 3, 2024
1 parent 3a43dcd commit a7c0ac6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
34 changes: 29 additions & 5 deletions crossbeam-skiplist/tests/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,9 +921,28 @@ fn comparable_get() {
b: u32,
}

#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(PartialEq, Eq)]
struct FooRef<'a> {
data: &'a [u8]
data: &'a [u8],
}

impl PartialOrd for FooRef<'_> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl Ord for FooRef<'_> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
let a = u64::from_be_bytes(self.data[..8].try_into().unwrap());
let b = u32::from_be_bytes(self.data[8..].try_into().unwrap());
let other_a = u64::from_be_bytes(other.data[..8].try_into().unwrap());
let other_b = u32::from_be_bytes(other.data[8..].try_into().unwrap());
Foo { a, b }.cmp(&Foo {
a: other_a,
b: other_b,
})
}
}

impl Equivalent<Foo> for FooRef<'_> {
Expand All @@ -948,11 +967,16 @@ fn comparable_get() {
let g = &epoch::pin();
s.insert(foo, 12, g);

let buf = 1u64.to_be_bytes().iter().chain(2u32.to_be_bytes().iter()).copied().collect::<Vec<_>>();
let buf = 1u64
.to_be_bytes()
.iter()
.chain(2u32.to_be_bytes().iter())
.copied()
.collect::<Vec<_>>();
let foo_ref = FooRef { data: &buf };

let ent = s.get(&foo_ref, g).unwrap();
assert_eq!(ent.key().a, 1);
assert_eq!(ent.key().b, 2);
assert_eq!(*ent.value(), 12);
}
}
4 changes: 3 additions & 1 deletion crossbeam-skiplist/tests/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,9 @@ fn iter_range() {
vec![90, 80, 70, 60, 50, 40, 30, 20, 10, 0]
);
assert_eq!(
s.range::<i32, _>(..).map(|x| *x.value()).collect::<Vec<_>>(),
s.range::<i32, _>(..)
.map(|x| *x.value())
.collect::<Vec<_>>(),
vec![0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
);

Expand Down

0 comments on commit a7c0ac6

Please sign in to comment.