Tests
This commit is contained in:
parent
5e61ee8e70
commit
9c487308be
6 changed files with 127 additions and 11 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use crate::node::Node;
|
||||
use crate::node::node_modifier::NodeModifier;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Formula {
|
||||
|
|
@ -10,7 +11,7 @@ impl Formula {
|
|||
let mut formula = Self {
|
||||
tree: Node::empty(),
|
||||
};
|
||||
formula.tree.modify_tree().add_node(Node::variable());
|
||||
formula.tree.modify_node().add_node(Node::variable());
|
||||
|
||||
formula
|
||||
}
|
||||
|
|
@ -22,4 +23,29 @@ impl Formula {
|
|||
outputs
|
||||
}
|
||||
pub fn mutate(&mut self) {}
|
||||
|
||||
pub fn modify_tree(&mut self) -> NodeModifier {
|
||||
self.tree.modify_tree()
|
||||
}
|
||||
pub fn display_tree(&self) {
|
||||
self.display_recursion(0, vec![&self.tree]);
|
||||
}
|
||||
fn display_recursion(&self, indent_level: u8, nodes: Vec<&Node>) {
|
||||
for node in nodes {
|
||||
if indent_level != 0 {
|
||||
for _ in 0..(indent_level) {
|
||||
print!("|\t");
|
||||
}
|
||||
}
|
||||
println!("{node}");
|
||||
if node.children.len() == 0 {
|
||||
continue;
|
||||
}
|
||||
let mut next_nodes: Vec<&Node> = Vec::new();
|
||||
for node in &node.children {
|
||||
next_nodes.push(node);
|
||||
}
|
||||
self.display_recursion(indent_level + 1, next_nodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue