|
|
|
|
| use super::nodes::{AstNode, NodeType};
|
|
|
|
|
| pub fn edge_weight(from: &AstNode, to: &AstNode) -> f64 {
|
| match (from.node_type.is_payload(), to.node_type.is_structural()) {
|
|
|
| (true, true) => 0.0,
|
|
|
| (false, true) => 0.1,
|
|
|
| (false, false) => 0.5,
|
|
|
| (true, false) => 0.0,
|
| }
|
| }
|
|
|
|
|
| pub fn has_dangerous_pattern(from: &AstNode, to: &AstNode) -> bool {
|
|
|
| from.node_type.is_payload() && to.node_type.is_structural()
|
| }
|
|
|
| #[cfg(test)]
|
| mod tests {
|
| use super::*;
|
|
|
| #[test]
|
| fn payload_cannot_reach_structural() {
|
| let payload = AstNode::new(NodeType::Word, "hello");
|
| let structural = AstNode::new(NodeType::Intent, "route");
|
| assert_eq!(edge_weight(&payload, &structural), 0.0);
|
| assert!(has_dangerous_pattern(&payload, &structural));
|
| }
|
|
|
| #[test]
|
| fn structural_can_reach_payload() {
|
| let structural = AstNode::new(NodeType::Intent, "route");
|
| let payload = AstNode::new(NodeType::Word, "hello");
|
| assert_eq!(edge_weight(&structural, &payload), 0.1);
|
| assert!(!has_dangerous_pattern(&structural, &payload));
|
| }
|
| }
|
|
|