encoding_index_tests::multi_byte_range_tests!
[-] [+]
[src]
macro_rules! multi_byte_range_tests { ( mod = $parentmod:ident, key = [$minkey:expr, $maxkey:expr], key < $keyubound:expr, value = [$minvalue:expr, $maxvalue:expr], value < $valueubound:expr ) => ( mod tests { extern crate test; use $parentmod::{forward, backward}; static MIN_KEY: u32 = $minkey; static MAX_KEY: u32 = $maxkey; static KEY_UBOUND: u32 = $keyubound; static MIN_VALUE: u32 = $minvalue; static MAX_VALUE: u32 = $maxvalue; static VALUE_UBOUND: u32 = $valueubound; #[test] #[allow(unused_comparisons)] fn test_no_failure() { for i in (if MIN_KEY>0 {MIN_KEY-1} else {0})..(MAX_KEY+2) { forward(i); } for j in (if MIN_VALUE>0 {MIN_VALUE-1} else {0})..(MAX_VALUE+2) { backward(j); } } #[test] fn test_correct_table() { for i in MIN_KEY..(MAX_KEY+2) { let j = forward(i); if j == 0xffffffff { continue; } let i_ = backward(j); if i_ == 0xffffffff { continue; } assert!(i_ == i, "backward(forward({})) = backward({}) = {} != {}", i, j, i_, i); } } #[bench] fn bench_forward_sequential_128(bencher: &mut test::Bencher) { let mut start: u32 = 0; bencher.iter(|| { for i in start..(start + 0x80) { test::black_box(forward(i)); } start += 0x80; if start >= KEY_UBOUND { start = 0; } }) } #[bench] fn bench_backward_sequential_128(bencher: &mut test::Bencher) { let mut start: u32 = 0; bencher.iter(|| { for i in start..(start + 0x80) { test::black_box(backward(i)); } start += 0x80; if start >= VALUE_UBOUND { start = 0; } }) } } ); }
Makes a common test suite for multi-byte range indices.