[roads] rename.rs: a new id never spells a word the output already holds
The R-55 property mapped renamed strings back anywhere in the output, so a group renamed to `in` turned every firewall "direction": "in" into the group's old name and failed about once in four runs (seed 8124609985917702487). The renaming now reserves every string the plans and problems hold; the seed is kept as a fixed test, which fails without the reservation. No change to the compiler.
This commit is contained in:
@@ -149,6 +149,31 @@ impl Renaming {
|
||||
for (o, _) in &olds {
|
||||
taken.insert(o.clone());
|
||||
}
|
||||
// `back` maps strings anywhere in the output, so a new id must never spell a word the output already
|
||||
// holds for another reason: a group renamed to `in` turned every firewall `"direction": "in"` into
|
||||
// the group's old name (seed 8124609985917702487). Reserve every string the plans and problems hold.
|
||||
fn strings(v: &Value, out: &mut BTreeSet<String>) {
|
||||
match v {
|
||||
Value::String(s) => {
|
||||
out.insert(s.clone());
|
||||
}
|
||||
Value::Array(a) => a.iter().for_each(|x| strings(x, out)),
|
||||
Value::Object(m) => m.iter().for_each(|(k, x)| {
|
||||
out.insert(k.clone());
|
||||
strings(x, out);
|
||||
}),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let c = compile(
|
||||
&Store::from_parts(&parts.roads, Some(&parts.directory), Some(&parts.devices)),
|
||||
now(),
|
||||
);
|
||||
strings(
|
||||
&serde_json::to_value(c.plans.values().collect::<Vec<_>>()).unwrap(),
|
||||
&mut taken,
|
||||
);
|
||||
strings(&serde_json::to_value(&c.problems).unwrap(), &mut taken);
|
||||
let mut to_new = BTreeMap::new();
|
||||
for (old, kind) in olds {
|
||||
let new = loop {
|
||||
@@ -385,6 +410,13 @@ fn the_extra_roads_reach_the_order_sensitive_paths() {
|
||||
);
|
||||
}
|
||||
|
||||
/// A seed that once renamed the household group to `in`, a word the plans already hold (a firewall
|
||||
/// direction). The renaming must avoid it, not the comparison.
|
||||
#[test]
|
||||
fn a_new_id_never_spells_a_word_of_the_output() {
|
||||
check_isomorphic(8124609985917702487).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_identity_renaming_changes_nothing() {
|
||||
let parts = base_parts();
|
||||
|
||||
Reference in New Issue
Block a user