Skip to content

Commit 1d05c2b

Browse files
committed
Change test to quickcheck
1 parent cc88a2d commit 1d05c2b

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

tests/quick.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,3 +1188,24 @@ quickcheck! {
11881188
}
11891189
}
11901190
}
1191+
1192+
quickcheck! {
1193+
#[test]
1194+
fn counts(nums: Vec<isize>) -> TestResult {
1195+
let counts = nums.iter().counts();
1196+
for (&item, &count) in counts.iter() {
1197+
if count <= 0 {
1198+
return TestResult::failed();
1199+
}
1200+
if count != nums.iter().filter(|&x| x == item).count() {
1201+
return TestResult::failed();
1202+
}
1203+
}
1204+
for item in nums.iter() {
1205+
if !counts.contains_key(item) {
1206+
return TestResult::failed();
1207+
}
1208+
}
1209+
TestResult::passed()
1210+
}
1211+
}

tests/test_std.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -913,16 +913,3 @@ fn tree_fold1() {
913913
assert_eq!(actual, expected);
914914
}
915915
}
916-
917-
#[test]
918-
fn counts() {
919-
let a: [usize; 0] = [];
920-
assert_eq!(0, a.iter().counts().len());
921-
let b = [1, 1, 1, 2, 2, 3];
922-
let b_counts = b.iter().counts();
923-
assert_eq!(3, b_counts.len());
924-
assert_eq!(Some(&3), b_counts.get(&1));
925-
assert_eq!(Some(&2), b_counts.get(&2));
926-
assert_eq!(Some(&1), b_counts.get(&3));
927-
assert_eq!(None, b_counts.get(&4));
928-
}

0 commit comments

Comments
 (0)