-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
pub fn change(source: &[f64], length: usize) -> Vec<f64> { | ||
let len = source.len(); | ||
let mut change = vec![0.0; len]; | ||
|
||
if length > len { | ||
return change; | ||
} | ||
|
||
for i in length..len { | ||
change[i] = source[i] - source[i - length]; | ||
} | ||
|
||
change | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_change() { | ||
let source = vec![1.0, 2.0, 3.0, 4.0, 5.0]; | ||
let length = 2; | ||
let expected = vec![0.0, 0.0, 2.0, 2.0, 2.0]; | ||
|
||
let result = change(&source, length); | ||
|
||
assert_eq!(result, expected); | ||
} | ||
|
||
#[test] | ||
fn test_change_zero_length() { | ||
let source = vec![1.0, 2.0, 3.0, 4.0, 5.0]; | ||
let length = 0; | ||
let expected = vec![0.0, 0.0, 0.0, 0.0, 0.0]; | ||
|
||
let result = change(&source, length); | ||
|
||
assert_eq!(result, expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod change; | ||
pub mod highest; | ||
pub mod lowest; | ||
pub mod nz; | ||
|