Added more tests for rand regarding relative error

This commit is contained in:
David Harris 2017-02-26 10:42:51 -06:00
parent d6d52824d2
commit 191aab4810

View file

@ -62,7 +62,11 @@ fn monte_carlo(a: f32, b: f32, n: u32) -> f32 {
}
fn main() {
println!("{}", monte_carlo(0., f32::consts::PI, 200_000));
let actual = 2.0;
let estimate = monte_carlo(0., f32::consts::PI, 200_000);
let rel_err = (estimate - actual) / actual;
assert!(rel_err < 10e-3);
println!("{}", estimate);
}
```