Add assert_approx_eq! macro
This commit is contained in:
parent
0211833008
commit
0e2242f6d6
7 changed files with 275 additions and 223 deletions
14
src/test/run-fail/assert-approx-eq-eps-macro-fail.rs
Normal file
14
src/test/run-fail/assert-approx-eq-eps-macro-fail.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:left: 1.0000001 does not approximately equal right: 1 with epsilon: 0.0000001
|
||||
pub fn main() {
|
||||
assert_approx_eq!(1.0000001f, 1.0f, 1.0e-7);
|
||||
}
|
||||
14
src/test/run-fail/assert-approx-eq-macro-fail.rs
Normal file
14
src/test/run-fail/assert-approx-eq-macro-fail.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:left: 1.00001 does not approximately equal right: 1
|
||||
pub fn main() {
|
||||
assert_approx_eq!(1.00001f, 1.0f);
|
||||
}
|
||||
16
src/test/run-pass/assert-approx-eq-macro-success.rs
Normal file
16
src/test/run-pass/assert-approx-eq-macro-success.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
pub fn main() {
|
||||
assert_approx_eq!(1.0f, 1.0f);
|
||||
assert_approx_eq!(1.0000001f, 1.0f);
|
||||
assert_approx_eq!(1.0000001f, 1.0f, 1.0e-6);
|
||||
assert_approx_eq!(1.000001f, 1.0f, 1.0e-5);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue