From 752e86c985cddb5d1fdd1cbaeca451fb6e6dc8dc Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 10 Jul 2019 20:01:43 +0200 Subject: [PATCH] Run tests on wasm --- src/math/atan.rs | 15 ++++++++++----- src/math/atan2.rs | 3 ++- src/math/ceil.rs | 3 ++- src/math/exp2.rs | 3 ++- src/math/expm1.rs | 3 ++- src/math/floorf.rs | 3 ++- src/math/j1f.rs | 6 ++++-- src/math/pow.rs | 24 ++++++++++++++++-------- src/math/rem_pio2.rs | 9 ++++++--- src/math/remquo.rs | 3 ++- src/math/round.rs | 3 ++- src/math/roundf.rs | 3 ++- src/math/sin.rs | 3 ++- src/math/trunc.rs | 3 ++- src/math/truncf.rs | 3 ++- 15 files changed, 58 insertions(+), 29 deletions(-) diff --git a/src/math/atan.rs b/src/math/atan.rs index d2684ece8..37ce16da9 100644 --- a/src/math/atan.rs +++ b/src/math/atan.rs @@ -141,7 +141,8 @@ mod tests { use super::atan; use core::f64; - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn sanity_check() { for (input, answer) in [ (3.0_f64.sqrt() / 3.0, f64::consts::FRAC_PI_6), @@ -163,22 +164,26 @@ mod tests { } } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn zero() { assert_eq!(atan(0.0), 0.0); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn infinity() { assert_eq!(atan(f64::INFINITY), f64::consts::FRAC_PI_2); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn minus_infinity() { assert_eq!(atan(f64::NEG_INFINITY), -f64::consts::FRAC_PI_2); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn nan() { assert!(atan(f64::NAN).is_nan()); } diff --git a/src/math/atan2.rs b/src/math/atan2.rs index 08385cd10..170a3a3fc 100644 --- a/src/math/atan2.rs +++ b/src/math/atan2.rs @@ -116,7 +116,8 @@ pub fn atan2(y: f64, x: f64) -> f64 { } } -#[test] +#[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] +#[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn sanity_check() { assert_eq!(atan2(0.0, 1.0), 0.0); assert_eq!(atan2(0.0, -1.0), PI); diff --git a/src/math/ceil.rs b/src/math/ceil.rs index c9d191d6c..aae105b87 100644 --- a/src/math/ceil.rs +++ b/src/math/ceil.rs @@ -43,7 +43,8 @@ pub fn ceil(x: f64) -> f64 { #[cfg(test)] mod tests { - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn sanity_check() { assert_eq!(super::ceil(1.1), 2.0); assert_eq!(super::ceil(2.9), 3.0); diff --git a/src/math/exp2.rs b/src/math/exp2.rs index c2192fde5..58b4f64ff 100644 --- a/src/math/exp2.rs +++ b/src/math/exp2.rs @@ -388,7 +388,8 @@ pub fn exp2(mut x: f64) -> f64 { scalbn(r, ki) } -#[test] +#[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] +#[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn i0_wrap_test() { let x = -3.0 / 256.0; assert_eq!(exp2(x), f64::from_bits(0x3fefbdba3692d514)); diff --git a/src/math/expm1.rs b/src/math/expm1.rs index 0d43b4e10..f1fd9d8c8 100644 --- a/src/math/expm1.rs +++ b/src/math/expm1.rs @@ -138,7 +138,8 @@ pub fn expm1(mut x: f64) -> f64 { #[cfg(test)] mod tests { - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn sanity_check() { assert_eq!(super::expm1(1.1), 2.0041660239464334); } diff --git a/src/math/floorf.rs b/src/math/floorf.rs index 9d7aaee6b..aa671a5db 100644 --- a/src/math/floorf.rs +++ b/src/math/floorf.rs @@ -43,7 +43,8 @@ pub fn floorf(x: f32) -> f32 { #[cfg(test)] mod tests { - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn no_overflow() { assert_eq!(super::floorf(0.5), 0.0); } diff --git a/src/math/j1f.rs b/src/math/j1f.rs index 5095894d7..5e1b57c46 100644 --- a/src/math/j1f.rs +++ b/src/math/j1f.rs @@ -360,12 +360,14 @@ fn qonef(x: f32) -> f32 { #[cfg(test)] mod tests { use super::{j1f, y1f}; - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn test_j1f_2488() { // 0x401F3E49 assert_eq!(j1f(2.4881766_f32), 0.49999475_f32); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn test_y1f_2002() { assert_eq!(y1f(2.0000002_f32), -0.10703229_f32); } diff --git a/src/math/pow.rs b/src/math/pow.rs index 068a4ec47..47d18c453 100644 --- a/src/math/pow.rs +++ b/src/math/pow.rs @@ -500,18 +500,21 @@ mod tests { }); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn zero_as_exponent() { test_sets_as_base(ALL, 0.0, 1.0); test_sets_as_base(ALL, -0.0, 1.0); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn one_as_base() { test_sets_as_exponent(1.0, ALL, 1.0); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn nan_inputs() { // NAN as the base: // (NAN ^ anything *but 0* should be NAN) @@ -522,7 +525,8 @@ mod tests { test_sets_as_base(&ALL[..(ALL.len() - 2)], NAN, NAN); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn infinity_as_base() { // Positive Infinity as the base: // (+Infinity ^ positive anything but 0 and NAN should be +Infinity) @@ -541,7 +545,8 @@ mod tests { test_sets(ALL, &|v: f64| pow(NEG_INFINITY, v), &|v: f64| pow(-0.0, -v)); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn infinity_as_exponent() { // Positive/Negative base greater than 1: // (pos/neg > 1 ^ Infinity should be Infinity - note this excludes NAN as the base) @@ -567,7 +572,8 @@ mod tests { test_sets_as_base(&[NEG_ONE, POS_ONE], NEG_INFINITY, 1.0); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn zero_as_base() { // Positive Zero as the base: // (+0 ^ anything positive but 0 and NAN should be +0) @@ -593,7 +599,8 @@ mod tests { test_sets_as_exponent(-0.0, &[NEG_ODDS], NEG_INFINITY); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn special_cases() { // One as the exponent: // (anything ^ 1 should be anything - i.e. the base) @@ -624,7 +631,8 @@ mod tests { }); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn normal_cases() { assert_eq!(pow(2.0, 20.0), (1 << 20) as f64); assert_eq!(pow(-1.0, 9.0), -1.0); diff --git a/src/math/rem_pio2.rs b/src/math/rem_pio2.rs index dc6b3297d..0be29a593 100644 --- a/src/math/rem_pio2.rs +++ b/src/math/rem_pio2.rs @@ -190,7 +190,8 @@ pub(crate) fn rem_pio2(x: f64) -> (i32, f64, f64) { mod tests { use super::rem_pio2; - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn test_near_pi() { assert_eq!( rem_pio2(3.141592025756836), @@ -210,12 +211,14 @@ mod tests { ); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn test_overflow_b9b847() { let _ = rem_pio2(-3054214.5490637687); } - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn test_overflow_4747b9() { let _ = rem_pio2(917340800458.2274); } diff --git a/src/math/remquo.rs b/src/math/remquo.rs index c72c8f187..95f7dee85 100644 --- a/src/math/remquo.rs +++ b/src/math/remquo.rs @@ -101,7 +101,8 @@ pub fn remquo(mut x: f64, mut y: f64) -> (f64, i32) { mod tests { use super::remquo; - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn test_q_overflow() { // 0xc000000000000001, 0x04c0000000000004 let _ = remquo(-2.0000000000000004, 8.406091369059082e-286); diff --git a/src/math/round.rs b/src/math/round.rs index 67590d2c1..59f8f4c25 100644 --- a/src/math/round.rs +++ b/src/math/round.rs @@ -40,7 +40,8 @@ pub fn round(mut x: f64) -> f64 { mod tests { use super::round; - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn negative_zero() { assert_eq!(round(-0.0_f64).to_bits(), (-0.0_f64).to_bits()); } diff --git a/src/math/roundf.rs b/src/math/roundf.rs index 85114be4b..e79bd9ffa 100644 --- a/src/math/roundf.rs +++ b/src/math/roundf.rs @@ -38,7 +38,8 @@ pub fn roundf(mut x: f32) -> f32 { mod tests { use super::roundf; - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn negative_zero() { assert_eq!(roundf(-0.0_f32).to_bits(), (-0.0_f32).to_bits()); } diff --git a/src/math/sin.rs b/src/math/sin.rs index 51aed88a8..0695668f2 100644 --- a/src/math/sin.rs +++ b/src/math/sin.rs @@ -78,7 +78,8 @@ pub fn sin(x: f64) -> f64 { } } -#[test] +#[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] +#[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn test_near_pi() { let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707 let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7 diff --git a/src/math/trunc.rs b/src/math/trunc.rs index c52ee2ee9..0413b8314 100644 --- a/src/math/trunc.rs +++ b/src/math/trunc.rs @@ -34,7 +34,8 @@ pub fn trunc(x: f64) -> f64 { #[cfg(test)] mod tests { - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn sanity_check() { assert_eq!(super::trunc(1.1), 1.0); } diff --git a/src/math/truncf.rs b/src/math/truncf.rs index d0c4c5810..71f116d3f 100644 --- a/src/math/truncf.rs +++ b/src/math/truncf.rs @@ -34,7 +34,8 @@ pub fn truncf(x: f32) -> f32 { #[cfg(test)] mod tests { - #[test] + #[cfg_attr(cfg(target_arch = "wasm32"), wasm_bindgen_test)] + #[cfg_attr(cfg(not(target_arch = "wasm32")), test)] fn sanity_check() { assert_eq!(super::truncf(1.1), 1.0); }