Created
January 19, 2019 15:47
-
-
Save winstonewert/3eb537310c70fc0631e64c5cee26a062 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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