#collection #values #contain #elements #testing #slice

same_elements

Function to test if two collections contain the same values

1 unstable release

0.1.0 Jan 5, 2021

#1923 in Data structures

MPL-2.0 license

8KB
55 lines

Same Elements

Function to test if two collections contain the same values.

Sometimes when creating unit tests, I need to test that two slices contain the same values, but not necessarily in the same order. You can sort the values before testing that the two slices are identical, or alternatively, you can use this crate instead.

Example code

use same_elements::*;

let a = [1,2,3,4,5];
let b = [2,4,1,3,5];
assert!(a.same_elements(&b));

lib.rs:

TODO: write documentation.

No runtime deps