Skip to content

Commit cfe6205

Browse files
committed
fix errors clippy
1 parent 8d4cc7e commit cfe6205

File tree

6 files changed

+48
-41
lines changed

6 files changed

+48
-41
lines changed

src/financial/black_scholes.rs

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,44 +52,41 @@ pub fn black_scholes(
5252
#[cfg(test)]
5353
mod 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
}

src/general/huffman_encoding.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ mod tests {
174174
use super::*;
175175
fn get_frequency(bytes: &[u8]) -> Vec<(u8, u64)> {
176176
let mut cnts: Vec<u64> = vec![0; 256];
177-
bytes.iter().for_each(|&b| cnts[b as usize] += 1);
177+
for &b in bytes.iter() {
178+
cnts[b as usize] += 1;
179+
}
178180
let mut result = vec![];
179181
cnts.iter()
180182
.enumerate()

src/geometry/ramer_douglas_peucker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ mod tests {
104104

105105
assert_eq!(ramer_douglas_peucker(&[], epsilon), vec![]);
106106
assert_eq!(
107-
ramer_douglas_peucker(&[a.clone()], epsilon),
107+
ramer_douglas_peucker(std::slice::from_ref(&a), epsilon),
108108
vec![a.clone()]
109109
);
110110
assert_eq!(

src/graph/graph_enumeration.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ mod tests {
4141
let mut result = enumerate_graph(&graph);
4242
let expected = vec![vec![], vec![2, 3], vec![1, 3, 4], vec![1, 2], vec![2]];
4343

44-
result.iter_mut().for_each(|v| v.sort_unstable());
44+
for v in result.iter_mut() {
45+
v.sort_unstable();
46+
}
4547
assert_eq!(result, expected);
4648
}
4749

@@ -55,7 +57,9 @@ mod tests {
5557
let mut result = enumerate_graph(&graph);
5658
let expected = vec![vec![], vec![2, 3], vec![1, 3, 4], vec![1, 2], vec![2]];
5759

58-
result.iter_mut().for_each(|v| v.sort_unstable());
60+
for v in result.iter_mut() {
61+
v.sort_unstable();
62+
}
5963
assert_eq!(result, expected);
6064
}
6165
}

src/math/fast_fourier_transform.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ mod tests {
192192
polynomial.append(&mut vec![0.0; 4]);
193193
let permutation = fast_fourier_transform_input_permutation(polynomial.len());
194194
let mut fft = fast_fourier_transform(&polynomial, &permutation);
195-
fft.iter_mut().for_each(|num| *num *= *num);
195+
for num in fft.iter_mut() {
196+
*num *= *num;
197+
}
196198
let ifft = inverse_fast_fourier_transform(&fft, &permutation);
197199
let expected = [1.0, 2.0, 1.0, 4.0, 4.0, 0.0, 4.0, 0.0, 0.0];
198200
for (x, y) in ifft.iter().zip(expected.iter()) {
@@ -210,7 +212,9 @@ mod tests {
210212
polynomial.append(&mut vec![0.0f64; n]);
211213
let permutation = fast_fourier_transform_input_permutation(polynomial.len());
212214
let mut fft = fast_fourier_transform(&polynomial, &permutation);
213-
fft.iter_mut().for_each(|num| *num *= *num);
215+
for num in fft.iter_mut() {
216+
*num *= *num;
217+
}
214218
let ifft = inverse_fast_fourier_transform(&fft, &permutation);
215219
let expected = (0..((n << 1) - 1)).map(|i| std::cmp::min(i + 1, (n << 1) - 1 - i) as f64);
216220
for (&x, y) in ifft.iter().zip(expected) {

src/math/pollard_rho.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ mod test {
201201
use super::*;
202202

203203
fn check_is_proper_factor(number: u64, factor: u64) -> bool {
204-
factor > 1 && factor < number && ((number % factor) == 0)
204+
factor > 1 && factor < number && number.is_multiple_of(factor)
205205
}
206206

207207
fn check_factorization(number: u64, factors: &[u64]) -> bool {

0 commit comments

Comments
 (0)