Tests
This commit is contained in:
parent
5e61ee8e70
commit
9c487308be
6 changed files with 127 additions and 11 deletions
|
|
@ -1,15 +1,17 @@
|
|||
use std::fmt;
|
||||
|
||||
use crate::node::node_modifier::NodeModifier;
|
||||
use handler::*;
|
||||
|
||||
mod functions;
|
||||
mod handler;
|
||||
mod node_modifier;
|
||||
pub mod node_modifier;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Node {
|
||||
children: Vec<Node>,
|
||||
handler: NodeHandler,
|
||||
max_children_count: Option<usize>,
|
||||
pub(crate) children: Vec<Node>,
|
||||
pub(crate) handler: NodeHandler,
|
||||
pub(crate) max_children_count: Option<usize>,
|
||||
}
|
||||
|
||||
impl Node {
|
||||
|
|
@ -63,7 +65,25 @@ impl Node {
|
|||
|
||||
return self.handler.run(inputs, passed_x);
|
||||
}
|
||||
pub fn modify_tree(&mut self) -> NodeModifier {
|
||||
pub fn modify_node(&mut self) -> NodeModifier {
|
||||
NodeModifier::from_random(self, None)
|
||||
}
|
||||
pub fn modify_tree(&mut self) -> NodeModifier {
|
||||
NodeModifier::from_node(self, None)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Node {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self.handler {
|
||||
NodeHandler::Number { number } => number.to_string(),
|
||||
NodeHandler::Function { function } => "Function".to_string(),
|
||||
NodeHandler::Variable => "X".to_string(),
|
||||
NodeHandler::Empty => "Empty".to_string(),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue