Skip to content

Commit a4da525

Browse files
committed
In theory shrinkage should be 2, but in practice we get better trees with a larger value.
1 parent 6763ede commit a4da525

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

tests/testsuite/resolve.rs

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ fn meta_test_deep_pretty_print_registry() {
277277
fn registry_strategy(
278278
max_crates: usize,
279279
max_versions: usize,
280+
shrinkage: usize,
280281
) -> impl Strategy<Value = PrettyPrintRegistry> {
281282
let name = string_regex("[A-Za-z_-][A-Za-z0-9_-]*(-sys)?").unwrap();
282283

@@ -285,7 +286,7 @@ fn registry_strategy(
285286

286287
// If this is false than the crate will depend on the nonexistent "bad"
287288
// instead of the complex set we generated for it.
288-
let allow_deps = prop::bool::weighted(0.95);
289+
let allow_deps = prop::bool::weighted(0.99);
289290

290291
let list_of_versions =
291292
btree_set((raw_version, allow_deps), 1..=max_versions).prop_map(move |ver| {
@@ -304,8 +305,9 @@ fn registry_strategy(
304305
vers
305306
});
306307

307-
// each version of each crate can depend on each crate smaller then it
308-
let max_deps = 1 + max_versions * (max_crates * (max_crates - 1)) / 2;
308+
// each version of each crate can depend on each crate smaller then it.
309+
// In theory shrinkage should be 2, but in practice we get better trees with a larger value.
310+
let max_deps = max_versions * (max_crates * (max_crates - 1)) / shrinkage;
309311

310312
let raw_version_range = (any::<Index>(), any::<Index>());
311313
let raw_dependency = (any::<Index>(), any::<Index>(), raw_version_range);
@@ -370,10 +372,9 @@ fn registry_strategy(
370372
/// that it makes registries with large dependency trees
371373
#[test]
372374
fn meta_test_deep_trees_from_strategy() {
373-
let mut seen_an_error = false;
374-
let mut seen_a_deep_tree = false;
375+
let mut dis = [0; 21];
375376

376-
let strategy = registry_strategy(50, 10);
377+
let strategy = registry_strategy(50, 10, 50);
377378
for _ in 0..256 {
378379
let PrettyPrintRegistry(input) = strategy
379380
.new_tree(&mut TestRunner::default())
@@ -386,29 +387,17 @@ fn meta_test_deep_trees_from_strategy() {
386387
vec![dep_req(&this.name(), &format!("={}", this.version()))],
387388
&reg,
388389
);
389-
match res {
390-
Ok(r) => {
391-
if r.len() >= 7 {
392-
seen_a_deep_tree = true;
393-
}
394-
}
395-
Err(_) => {
396-
seen_an_error = true;
397-
}
398-
}
399-
if seen_a_deep_tree && seen_an_error {
390+
dis[res.as_ref().map(|x| min(x.len(), dis.len()) - 1).unwrap_or(0)] += 1;
391+
if dis.iter().all(|&x| x > 0) {
400392
return;
401393
}
402394
}
403395
}
404396

405397
assert!(
406-
seen_an_error,
407-
"In 2560 tries we did not see any crates that could not be built!"
408-
);
409-
assert!(
410-
seen_a_deep_tree,
411-
"In 2560 tries we did not see any crates that had more then 7 pkg in the dependency tree!"
398+
dis.iter().all(|&x| x > 0),
399+
"In 2560 tries we did not see a wide enough distribution of dependency trees! dis:{:?}",
400+
dis
412401
);
413402
}
414403

@@ -432,7 +421,7 @@ proptest! {
432421
})]
433422
#[test]
434423
fn limited_independence_of_irrelevant_alternatives(
435-
PrettyPrintRegistry(input) in registry_strategy(50, 10),
424+
PrettyPrintRegistry(input) in registry_strategy(50, 10, 50),
436425
indexs_to_unpublish in vec(any::<prop::sample::Index>(), 10)
437426
) {
438427
let reg = registry(input.clone());

0 commit comments

Comments
 (0)