Skip to content

Commit

Permalink
chore: clippy warnings fix
Browse files Browse the repository at this point in the history
  • Loading branch information
amv-dev committed Jun 9, 2021
1 parent 4ba2110 commit 53f6d9b
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 68 deletions.
4 changes: 2 additions & 2 deletions src/core/candles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ mod tests {
Source::HL2,
];

values.iter().for_each(|&v| {
for &v in &values {
let r1: String = v.into();
let r2: &str = v.into();

Expand All @@ -252,7 +252,7 @@ mod tests {
Source::TP => assert_eq!("tp", r1),
Source::HL2 => assert_eq!("hl2", r1),
}
});
}
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/core/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,10 @@ mod tests {
for length in 1..255 {
let mut w = Window::new(length, data[0]);

data.iter().for_each(|&c| {
for &c in &data {
w.push(c);
assert_eq!(c, w.newest());
});
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/methods/collapse_timeframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mod tests {
for length in 2..10 {
let mut method = TestingMethod::new(length, &candles[0]).unwrap();

let converted = candles.iter().flat_map(|x| method.next(x));
let converted = candles.iter().filter_map(|x| method.next(x));

candles
.windows(length)
Expand Down
24 changes: 14 additions & 10 deletions src/methods/ema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,15 @@ mod tests {
let alpha = 2. / (length + 1) as ValueType;

let mut prev_value = src[0];
src.iter().for_each(|&x| {
for &x in &src {
let value = ma.next(x);

let value2 = alpha * x + (1. - alpha) * prev_value;

prev_value = value2;

assert_eq_float(value2, value);
});
}
});
}

Expand Down Expand Up @@ -386,7 +386,8 @@ mod tests {

let mut prev_value1 = src[0];
let mut prev_value2 = src[0];
src.iter().for_each(|&x| {

for &x in &src {
let value = ma.next(x);

let ema1 = alpha * x + (1. - alpha) * prev_value1;
Expand All @@ -398,7 +399,7 @@ mod tests {
let value2 = ema2;

assert_eq_float(value2, value);
});
}
});
}

Expand Down Expand Up @@ -439,7 +440,8 @@ mod tests {

let mut prev_value1 = src[0];
let mut prev_value2 = src[0];
src.iter().for_each(|&x| {

for &x in &src {
let value = ma.next(x);

let ema1 = alpha * x + (1. - alpha) * prev_value1;
Expand All @@ -451,7 +453,7 @@ mod tests {
let value2 = 2. * ema1 - ema2;

assert_eq_float(value2, value);
});
}
});
}

Expand Down Expand Up @@ -493,7 +495,8 @@ mod tests {
let mut prev_value1 = src[0];
let mut prev_value2 = src[0];
let mut prev_value3 = src[0];
src.iter().for_each(|&x| {

for &x in &src {
let value = ma.next(x);

let ema1 = alpha * x + (1. - alpha) * prev_value1;
Expand All @@ -507,7 +510,7 @@ mod tests {
let value2 = ema3;

assert_eq_float(value2, value);
});
}
});
}

