Skip to content

Commit 6966567

Browse files
mendelsshopphimuemue
authored andcommitted
Added tests for array_combinations_with_replacement
1 parent 1de0c30 commit 6966567

File tree

7 files changed

+103
-0
lines changed

7 files changed

+103
-0
lines changed

benches/combinations_with_replacement.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,42 @@ fn comb_replacement_n10_k10(c: &mut Criterion) {
3030
})
3131
});
3232
}
33+
fn array_comb_replacement_n10_k5(c: &mut Criterion) {
34+
c.bench_function("array comb replacement n10k5", move |b| {
35+
b.iter(|| {
36+
for i in (0..10).array_combinations_with_replacement::<5>() {
37+
black_box(i);
38+
}
39+
})
40+
});
41+
}
3342

43+
fn array_comb_replacement_n5_k10(c: &mut Criterion) {
44+
c.bench_function("array comb replacement n5 k10", move |b| {
45+
b.iter(|| {
46+
for i in (0..5).array_combinations_with_replacement::<10>() {
47+
black_box(i);
48+
}
49+
})
50+
});
51+
}
52+
53+
fn array_comb_replacement_n10_k10(c: &mut Criterion) {
54+
c.bench_function("array comb replacement n10 k10", move |b| {
55+
b.iter(|| {
56+
for i in (0..10).array_combinations_with_replacement::<10>() {
57+
black_box(i);
58+
}
59+
})
60+
});
61+
}
3462
criterion_group!(
3563
benches,
3664
comb_replacement_n10_k5,
3765
comb_replacement_n5_k10,
3866
comb_replacement_n10_k10,
67+
array_comb_replacement_n10_k5,
68+
array_comb_replacement_n5_k10,
69+
array_comb_replacement_n10_k10,
3970
);
4071
criterion_main!(benches);

benches/specializations.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,30 @@ bench_specializations! {
441441
}
442442
v.iter().combinations_with_replacement(4)
443443
}
444+
array_combinations_with_replacement1 {
445+
{
446+
let v = black_box(vec![0; 4096]);
447+
}
448+
v.iter().array_combinations_with_replacement::<1>()
449+
}
450+
array_combinations_with_replacement2 {
451+
{
452+
let v = black_box(vec![0; 90]);
453+
}
454+
v.iter().array_combinations_with_replacement::<2>()
455+
}
456+
array_combinations_with_replacement3 {
457+
{
458+
let v = black_box(vec![0; 28]);
459+
}
460+
v.iter().array_combinations_with_replacement::<3>()
461+
}
462+
array_combinations_with_replacement4 {
463+
{
464+
let v = black_box(vec![0; 16]);
465+
}
466+
v.iter().array_combinations_with_replacement::<4>()
467+
}
444468
permutations1 {
445469
{
446470
let v = black_box(vec![0; 1024]);

tests/adaptors_no_collect.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ fn combinations_no_collect() {
4949
fn combinations_with_replacement_no_collect() {
5050
no_collect_test(|iter| iter.combinations_with_replacement(5))
5151
}
52+
#[test]
53+
fn array_combinations_with_replacement_no_collect() {
54+
no_collect_test(|iter| iter.array_combinations_with_replacement::<5>())
55+
}

tests/laziness.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ must_use_tests! {
217217
let _ = Panicking.combinations_with_replacement(1);
218218
let _ = Panicking.combinations_with_replacement(2);
219219
}
220+
array_combinations_with_replacement {
221+
let _ = Panicking.array_combinations_with_replacement::<0>();
222+
let _ = Panicking.array_combinations_with_replacement::<1>();
223+
let _ = Panicking.array_combinations_with_replacement::<2>();
224+
}
220225
permutations {
221226
let _ = Panicking.permutations(0);
222227
let _ = Panicking.permutations(1);

tests/quick.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,11 @@ quickcheck! {
18381838
is_fused(a.combinations_with_replacement(3))
18391839
}
18401840

1841+
fn fused_array_combination_with_replacement(a: Iter<i16>) -> bool
1842+
{
1843+
is_fused(a.clone().array_combinations_with_replacement::<1>()) &&
1844+
is_fused(a.array_combinations_with_replacement::<3>())
1845+
}
18411846
fn fused_tuple_combination(a: Iter<i16>) -> bool
18421847
{
18431848
is_fused(a.clone().fuse().tuple_combinations::<(_,)>()) &&

tests/specializations.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ quickcheck! {
299299
TestResult::passed()
300300
}
301301

302+
fn array_combinations_with_replacement(a: Vec<u8>) -> TestResult {
303+
if a.len() > 10 {
304+
return TestResult::discard();
305+
}
306+
test_specializations(&a.iter().array_combinations_with_replacement::<1>());
307+
test_specializations(&a.iter().array_combinations_with_replacement::<2>());
308+
test_specializations(&a.iter().array_combinations_with_replacement::<3>());
309+
310+
TestResult::passed()
311+
}
302312
fn permutations(a: Vec<u8>, n: u8) -> TestResult {
303313
if n > 3 || a.len() > 8 {
304314
return TestResult::discard();

tests/test_std.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,30 @@ fn combinations_with_replacement_range_count() {
12561256
}
12571257
}
12581258

1259+
#[test]
1260+
#[cfg(not(miri))]
1261+
fn array_combinations_with_replacement() {
1262+
// Pool smaller than n
1263+
it::assert_equal(
1264+
(0..1).array_combinations_with_replacement::<2>(),
1265+
vec![[0, 0]],
1266+
);
1267+
// Pool larger than n
1268+
it::assert_equal(
1269+
(0..3).array_combinations_with_replacement::<2>(),
1270+
vec![[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]],
1271+
);
1272+
// Zero size
1273+
it::assert_equal((0..3).array_combinations_with_replacement::<0>(), vec![[]]);
1274+
// Zero size on empty pool
1275+
it::assert_equal((0..0).array_combinations_with_replacement::<0>(), vec![[]]);
1276+
// Empty pool
1277+
it::assert_equal(
1278+
(0..0).array_combinations_with_replacement::<2>(),
1279+
vec![] as Vec<[_; 2]>,
1280+
);
1281+
}
1282+
12591283
#[test]
12601284
fn powerset() {
12611285
it::assert_equal((0..0).powerset(), vec![vec![]]);

0 commit comments

Comments
 (0)