Skip to content

Instantly share code, notes, and snippets.

@winstonewert
Created January 19, 2019 15:47
Show Gist options
  • Save winstonewert/3eb537310c70fc0631e64c5cee26a062 to your computer and use it in GitHub Desktop.
Save winstonewert/3eb537310c70fc0631e64c5cee26a062 to your computer and use it in GitHub Desktop.
use quickcheck::*;
use fasthash::MetroHasher;
use itertools::Itertools;
use im_rc::hashset::HashSet;
fn make_std_set(items: &[i32]) -> std::collections::HashSet<i32> {
items.iter().cloned().collect()
}
fn make_set(items: &[i32]) -> HashSet<i32, MyHasher> {
items.iter().cloned().collect()
}
struct MyHasher {}
impl std::hash::BuildHasher for MyHasher {
type Hasher = MetroHasher;
fn build_hasher(&self) -> MetroHasher {
MetroHasher::default()
}
}
impl Default for MyHasher {
fn default() -> MyHasher {
MyHasher {}
}
}
quickcheck! {
fn prop(base_values: Vec<i32>, union_values: Vec<Vec<i32>>) -> bool {
let lhs = make_set(&base_values);
let lhs_std = make_std_set(&base_values);
for values in union_values {
let rhs = make_set(&values);
let rhs_std = make_std_set(&values);
let union = lhs.clone().union(rhs);
let union_std = lhs_std.union(&rhs_std);
if union_std.count() != union.len() {
return false;
}
}
true
}
}
#[test]
fn test() {
let base_values = vec![48];
let union_values = vec![
vec![-65],
vec![69, 45, 76]
];
let lhs = make_set(&base_values);
let lhs_std = make_std_set(&base_values);
for values in union_values {
let rhs = make_set(&values);
let rhs_std = make_std_set(&values);
let union = lhs.clone().union(rhs);
let union_std = lhs_std.union(&rhs_std);
if union_std.count() != union.len() {
assert!(false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment