Skip to content

Commit

Permalink
Use assert_ne in hash tests
Browse files Browse the repository at this point in the history
The hash tests were written before the assert_ne macro was added to the standard library. The assert_ne macro provides better output in case of a failure.
  • Loading branch information
MichaelMcDonnell committed Feb 27, 2020
1 parent abc3073 commit 290ed02
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/libcore/tests/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ fn test_siphash_2_4() {
#[cfg(target_pointer_width = "32")]
fn test_hash_usize() {
let val = 0xdeadbeef_deadbeef_u64;
assert!(hash(&(val as u64)) != hash(&(val as usize)));
assert_ne!(hash(&(val as u64)), hash(&(val as usize)));
assert_eq!(hash(&(val as u32)), hash(&(val as usize)));
}

Expand All @@ -247,7 +247,7 @@ fn test_hash_usize() {
fn test_hash_usize() {
let val = 0xdeadbeef_deadbeef_u64;
assert_eq!(hash(&(val as u64)), hash(&(val as usize)));
assert!(hash(&(val as u32)) != hash(&(val as usize)));
assert_ne!(hash(&(val as u32)), hash(&(val as usize)));
}

#[test]
Expand All @@ -262,14 +262,14 @@ fn test_hash_idempotent() {
fn test_hash_no_bytes_dropped_64() {
let val = 0xdeadbeef_deadbeef_u64;

assert!(hash(&val) != hash(&zero_byte(val, 0)));
assert!(hash(&val) != hash(&zero_byte(val, 1)));
assert!(hash(&val) != hash(&zero_byte(val, 2)));
assert!(hash(&val) != hash(&zero_byte(val, 3)));
assert!(hash(&val) != hash(&zero_byte(val, 4)));
assert!(hash(&val) != hash(&zero_byte(val, 5)));
assert!(hash(&val) != hash(&zero_byte(val, 6)));
assert!(hash(&val) != hash(&zero_byte(val, 7)));
assert_ne!(hash(&val), hash(&zero_byte(val, 0)));
assert_ne!(hash(&val), hash(&zero_byte(val, 1)));
assert_ne!(hash(&val), hash(&zero_byte(val, 2)));
assert_ne!(hash(&val), hash(&zero_byte(val, 3)));
assert_ne!(hash(&val), hash(&zero_byte(val, 4)));
assert_ne!(hash(&val), hash(&zero_byte(val, 5)));
assert_ne!(hash(&val), hash(&zero_byte(val, 6)));
assert_ne!(hash(&val), hash(&zero_byte(val, 7)));

fn zero_byte(val: u64, byte: usize) -> u64 {
assert!(byte < 8);
Expand All @@ -281,10 +281,10 @@ fn test_hash_no_bytes_dropped_64() {
fn test_hash_no_bytes_dropped_32() {
let val = 0xdeadbeef_u32;

assert!(hash(&val) != hash(&zero_byte(val, 0)));
assert!(hash(&val) != hash(&zero_byte(val, 1)));
assert!(hash(&val) != hash(&zero_byte(val, 2)));
assert!(hash(&val) != hash(&zero_byte(val, 3)));
assert_ne!(hash(&val), hash(&zero_byte(val, 0)));
assert_ne!(hash(&val), hash(&zero_byte(val, 1)));
assert_ne!(hash(&val), hash(&zero_byte(val, 2)));
assert_ne!(hash(&val), hash(&zero_byte(val, 3)));

fn zero_byte(val: u32, byte: usize) -> u32 {
assert!(byte < 4);
Expand All @@ -299,14 +299,17 @@ fn test_hash_no_concat_alias() {
let u = ("a", "abb");

assert!(s != t && t != u);
assert!(hash(&s) != hash(&t) && hash(&s) != hash(&u));
assert_ne!(s, t);
assert_ne!(t, u);
assert_ne!(hash(&s), hash(&t));
assert_ne!(hash(&s), hash(&u));

let u = [1, 0, 0, 0];
let v = (&u[..1], &u[1..3], &u[3..]);
let w = (&u[..], &u[4..4], &u[4..4]);

assert!(v != w);
assert!(hash(&v) != hash(&w));
assert_ne!(v, w);
assert_ne!(hash(&v), hash(&w));
}

#[test]
Expand Down

0 comments on commit 290ed02

Please sign in to comment.