@@ -52,44 +52,41 @@ pub fn black_scholes(
5252#[ cfg( test) ]
5353mod tests {
5454 use super :: * ;
55-
56- #[ test]
57- fn my_test ( ) {
58- macro_rules! test_black_scholes {
59- ( $( $name: ident: $inputs: expr, ) * ) => {
60- $(
61- fn $name( ) {
62- let ( spot_price, strike_price, time_to_maturity, risk_free_rate, volatility) = $inputs;
63- let expected = black_scholes( spot_price, strike_price, time_to_maturity, risk_free_rate, volatility) . unwrap( ) ;
64- assert!( expected >= 0.0 ) ;
65- }
66- ) *
67- }
55+ macro_rules! test_black_scholes {
56+ ( $( $name: ident: $inputs: expr, ) * ) => {
57+ $(
58+ #[ test]
59+ fn $name( ) {
60+ let ( spot_price, strike_price, time_to_maturity, risk_free_rate, volatility) = $inputs;
61+ let expected = black_scholes( spot_price, strike_price, time_to_maturity, risk_free_rate, volatility) . unwrap( ) ;
62+ assert!( expected >= 0.0 ) ;
63+ }
64+ ) *
6865 }
66+ }
6967
70- macro_rules! test_black_scholes_Err {
71- ( $( $name: ident: $inputs: expr, ) * ) => {
72- $(
73- #[ test]
74- fn $name( ) {
75- let ( spot_price, strike_price, time_to_maturity, risk_free_rate, volatility) = $inputs;
76- assert_eq!( black_scholes( spot_price, strike_price, time_to_maturity, risk_free_rate, volatility) . unwrap_err( ) , BlackScholesError :: InvalidParameters ) ;
77- }
78- ) *
79- }
68+ macro_rules! test_black_scholes_Err {
69+ ( $( $name: ident: $inputs: expr, ) * ) => {
70+ $(
71+ #[ test]
72+ fn $name( ) {
73+ let ( spot_price, strike_price, time_to_maturity, risk_free_rate, volatility) = $inputs;
74+ assert_eq!( black_scholes( spot_price, strike_price, time_to_maturity, risk_free_rate, volatility) . unwrap_err( ) , BlackScholesError :: InvalidParameters ) ;
75+ }
76+ ) *
8077 }
78+ }
8179
82- test_black_scholes ! {
83- valid_parameters: ( 100.0 , 100.0 , 1.0 , 0.05 , 0.2 ) ,
84- another_valid_case: ( 150.0 , 100.0 , 2.0 , 0.03 , 0.25 ) ,
85- }
80+ test_black_scholes ! {
81+ valid_parameters: ( 100.0 , 100.0 , 1.0 , 0.05 , 0.2 ) ,
82+ another_valid_case: ( 150.0 , 100.0 , 2.0 , 0.03 , 0.25 ) ,
83+ }
8684
87- test_black_scholes_Err ! {
88- negative_spot_price: ( -100.0 , 100.0 , 1.0 , 0.05 , 0.2 ) ,
89- zero_strike_price: ( 100.0 , 0.0 , 1.0 , 0.05 , 0.2 ) ,
90- negative_time_to_maturity: ( 100.0 , 100.0 , -1.0 , 0.05 , 0.2 ) ,
91- negative_risk_free_rate: ( 100.0 , 100.0 , 1.0 , -0.05 , 0.2 ) ,
92- negative_volatility: ( 100.0 , 100.0 , 1.0 , 0.05 , -0.2 ) ,
93- }
85+ test_black_scholes_Err ! {
86+ negative_spot_price: ( -100.0 , 100.0 , 1.0 , 0.05 , 0.2 ) ,
87+ zero_strike_price: ( 100.0 , 0.0 , 1.0 , 0.05 , 0.2 ) ,
88+ negative_time_to_maturity: ( 100.0 , 100.0 , -1.0 , 0.05 , 0.2 ) ,
89+ negative_risk_free_rate: ( 100.0 , 100.0 , 1.0 , -0.05 , 0.2 ) ,
90+ negative_volatility: ( 100.0 , 100.0 , 1.0 , 0.05 , -0.2 ) ,
9491 }
9592}
0 commit comments