Skip to content

Commit

Permalink
Change test to quickcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
JarredAllen committed Aug 18, 2020
1 parent cc88a2d commit 1d05c2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
21 changes: 21 additions & 0 deletions tests/quick.rs
Expand Up @@ -1188,3 +1188,24 @@ quickcheck! {
}
}
}

quickcheck! {
#[test]
fn counts(nums: Vec<isize>) -> TestResult {
let counts = nums.iter().counts();
for (&item, &count) in counts.iter() {
if count <= 0 {
return TestResult::failed();
}
if count != nums.iter().filter(|&x| x == item).count() {
return TestResult::failed();
}
}
for item in nums.iter() {
if !counts.contains_key(item) {
return TestResult::failed();
}
}
TestResult::passed()
}
}
13 changes: 0 additions & 13 deletions tests/test_std.rs
Expand Up @@ -913,16 +913,3 @@ fn tree_fold1() {
assert_eq!(actual, expected);
}
}

#[test]
fn counts() {
let a: [usize; 0] = [];
assert_eq!(0, a.iter().counts().len());
let b = [1, 1, 1, 2, 2, 3];
let b_counts = b.iter().counts();
assert_eq!(3, b_counts.len());
assert_eq!(Some(&3), b_counts.get(&1));
assert_eq!(Some(&2), b_counts.get(&2));
assert_eq!(Some(&1), b_counts.get(&3));
assert_eq!(None, b_counts.get(&4));
}

0 comments on commit 1d05c2b

Please sign in to comment.