Skip to content

Commit f49eaec

Browse files
committed
reorganize test contents and adjust generated inputs to reduce iterations
1 parent 3f1aa0b commit f49eaec

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

library/coretests/tests/num/uint_macros.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ macro_rules! uint_module {
407407
assert_eq!(&xs, &[0xff, 0x00, 0x0f, 0xf0, 0x33, 0xcc, 0x55, 0xaa]);
408408
}
409409

410-
// `256 * BITS` masks
410+
// `256 * (BITS / 5)` masks
411411
let sparse_masks = (i8::MIN..=i8::MAX)
412412
.map(|i| (i as i128 as $T).rotate_right(4))
413-
.flat_map(|x| (0..$T::BITS).map(move |s| ((1 as $T) << s) ^ x));
413+
.flat_map(|x| (0..$T::BITS).step_by(5).map(move |r| x.rotate_right(r)));
414414

415415
for sparse in sparse_masks {
416416
// Collect the set bits to sequential low bits
@@ -419,21 +419,19 @@ macro_rules! uint_module {
419419
assert_eq!(count, dense.count_ones());
420420
assert_eq!(count, dense.trailing_ones());
421421

422+
// Check that each bit is individually mapped correctly
422423
let mut t = sparse;
423-
for k in 0..$T::BITS {
424-
let x = ((1 as $T) << k).scatter_bits(sparse);
425-
let y = t.isolate_lowest_one();
426-
assert_eq!(x, y);
427-
t ^= y;
428-
}
429-
430-
let mut t = sparse;
431-
for k in 0..count {
432-
let y = t.isolate_lowest_one();
433-
let x = y.gather_bits(sparse);
434-
assert_eq!(x, (1 as $T) << k);
435-
t ^= y;
424+
let mut bit = 1 as $T;
425+
for _ in 0..count {
426+
let lowest_one = t.isolate_lowest_one();
427+
assert_eq!(lowest_one, bit.scatter_bits(sparse));
428+
assert_eq!(bit, lowest_one.gather_bits(sparse));
429+
t ^= lowest_one;
430+
bit <<= 1;
436431
}
432+
// Other bits are ignored
433+
assert_eq!(0, bit.wrapping_neg().scatter_bits(sparse));
434+
assert_eq!(0, (!sparse).gather_bits(sparse));
437435

438436
for &x in &xs {
439437
// Gather bits from `x & sparse` to `dense`

0 commit comments

Comments
 (0)