-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathstat.rs
More file actions
30 lines (26 loc) · 677 Bytes
/
stat.rs
File metadata and controls
30 lines (26 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
extern crate peroxide;
use peroxide::fuga::*;
#[test]
fn test_mean() {
let a: Vec<f32> = vec![1.0, 2.0, 3.0, 4.0, 5.0];
assert_eq!(a.mean(), 3.0);
}
#[test]
fn test_mean_stable() {
let a: Vec<f32> = vec![1.0; 10000000];
let diff = 10000.0;
let b = a.iter().map(|x| x + diff).collect::<Vec<f32>>();
assert_eq!(a.mean(), b.mean() - diff);
}
#[test]
fn test_variance() {
let a = vec![1.0, 2.0, 3.0, 4.0, 5.0];
assert_eq!(a.var(), 2.5);
}
#[test]
fn test_variance_stable() {
let a = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let diff = 1000000000.0;
let b = a.iter().map(|x| x + diff).collect::<Vec<f64>>();
assert_eq!(a.var(), b.var());
}