It doesn't work
This commit is contained in:
parent
b521356cc9
commit
c71ed10e76
5 changed files with 81 additions and 25 deletions
21
src/tests.rs
21
src/tests.rs
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{formula::Formula, node::Node};
|
||||
use crate::{formula::Formula, learner::Learner, node::Node};
|
||||
|
||||
#[test]
|
||||
fn test_node_variable() {
|
||||
|
|
@ -17,7 +17,8 @@ fn test_plus_one() {
|
|||
Node::function(
|
||||
"+1".to_string(),
|
||||
|inputs: Vec<f64>| inputs[0] + 1f64,
|
||||
Some(1)
|
||||
Some(1),
|
||||
1
|
||||
),
|
||||
None
|
||||
)
|
||||
|
|
@ -35,7 +36,7 @@ fn test_branch_sum() {
|
|||
formula
|
||||
.modify_tree()
|
||||
.insert_node(
|
||||
Node::function("Sum".to_string(), |inputs| inputs.iter().sum(), Some(2)),
|
||||
Node::function("Sum".to_string(), |inputs| inputs.iter().sum(), Some(2), 0),
|
||||
None
|
||||
)
|
||||
.is_err()
|
||||
|
|
@ -60,7 +61,7 @@ fn test_display_as_text() {
|
|||
formula
|
||||
.modify_tree()
|
||||
.insert_node(
|
||||
Node::function("sum".to_string(), |inputs| inputs.iter().sum(), None),
|
||||
Node::function("sum".to_string(), |inputs| inputs.iter().sum(), None, 0),
|
||||
None
|
||||
)
|
||||
.is_err()
|
||||
|
|
@ -73,7 +74,8 @@ fn test_display_as_text() {
|
|||
.add_node(Node::function(
|
||||
"sin".to_string(),
|
||||
|inputs| inputs[0].sin(),
|
||||
Some(1)
|
||||
Some(1),
|
||||
0
|
||||
))
|
||||
.is_err()
|
||||
== false
|
||||
|
|
@ -89,3 +91,12 @@ fn test_display_as_text() {
|
|||
);
|
||||
assert_eq!(formula.as_text(), "sum(X,sin(X))".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_2x() {
|
||||
let inputs = vec![0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.];
|
||||
let outputs = vec![0., 2., 4., 6., 8., 10., 12., 14., 16., 18., 20., 22., 24.];
|
||||
let mut learner = Learner::new(inputs.clone(), outputs.clone(), None, None);
|
||||
let formula = learner.calculate_formula();
|
||||
assert_eq!(formula.run(inputs), outputs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue