Skip to content

Commit da226dd

Browse files
committed
Lighten tests, in particular for Miri, yet test and explain more
1 parent 914b855 commit da226dd

File tree

1 file changed

+32
-20
lines changed
  • src/liballoc/tests/btree

1 file changed

+32
-20
lines changed

src/liballoc/tests/btree/map.rs

+32-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn test_basic_large() {
1515
#[cfg(not(miri))] // Miri is too slow
1616
let size = 10000;
1717
#[cfg(miri)]
18-
let size = 200;
18+
let size = 144; // to obtain height 3 tree (having edges to both kinds of nodes)
1919
assert_eq!(map.len(), 0);
2020

2121
for i in 0..size {
@@ -381,8 +381,8 @@ fn test_range_small() {
381381
}
382382

383383
#[test]
384-
fn test_range_depth_2() {
385-
// Assuming that node.CAPACITY is 11, having 12 pairs implies a depth 2 tree
384+
fn test_range_height_2() {
385+
// Assuming that node.CAPACITY is 11, having 12 pairs implies a height 2 tree
386386
// with 2 leaves. Depending on details we don't want or need to rely upon,
387387
// the single key at the root will be 6 or 7.
388388

@@ -524,7 +524,7 @@ fn test_range_1000() {
524524
#[cfg(not(miri))] // Miri is too slow
525525
let size = 1000;
526526
#[cfg(miri)]
527-
let size = 200;
527+
let size = 144; // to obtain height 3 tree (having edges to both kinds of nodes)
528528
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
529529

530530
fn test(map: &BTreeMap<u32, u32>, size: u32, min: Bound<&u32>, max: Bound<&u32>) {
@@ -561,14 +561,15 @@ fn test_range_borrowed_key() {
561561

562562
#[test]
563563
fn test_range() {
564-
#[cfg(not(miri))] // Miri is too slow
565564
let size = 200;
565+
#[cfg(not(miri))] // Miri is too slow
566+
let step = 1;
566567
#[cfg(miri)]
567-
let size = 30;
568+
let step = 66;
568569
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
569570

570-
for i in 0..size {
571-
for j in i..size {
571+
for i in (0..size).step_by(step) {
572+
for j in (i..size).step_by(step) {
572573
let mut kvs = map.range((Included(&i), Included(&j))).map(|(&k, &v)| (k, v));
573574
let mut pairs = (i..=j).map(|i| (i, i));
574575

@@ -583,14 +584,15 @@ fn test_range() {
583584

584585
#[test]
585586
fn test_range_mut() {
586-
#[cfg(not(miri))] // Miri is too slow
587587
let size = 200;
588+
#[cfg(not(miri))] // Miri is too slow
589+
let step = 1;
588590
#[cfg(miri)]
589-
let size = 30;
591+
let step = 66;
590592
let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
591593

592-
for i in 0..size {
593-
for j in i..size {
594+
for i in (0..size).step_by(step) {
595+
for j in (i..size).step_by(step) {
594596
let mut kvs = map.range_mut((Included(&i), Included(&j))).map(|(&k, &mut v)| (k, v));
595597
let mut pairs = (i..=j).map(|i| (i, i));
596598

@@ -758,10 +760,7 @@ fn test_bad_zst() {
758760
#[test]
759761
fn test_clone() {
760762
let mut map = BTreeMap::new();
761-
#[cfg(not(miri))] // Miri is too slow
762-
let size = 100;
763-
#[cfg(miri)]
764-
let size = 30;
763+
let size = 12; // to obtain height 2 tree (having edges to leaf nodes)
765764
assert_eq!(map.len(), 0);
766765

767766
for i in 0..size {
@@ -788,24 +787,36 @@ fn test_clone() {
788787
assert_eq!(map.len(), size / 2 - i - 1);
789788
assert_eq!(map, map.clone());
790789
}
790+
791+
// Full 2-level and minimal 3-level tree (sizes 143, 144 -- the only ones we clone for).
792+
for i in 1..=144 {
793+
assert_eq!(map.insert(i, i), None);
794+
assert_eq!(map.len(), i);
795+
if i >= 143 {
796+
assert_eq!(map, map.clone());
797+
}
798+
}
791799
}
792800

793801
#[test]
794802
fn test_clone_from() {
795803
let mut map1 = BTreeMap::new();
796-
let size = 30;
804+
let max_size = 12; // to obtain height 2 tree (having edges to leaf nodes)
797805

798-
for i in 0..size {
806+
// Range to max_size inclusive, because i is the size of map1 being tested.
807+
for i in 0..=max_size {
799808
let mut map2 = BTreeMap::new();
800809
for j in 0..i {
801810
let mut map1_copy = map2.clone();
802-
map1_copy.clone_from(&map1);
811+
map1_copy.clone_from(&map1); // small cloned from large
803812
assert_eq!(map1_copy, map1);
804813
let mut map2_copy = map1.clone();
805-
map2_copy.clone_from(&map2);
814+
map2_copy.clone_from(&map2); // large cloned from small
806815
assert_eq!(map2_copy, map2);
807816
map2.insert(100 * j + 1, 2 * j + 1);
808817
}
818+
map2.clone_from(&map1); // same length
819+
assert_eq!(map2, map1);
809820
map1.insert(i, 10 * i);
810821
}
811822
}
@@ -956,6 +967,7 @@ create_append_test!(test_append_145, 145);
956967
// Tests for several randomly chosen sizes.
957968
create_append_test!(test_append_170, 170);
958969
create_append_test!(test_append_181, 181);
970+
#[cfg(not(miri))] // Miri is too slow
959971
create_append_test!(test_append_239, 239);
960972
#[cfg(not(miri))] // Miri is too slow
961973
create_append_test!(test_append_1700, 1700);

0 commit comments

Comments
 (0)