From d665b72a4c8b727bcff56798effe07c98e3f0c18 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 18 May 2022 14:55:30 -0400 Subject: [PATCH] improve newtons_method test --- tests/misc.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/misc.rs b/tests/misc.rs index bff9109..a237002 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -170,8 +170,35 @@ fn newtons_method() { &|x: f64| x.powf(2.0) - 1.0, &|x: f64| 2.0 * x, &3.0, - &(0.0..10.0), + &(0.0..5.0), &f64::EPSILON, ); assert_eq!(data, Some(1.0)); + + let data = newtons_method( + &|x: f64| x.sin(), + &|x: f64| x.cos(), + &3.0, + &(2.95..3.18), + &f64::EPSILON, + ); + assert_eq!(data, Some(std::f64::consts::PI)); + + let data = newtons_method( + &|x: f64| x.sin(), + &|_: f64| f64::NAN, + &0.0, + &(-10.0..10.0), + &f64::EPSILON, + ); + assert_eq!(data, None); + + let data = newtons_method( + &|_: f64| f64::NAN, + &|x: f64| x.sin(), + &0.0, + &(-10.0..10.0), + &f64::EPSILON, + ); + assert_eq!(data, None); }