fix: pass dag prop test

This commit is contained in:
Zixuan Chen 2022-10-17 14:45:24 +08:00
parent 906aebfa8a
commit 56be50c1b6
2 changed files with 34 additions and 22 deletions

View file

@ -353,24 +353,25 @@ where
} }
} }
// if top nodes are from the same client with different source, we find a shared node // // if top nodes are from the same client with different source, we find a shared node
if let Some((other_node, other_type)) = queue.peek() { // if let Some((other_node, other_type)) = queue.peek() {
if node_type != *other_type && node.id.client_id == other_node.id.client_id { // if node_type != *other_type && node.id.client_id == other_node.id.client_id {
if node_type != NodeType::Shared { // if node_type != NodeType::Shared {
ans.push(ID { // debug_assert!(other_node.id.counter < node.id.counter);
client_id: node.id.client_id, // ans.push(ID {
counter: node.id.counter.min(other_node.id.counter), // client_id: node.id.client_id,
}); // counter: other_node.id.counter,
node_type = NodeType::Shared; // });
} // node_type = NodeType::Shared;
match other_type { // }
NodeType::A => a_count -= 1, // match other_type {
NodeType::B => b_count -= 1, // NodeType::A => a_count -= 1,
NodeType::Shared => {} // NodeType::B => b_count -= 1,
} // NodeType::Shared => {}
queue.pop(); // }
} // queue.pop();
} // }
// }
// detect whether client is visited by other // detect whether client is visited by other
if let Some((ctr, visited_type)) = visited.get_mut(&node.id.client_id) { if let Some((ctr, visited_type)) = visited.get_mut(&node.id.client_id) {

View file

@ -580,12 +580,12 @@ mod find_common_ancestors_proptest {
fn issue() { fn issue() {
if let Err(err) = test_mul_ancestors::<3>( if let Err(err) = test_mul_ancestors::<3>(
10, 10,
vec![],
vec![Interaction { vec![Interaction {
dag_idx: 4, dag_idx: 2,
merge_with: Some(2), merge_with: Some(5),
len: 1, len: 1,
}], }],
vec![],
) { ) {
println!("{}", err); println!("{}", err);
panic!(); panic!();
@ -681,7 +681,18 @@ mod find_common_ancestors_proptest {
dags.push(TestDag::new(i as ClientID)); dags.push(TestDag::new(i as ClientID));
} }
for interaction in before_merge_insertion { for mut interaction in before_merge_insertion {
if interaction.dag_idx < N {
// cannot act on first N nodes
interaction.dag_idx = interaction.dag_idx % (dags.len() - N) + N;
}
if let Some(merge) = interaction.merge_with {
if interaction.dag_idx == merge {
let next_merge = (merge + 1) % dags.len();
interaction.merge_with = Some(next_merge);
}
}
apply(interaction, &mut dags); apply(interaction, &mut dags);
} }