refactor: sort unit tests
This commit is contained in:
parent
396deba4e1
commit
18a777c449
3 changed files with 35 additions and 35 deletions
|
|
@ -153,3 +153,22 @@ fn collapse_toplevel(nodes: &mut Vec<Node>, mut end: usize) {
|
|||
nodes.remove(start);
|
||||
}
|
||||
}
|
||||
|
||||
use super::PREC;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
assert_eq!(
|
||||
Nodes(vec![
|
||||
Node::Function(Function::Sine),
|
||||
Node::ParenthesisStart,
|
||||
Node::Number(Float::with_val(PREC, 2)),
|
||||
Node::ParenthesisEnd,
|
||||
Node::Operator(Operator::Plus),
|
||||
Node::Number(Float::with_val(PREC, 1))
|
||||
])
|
||||
.evaluate()
|
||||
.to_f64(),
|
||||
1.9092974268256817,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,3 +188,18 @@ impl FromStr for Nodes {
|
|||
Ok(Self(nodes))
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
assert_eq!(
|
||||
Nodes::from_str("sin(2) + 1").unwrap().as_ref(),
|
||||
&[
|
||||
Node::Function(Function::Sine),
|
||||
Node::ParenthesisStart,
|
||||
Node::Number(Float::with_val(PREC, 2)),
|
||||
Node::ParenthesisEnd,
|
||||
Node::Operator(Operator::Plus),
|
||||
Node::Number(Float::with_val(PREC, 1))
|
||||
],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
use core::f64;
|
||||
use std::str::FromStr;
|
||||
|
||||
use rug::Float;
|
||||
|
||||
use crate::nodes::{Function, Node, Nodes, Operator, PREC};
|
||||
use crate::nodes::Nodes;
|
||||
|
||||
fn eval(s: &str) -> f64 {
|
||||
Nodes::from_str(s).unwrap().evaluate().to_f64()
|
||||
|
|
@ -40,35 +38,3 @@ fn unary_operators() {
|
|||
assert_eq!(eval("-10"), -10.);
|
||||
assert_eq!(eval("+10"), 10.);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nodes_to_num() {
|
||||
assert_eq!(
|
||||
Nodes(vec![
|
||||
Node::Function(Function::Sine),
|
||||
Node::ParenthesisStart,
|
||||
Node::Number(Float::with_val(PREC, 2)),
|
||||
Node::ParenthesisEnd,
|
||||
Node::Operator(Operator::Plus),
|
||||
Node::Number(Float::with_val(PREC, 1))
|
||||
])
|
||||
.evaluate()
|
||||
.to_f64(),
|
||||
1.9092974268256817,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nodes_from_str() {
|
||||
assert_eq!(
|
||||
Nodes::from_str("sin(2) + 1").unwrap().as_ref(),
|
||||
&[
|
||||
Node::Function(Function::Sine),
|
||||
Node::ParenthesisStart,
|
||||
Node::Number(Float::with_val(PREC, 2)),
|
||||
Node::ParenthesisEnd,
|
||||
Node::Operator(Operator::Plus),
|
||||
Node::Number(Float::with_val(PREC, 1))
|
||||
],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue