Skip to content

Commit

Permalink
Add tests for Atomic*::fetch_{min,max}
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Feb 14, 2021
1 parent 3158857 commit d1a541e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions library/core/tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ fn uint_xor() {
assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
}

#[test]
fn uint_min() {
let x = AtomicUsize::new(0xf731);
assert_eq!(x.fetch_min(0x137f, SeqCst), 0xf731);
assert_eq!(x.load(SeqCst), 0x137f);
assert_eq!(x.fetch_min(0xf731, SeqCst), 0x137f);
assert_eq!(x.load(SeqCst), 0x137f);
}

#[test]
fn uint_max() {
let x = AtomicUsize::new(0x137f);
assert_eq!(x.fetch_max(0xf731, SeqCst), 0x137f);
assert_eq!(x.load(SeqCst), 0xf731);
assert_eq!(x.fetch_max(0x137f, SeqCst), 0xf731);
assert_eq!(x.load(SeqCst), 0xf731);
}

#[test]
fn int_and() {
let x = AtomicIsize::new(0xf731);
Expand Down Expand Up @@ -87,6 +105,24 @@ fn int_xor() {
assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
}

#[test]
fn int_min() {
let x = AtomicIsize::new(0xf731);
assert_eq!(x.fetch_min(0x137f, SeqCst), 0xf731);
assert_eq!(x.load(SeqCst), 0x137f);
assert_eq!(x.fetch_min(0xf731, SeqCst), 0x137f);
assert_eq!(x.load(SeqCst), 0x137f);
}

#[test]
fn int_max() {
let x = AtomicIsize::new(0x137f);
assert_eq!(x.fetch_max(0xf731, SeqCst), 0x137f);
assert_eq!(x.load(SeqCst), 0xf731);
assert_eq!(x.fetch_max(0x137f, SeqCst), 0xf731);
assert_eq!(x.load(SeqCst), 0xf731);
}

static S_FALSE: AtomicBool = AtomicBool::new(false);
static S_TRUE: AtomicBool = AtomicBool::new(true);
static S_INT: AtomicIsize = AtomicIsize::new(0);
Expand Down

0 comments on commit d1a541e

Please sign in to comment.