refactor: create submodules for tests
This commit is contained in:
parent
00dfcdb10c
commit
bb985f917a
2 changed files with 74 additions and 66 deletions
|
|
@ -192,32 +192,34 @@ impl Function {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
use super::PREC;
|
||||
#[cfg(test)]
|
||||
use std::assert_matches;
|
||||
mod tests {
|
||||
use super::super::PREC;
|
||||
use super::*;
|
||||
use std::assert_matches;
|
||||
|
||||
#[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()
|
||||
.unwrap()
|
||||
.to_f64(),
|
||||
1.9092974268256817,
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn basic() {
|
||||
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()
|
||||
.unwrap()
|
||||
.to_f64(),
|
||||
1.9092974268256817,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zerosized() {
|
||||
assert_matches!(
|
||||
Nodes(vec![Node::ParenthesisStart, Node::ParenthesisEnd]).evaluate(),
|
||||
Err(Error::CollapseFailed(Nodes(v))) if v.is_empty()
|
||||
)
|
||||
#[test]
|
||||
fn zerosized() {
|
||||
assert_matches!(
|
||||
Nodes(vec![Node::ParenthesisStart, Node::ParenthesisEnd]).evaluate(),
|
||||
Err(Error::CollapseFailed(Nodes(v))) if v.is_empty()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,43 +195,49 @@ impl FromStr for Nodes {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
assert_eq!(
|
||||
Nodes::from_str("sin(2) + 1").unwrap().as_ref(),
|
||||
&[
|
||||
Node::Function(Function::Sine),
|
||||
Node::ParenthesisStart,
|
||||
Node::from(2),
|
||||
Node::ParenthesisEnd,
|
||||
Node::Operator(Operator::Plus),
|
||||
Node::from(1),
|
||||
],
|
||||
)
|
||||
}
|
||||
#[test]
|
||||
fn test_e() {
|
||||
assert_eq!(
|
||||
Nodes::from_str("5e * 5").unwrap().as_ref(),
|
||||
&[
|
||||
Node::from(5),
|
||||
Node::Operator(Operator::Mult),
|
||||
Node::from(f64::consts::E),
|
||||
Node::Operator(Operator::Mult),
|
||||
Node::from(5),
|
||||
],
|
||||
)
|
||||
}
|
||||
#[test]
|
||||
fn test_unary_op() {
|
||||
assert_eq!(
|
||||
Nodes::from_str("5(-5)").unwrap().as_ref(),
|
||||
&[
|
||||
Node::from(5),
|
||||
Node::Operator(Operator::Mult),
|
||||
Node::ParenthesisStart,
|
||||
Node::from(-5),
|
||||
Node::ParenthesisEnd,
|
||||
],
|
||||
)
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
assert_eq!(
|
||||
Nodes::from_str("sin(2) + 1").unwrap().as_ref(),
|
||||
&[
|
||||
Node::Function(Function::Sine),
|
||||
Node::ParenthesisStart,
|
||||
Node::from(2),
|
||||
Node::ParenthesisEnd,
|
||||
Node::Operator(Operator::Plus),
|
||||
Node::from(1),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn e_constant() {
|
||||
assert_eq!(
|
||||
Nodes::from_str("5e * 5").unwrap().as_ref(),
|
||||
&[
|
||||
Node::from(5),
|
||||
Node::Operator(Operator::Mult),
|
||||
Node::from(f64::consts::E),
|
||||
Node::Operator(Operator::Mult),
|
||||
Node::from(5),
|
||||
],
|
||||
)
|
||||
}
|
||||
#[test]
|
||||
fn unary_op() {
|
||||
assert_eq!(
|
||||
Nodes::from_str("5(-5)").unwrap().as_ref(),
|
||||
&[
|
||||
Node::from(5),
|
||||
Node::Operator(Operator::Mult),
|
||||
Node::ParenthesisStart,
|
||||
Node::from(-5),
|
||||
Node::ParenthesisEnd,
|
||||
],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue