Skip to content

Commit 11b2058

Browse files
committed
test_std: Add generic_test! to instanciate tests w/ multiple types
1 parent 45e5a64 commit 11b2058

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ either = { version = "1.0", default-features = false }
2828
[dev-dependencies]
2929
rand = "0.7"
3030
criterion = "=0" # TODO how could this work with our minimum supported rust version?
31+
paste = "1.0.0" # Used in test_std to instanciate generic tests
3132

3233
[dev-dependencies.quickcheck]
3334
version = "0.9"

tests/test_std.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use paste;
12
use permutohedron;
23
use quickcheck as qc;
34
use rand::{distributions::{Distribution, Standard}, Rng, SeedableRng, rngs::StdRng};
@@ -426,21 +427,20 @@ where
426427
)
427428
}
428429

429-
qc::quickcheck! {
430-
fn k_smallest_sort_u8(i: RandIter<u8>, k: u16) -> () {
431-
k_smallest_sort(i, k)
432-
}
433-
fn k_smallest_sort_u16(i: RandIter<u16>, k: u16) -> () {
434-
k_smallest_sort(i, k)
435-
}
436-
fn k_smallest_sort_u32(i: RandIter<u32>, k: u16) -> () {
437-
k_smallest_sort(i, k)
438-
}
439-
fn k_smallest_sort_u64(i: RandIter<u64>, k: u16) -> () {
440-
k_smallest_sort(i, k)
441-
}
430+
macro_rules! generic_test {
431+
($f:ident, $($t:ty),+) => {
432+
$(paste::item! {
433+
qc::quickcheck! {
434+
fn [< $f _ $t >](i: RandIter<$t>, k: u16) -> () {
435+
$f(i, k)
436+
}
437+
}
438+
})+
439+
};
442440
}
443441

442+
generic_test!(k_smallest_sort, u8, u16, u32, u64, i8, i16, i32, i64);
443+
444444
#[test]
445445
fn sorted_by_key() {
446446
let sc = [3, 4, 1, 2].iter().cloned().sorted_by_key(|&x| x);
@@ -474,7 +474,6 @@ fn test_multipeek() {
474474
assert_eq!(mp.next(), Some(5));
475475
assert_eq!(mp.next(), None);
476476
assert_eq!(mp.peek(), None);
477-
478477
}
479478

480479
#[test]

0 commit comments

Comments
 (0)