Macro assertables::assert_bag_ne
source · macro_rules! assert_bag_ne { ($a:expr, $b:expr $(,)?) => { ... }; ($a:expr, $b:expr, $($message:tt)+) => { ... }; }
Expand description
Assert a bag is not equal to another.
-
If true, return
()
. -
Otherwise, call
panic!
with a message and the values of the expressions with their debug representations.
Examples
// Return Ok
let a = [1, 1];
let b = [1, 1, 1];
assert_bag_ne!(&a, &b);
//-> ()
// Panic with error message
let result = panic::catch_unwind(|| {
let a = [1, 1];
let b = [1, 1];
assert_bag_ne!(&a, &b);
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = concat!(
"assertion failed: `assert_bag_ne!(left_bag, right_bag)`\n",
" left_bag label: `&a`,\n",
" left_bag debug: `[1, 1]`,\n",
" right_bag label: `&b`,\n",
" right_bag debug: `[1, 1]`,\n",
" left: `{1: 2}`,\n",
" right: `{1: 2}`"
);
assert_eq!(actual, expect);
// Panic with custom message
let result = panic::catch_unwind(|| {
let a = [1, 1];
let b = [1, 1];
assert_bag_ne!(&a, &b, "message");
//-> panic!
});
assert!(result.is_err());
let actual = result.unwrap_err().downcast::<String>().unwrap().to_string();
let expect = "message";
assert_eq!(actual, expect);
This implementation uses [BTreeMap
] to count items and sort them.