From 290ed0297f0b4ee2aa5fe88bc7800c3fb6b0678c Mon Sep 17 00:00:00 2001 From: Michael Mc Donnell Date: Wed, 26 Feb 2020 12:13:31 -0800 Subject: [PATCH] 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. --- src/libcore/tests/hash/sip.rs | 37 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/libcore/tests/hash/sip.rs b/src/libcore/tests/hash/sip.rs index 0f095549915..12aa20a0bbd 100644 --- a/src/libcore/tests/hash/sip.rs +++ b/src/libcore/tests/hash/sip.rs @@ -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]