Skip to content

Commit

Permalink
Run tests on wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Jul 10, 2019
1 parent 0c59a47 commit 752e86c
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 29 deletions.
15 changes: 10 additions & 5 deletions src/math/atan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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());
}
Expand Down
3 changes: 2 additions & 1 deletion src/math/atan2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/math/ceil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/math/exp2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion src/math/expm1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/math/floorf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions src/math/j1f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
24 changes: 16 additions & 8 deletions src/math/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/math/rem_pio2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/math/remquo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/math/round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
3 changes: 2 additions & 1 deletion src/math/roundf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
3 changes: 2 additions & 1 deletion src/math/sin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/math/trunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/math/truncf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 752e86c

Please sign in to comment.