Rollup merge of #69504 - MichaelMcDonnell:hash_assert_ne, r=LukasKalbertodt
Use assert_ne in hash tests 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.
This commit is contained in:
commit
2774d48337
@ -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)));
|
||||
}
|
||||
|
||||
@ -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]
|
||||
@ -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);
|
||||
@ -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);
|
||||
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user