refactor: create submodules for tests

This commit is contained in:
electria 2026-10-06 16:21:18 -07:00
commit bb985f917a
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs
2 changed files with 74 additions and 66 deletions

View file

@ -192,12 +192,13 @@ impl Function {
} }
#[cfg(test)] #[cfg(test)]
use super::PREC; mod tests {
#[cfg(test)] use super::super::PREC;
use super::*;
use std::assert_matches; use std::assert_matches;
#[test] #[test]
fn test() { fn basic() {
assert_eq!( assert_eq!(
Nodes(vec![ Nodes(vec![
Node::Function(Function::Sine), Node::Function(Function::Sine),
@ -215,9 +216,10 @@ fn test() {
} }
#[test] #[test]
fn test_zerosized() { fn zerosized() {
assert_matches!( assert_matches!(
Nodes(vec![Node::ParenthesisStart, Node::ParenthesisEnd]).evaluate(), Nodes(vec![Node::ParenthesisStart, Node::ParenthesisEnd]).evaluate(),
Err(Error::CollapseFailed(Nodes(v))) if v.is_empty() Err(Error::CollapseFailed(Nodes(v))) if v.is_empty()
) )
} }
}

View file

@ -195,8 +195,12 @@ impl FromStr for Nodes {
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[test] #[test]
fn test() { fn basic() {
assert_eq!( assert_eq!(
Nodes::from_str("sin(2) + 1").unwrap().as_ref(), Nodes::from_str("sin(2) + 1").unwrap().as_ref(),
&[ &[
@ -209,8 +213,9 @@ fn test() {
], ],
) )
} }
#[test] #[test]
fn test_e() { fn e_constant() {
assert_eq!( assert_eq!(
Nodes::from_str("5e * 5").unwrap().as_ref(), Nodes::from_str("5e * 5").unwrap().as_ref(),
&[ &[
@ -223,7 +228,7 @@ fn test_e() {
) )
} }
#[test] #[test]
fn test_unary_op() { fn unary_op() {
assert_eq!( assert_eq!(
Nodes::from_str("5(-5)").unwrap().as_ref(), Nodes::from_str("5(-5)").unwrap().as_ref(),
&[ &[
@ -235,3 +240,4 @@ fn test_unary_op() {
], ],
) )
} }
}