basic tests done, fixed children calculation problem
This commit is contained in:
parent
9c487308be
commit
7a98924965
3 changed files with 11 additions and 18 deletions
16
src/main.rs
16
src/main.rs
|
|
@ -5,18 +5,4 @@ mod node;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
fn main() {
|
fn main() {}
|
||||||
let mut formula = Formula::new();
|
|
||||||
formula
|
|
||||||
.modify_tree()
|
|
||||||
.insert_node(Node::function(|inputs| inputs.iter().sum(), Some(2)), None);
|
|
||||||
if let Err(x) = formula
|
|
||||||
.modify_tree()
|
|
||||||
.go_down(0)
|
|
||||||
.add_node(Node::number(1f64))
|
|
||||||
{
|
|
||||||
println!("{x}");
|
|
||||||
}
|
|
||||||
formula.display_tree();
|
|
||||||
let results = formula.run(vec![0f64, 1f64, 2f64, 3f64, 4f64, 5f64]);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ impl<'a> NodeModifier<'a> {
|
||||||
|
|
||||||
pub fn add_node(&mut self, node: Node) -> Result<(), NodeManipulationError> {
|
pub fn add_node(&mut self, node: Node) -> Result<(), NodeManipulationError> {
|
||||||
if let Some(x) = self.picked_node.max_children_count {
|
if let Some(x) = self.picked_node.max_children_count {
|
||||||
if self.picked_node.children.len() + 1 >= x {
|
if self.picked_node.children.len() + 1 > x {
|
||||||
return Err(NodeManipulationError::TooMuchChildren(node));
|
return Err(NodeManipulationError::TooMuchChildren(node));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +105,7 @@ impl<'a> NodeModifier<'a> {
|
||||||
between: Option<usize>,
|
between: Option<usize>,
|
||||||
) -> Result<(), NodeManipulationError> {
|
) -> Result<(), NodeManipulationError> {
|
||||||
if let Some(x) = self.picked_node.max_children_count {
|
if let Some(x) = self.picked_node.max_children_count {
|
||||||
if self.picked_node.children.len() + 1 >= x {
|
if self.picked_node.children.len() + 1 > x {
|
||||||
return Err(NodeManipulationError::TooMuchChildren(node));
|
return Err(NodeManipulationError::TooMuchChildren(node));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,14 @@ fn test_branch_sum() {
|
||||||
.is_err()
|
.is_err()
|
||||||
== false
|
== false
|
||||||
);
|
);
|
||||||
assert!(formula.modify_tree().add_node(Node::number(1f64)).is_err() == false);
|
assert!(
|
||||||
|
formula
|
||||||
|
.modify_tree()
|
||||||
|
.go_down(0)
|
||||||
|
.add_node(Node::number(1f64))
|
||||||
|
.is_err()
|
||||||
|
== false
|
||||||
|
);
|
||||||
formula.display_tree();
|
formula.display_tree();
|
||||||
let results = formula.run(vec![0f64, 1f64, 2f64, 3f64, 4f64, 5f64]);
|
let results = formula.run(vec![0f64, 1f64, 2f64, 3f64, 4f64, 5f64]);
|
||||||
assert_eq!(results, vec![1f64, 2f64, 3f64, 4f64, 5f64, 6f64])
|
assert_eq!(results, vec![1f64, 2f64, 3f64, 4f64, 5f64, 6f64])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue