diff options
author | Casper <casperneo@uchicago.edu> | 2019-09-09 13:02:43 -0700 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-09-09 13:02:43 -0700 |
commit | c0282873fb42db8b5c8feb0789362610c3228ac1 (patch) | |
tree | 313f9872dd05a54a328ad222302f87f05af7b433 /tests/rust_usage_test | |
parent | 4b870aca98eca22c56faa3245ada7014752f7b2c (diff) | |
download | flatbuffers-c0282873fb42db8b5c8feb0789362610c3228ac1.tar.gz flatbuffers-c0282873fb42db8b5c8feb0789362610c3228ac1.tar.bz2 flatbuffers-c0282873fb42db8b5c8feb0789362610c3228ac1.zip |
Rust: Fixed cargo clippy on non-generated code (#5485)
* Cargo clippy lints
* more lints
* more lints
* Restored a doc comment
* Comment on float eps-eq and adjusted casting
Diffstat (limited to 'tests/rust_usage_test')
-rw-r--r-- | tests/rust_usage_test/bin/alloc_check.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/tests/rust_usage_test/bin/alloc_check.rs b/tests/rust_usage_test/bin/alloc_check.rs index ae1039cb..e7ec9e5b 100644 --- a/tests/rust_usage_test/bin/alloc_check.rs +++ b/tests/rust_usage_test/bin/alloc_check.rs @@ -106,10 +106,13 @@ fn main() { assert_eq!("MyMonster", m.name()); let pos = m.pos().unwrap(); - assert_eq!(pos.x(), 1.0f32); - assert_eq!(pos.y(), 2.0f32); - assert_eq!(pos.z(), 3.0f32); - assert_eq!(pos.test1(), 3.0f64); + // We know the bits should be exactly equal here but compilers may + // optimize floats in subtle ways so we're playing it safe and using + // epsilon comparison + assert!((pos.x() - 1.0f32).abs() < std::f32::EPSILON); + assert!((pos.y() - 2.0f32).abs() < std::f32::EPSILON); + assert!((pos.z() - 3.0f32).abs() < std::f32::EPSILON); + assert!((pos.test1() - 3.0f64).abs() < std::f64::EPSILON); assert_eq!(pos.test2(), my_game::example::Color::Green); let pos_test3 = pos.test3(); assert_eq!(pos_test3.a(), 5i16); @@ -126,8 +129,8 @@ fn main() { let test4 = m.test4().unwrap(); assert_eq!(test4.len(), 2); - assert_eq!(test4[0].a() as i32 + test4[0].b() as i32 + - test4[1].a() as i32 + test4[1].b() as i32, 100); + assert_eq!(i32::from(test4[0].a()) + i32::from(test4[1].a()) + + i32::from(test4[0].b()) + i32::from(test4[1].b()), 100); let testarrayofstring = m.testarrayofstring().unwrap(); assert_eq!(testarrayofstring.len(), 2); |