forked from eliovir/rust-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunittests.rs
More file actions
33 lines (33 loc) · 718 Bytes
/
unittests.rs
File metadata and controls
33 lines (33 loc) · 718 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
31
32
33
/**
* http://doc.rust-lang.org/guide-testing.html
* http://doc.rust-lang.org/test/index.html
* rustc unittests.rs --test -o unittests
* ./unittests --test
*
* @license MIT license <http://www.opensource.org/licenses/mit-license.php>
*/
#[cfg(test)]
mod tests {
#[test]
#[should_panic]
fn test_fail() {
assert!(1 == 2, "This test must fail!");
}
#[test]
fn test_float() {
let expected = 1f64;
let mut actual = 1f64;
let precision = 0.1f64;
actual = actual + precision / 2f64;
assert!((expected - actual).abs() < precision);
}
#[test]
fn test_success() {
assert!(1 == 1);
assert_eq!(1, 1);
}
}
#[cfg(not(test))]
fn main() {
println!("This program must be build and run with --test");
}