Skip to content

Commit

Permalink
fix kinda odd bug in matching
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-duarte-ifood committed Oct 13, 2023
1 parent 2513aa4 commit 126fc51
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion matching/src/ordered_tree_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn ordered_tree_matching_helper(

let matching = MatchingEntry::new(
matrix_m[m][n] + root_matching,
2 * matrix_m[m][n] / (m + n) == 1,
left == right,
);
let mut result = HashMap::new();
result.insert(
Expand Down Expand Up @@ -325,4 +325,38 @@ mod tests {
matchings.get_matching_entry(left, right)
)
}

#[test]
fn perfect_matching_deeper_nodes() {
let leaf = CSTNode::Terminal {
kind: "kind_b".into(),
value: "value_b".into(),
};

let intermediate = CSTNode::NonTerminal {
kind: "intermediate".into(),
children: vec![leaf],
};

let left = CSTNode::NonTerminal {
kind: "kind_a".to_owned(),
children: vec![intermediate.clone()],
};
let right = CSTNode::NonTerminal {
kind: "kind_a".to_owned(),
children: vec![intermediate.clone()],
};

let matchings = ordered_tree_matching(&left, &right);

assert_eq!(
Some(&MatchingEntry::new(2, true)),
matchings.get_matching_entry(intermediate.clone(), intermediate)
);

assert_eq!(
Some(&MatchingEntry::new(3, true)),
matchings.get_matching_entry(left, right)
)
}
}

0 comments on commit 126fc51

Please sign in to comment.