Expand Down Expand Up @@ -549,7 +552,8 @@ mod tests {
let mut prev_value1 = src[0];
let mut prev_value2 = src[0];
let mut prev_value3 = src[0];
src.iter().for_each(|&x| {

for &x in &src {
let value = ma.next(x);

let e_ma = alpha * x + (1. - alpha) * prev_value1;
Expand All @@ -563,7 +567,7 @@ mod tests {
let value2 = 3. * e_ma - 3. * d_ma + t_ma;

assert_eq_float(value2, value);
});
}
});
}
}
4 changes: 2 additions & 2 deletions src/methods/hma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ mod tests {

let mut ma = TestingMethod::new(length, src[0]).unwrap();

src.iter().for_each(|&x| {
for &x in &src {
let value1 = ma.next(x);
let value2 = wma3.next(2. * wma2.next(x) - wma1.next(x));
assert_eq_float(value2, value1);
});
}
});
}
}
10 changes: 4 additions & 6 deletions src/methods/lin_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ mod tests {

let src: Vec<ValueType> = candles.take(300).map(|x| x.close).collect();

[
2, 3, 4, 5, 6, 7, 10, 11, 13, 17, 20, 21, 22, 25, 70, 77, 100, 125, 128, 173, 254,
]
.iter()
.for_each(|&length| {
for &length in &[
2, 3, 4, 5, 7, 10, 11, 13, 17, 20, 21, 25, 70, 77, 100, 125, 128, 173, 254,
] {
let mut ma = TestingMethod::new(length, src[0]).unwrap();
let length = length as usize;

Expand All @@ -165,6 +163,6 @@ mod tests {

assert_eq_float(b, ma_value);
});
});
}
}
}
5 changes: 3 additions & 2 deletions src/methods/rma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ mod tests {
let mut ma = TestingMethod::new(length, src[0]).unwrap();

let mut value2 = src[0];
src.iter().for_each(|&x| {

for &x in &src {
let value = ma.next(x);

value2 = (x + (length - 1) as ValueType * value2) / (length as ValueType);

assert_eq_float(value2, value);
});
}
});
}
}
72 changes: 35 additions & 37 deletions src/methods/smm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,43 +313,41 @@ mod tests {

let src: Vec<ValueType> = candles.take(3000).map(|x| x.close).collect();

[1, 2, 3, 5, 11, 23, 51, 100, 150, 203, 254]
.iter()
.for_each(|&ma_length| {
let mut ma = TestingMethod::new(ma_length, src[0]).unwrap();
let ma_length = ma_length as usize;

src.iter().enumerate().for_each(|(i, &x)| {
let value = ma.next(x);
let slice_from = i.saturating_sub(ma_length - 1);
let slice_to = i;
let mut slice = Vec::with_capacity(ma_length);

src.iter()
.skip(slice_from)
.take(slice_to - slice_from + 1)
.for_each(|&x| slice.push(x));

while slice.len() < ma_length {
slice.push(src[0]);
}

slice.sort_by(|a, b| a.partial_cmp(b).unwrap());

assert_eq!(slice.len(), ma.slice.len());

slice
.iter()
.zip(ma.slice.iter())
.for_each(|(&a, &b)| assert_eq!(a.to_bits(), b.to_bits()));

let value2 = if ma_length % 2 == 0 {
(slice[ma_length / 2] + slice[ma_length / 2 - 1]) / 2.0
} else {
slice[ma_length / 2]
};
assert_eq_float(value2, value);
});
for &ma_length in &[1, 2, 3, 5, 11, 23, 51, 100, 150, 203, 254] {
let mut ma = TestingMethod::new(ma_length, src[0]).unwrap();
let ma_length = ma_length as usize;

src.iter().enumerate().for_each(|(i, &x)| {
let value = ma.next(x);
let slice_from = i.saturating_sub(ma_length - 1);
let slice_to = i;
let mut slice = Vec::with_capacity(ma_length);

src.iter()
.skip(slice_from)
.take(slice_to - slice_from + 1)
.for_each(|&x| slice.push(x));

while slice.len() < ma_length {
slice.push(src[0]);
}

slice.sort_by(|a, b| a.partial_cmp(b).unwrap());

assert_eq!(slice.len(), ma.slice.len());

slice
.iter()
.zip(ma.slice.iter())
.for_each(|(&a, &b)| assert_eq!(a.to_bits(), b.to_bits()));

let value2 = if ma_length % 2 == 0 {
(slice[ma_length / 2] + slice[ma_length / 2 - 1]) / 2.0
} else {
slice[ma_length / 2]
};
assert_eq_float(value2, value);
});
}
}
}
4 changes: 2 additions & 2 deletions src/methods/swma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
],
];

weights.iter().for_each(|weights| {
for weights in &weights {
let wsum: ValueType = weights.iter().sum();
let length = weights.len();

Expand All @@ -182,6 +182,6 @@ mod tests {
assert_eq_float(value2, value);
assert_eq_float(value3, value);
});
});
}
}
}
4 changes: 2 additions & 2 deletions src/methods/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ mod tests {
let mut tr = TestingMethod::new(&src[0]).unwrap();
let mut prev_close = src[0].close;

src.iter().for_each(|c| {
for c in &src {
let value = (c.high - c.low)
.max((c.high - prev_close).abs())
.max((c.low - prev_close).abs());
Expand All @@ -103,6 +103,6 @@ mod tests {
prev_close = c.close;
assert_eq_float(value, value2);
assert_eq_float(value, value3);
});
}
}
}
5 changes: 3 additions & 2 deletions src/methods/wsma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ mod tests {
let mut ma = TestingMethod::new(length, src[0]).unwrap();

let mut prev_value = src[0];
src.iter().for_each(|&x| {

for &x in &src {
let value = ma.next(x);

let value2 = prev_value + (x - prev_value) / length as ValueType;

prev_value = value2;

assert_eq_float(value2, value);
});
}
});
}
}

0 comments on commit 53f6d9b

Please sign in to comment.