From 18a777c449bbf4a6e514fed015c902e06515b2f4 Mon Sep 17 00:00:00 2001 From: electria Date: Wed, 30 Sep 2026 15:40:26 -0700 Subject: [PATCH] refactor: sort unit tests --- src/nodes/evaluate.rs | 19 +++++++++++++++++++ src/nodes/from_str.rs | 15 +++++++++++++++ src/nodes/tests.rs | 36 +----------------------------------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/nodes/evaluate.rs b/src/nodes/evaluate.rs index f585097..9c2be17 100644 --- a/src/nodes/evaluate.rs +++ b/src/nodes/evaluate.rs @@ -153,3 +153,22 @@ fn collapse_toplevel(nodes: &mut Vec, 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, + ); +} diff --git a/src/nodes/from_str.rs b/src/nodes/from_str.rs index 189f14c..07f6d4c 100644 --- a/src/nodes/from_str.rs +++ b/src/nodes/from_str.rs @@ -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)) + ], + ) +} diff --git a/src/nodes/tests.rs b/src/nodes/tests.rs index 413d5d1..439acf4 100644 --- a/src/nodes/tests.rs +++ b/src/nodes/tests.rs @@ -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)) - ], - ) -}