Skip to content

Commit 390a175

Browse files
committed
Run tests on wasm
1 parent 0c59a47 commit 390a175

15 files changed

+58
-29
lines changed

src/math/atan.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ mod tests {
141141
use super::atan;
142142
use core::f64;
143143

144-
#[test]
144+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
145+
#[cfg_attr(not(target_arch = "wasm32"), test)]
145146
fn sanity_check() {
146147
for (input, answer) in [
147148
(3.0_f64.sqrt() / 3.0, f64::consts::FRAC_PI_6),
@@ -163,22 +164,26 @@ mod tests {
163164
}
164165
}
165166

166-
#[test]
167+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
168+
#[cfg_attr(not(target_arch = "wasm32"), test)]
167169
fn zero() {
168170
assert_eq!(atan(0.0), 0.0);
169171
}
170172

171-
#[test]
173+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
174+
#[cfg_attr(not(target_arch = "wasm32"), test)]
172175
fn infinity() {
173176
assert_eq!(atan(f64::INFINITY), f64::consts::FRAC_PI_2);
174177
}
175178

176-
#[test]
179+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
180+
#[cfg_attr(not(target_arch = "wasm32"), test)]
177181
fn minus_infinity() {
178182
assert_eq!(atan(f64::NEG_INFINITY), -f64::consts::FRAC_PI_2);
179183
}
180184

181-
#[test]
185+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
186+
#[cfg_attr(not(target_arch = "wasm32"), test)]
182187
fn nan() {
183188
assert!(atan(f64::NAN).is_nan());
184189
}

src/math/atan2.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ pub fn atan2(y: f64, x: f64) -> f64 {
116116
}
117117
}
118118

119-
#[test]
119+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
120+
#[cfg_attr(not(target_arch = "wasm32"), test)]
120121
fn sanity_check() {
121122
assert_eq!(atan2(0.0, 1.0), 0.0);
122123
assert_eq!(atan2(0.0, -1.0), PI);

src/math/ceil.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ pub fn ceil(x: f64) -> f64 {
4343

4444
#[cfg(test)]
4545
mod tests {
46-
#[test]
46+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
47+
#[cfg_attr(not(target_arch = "wasm32"), test)]
4748
fn sanity_check() {
4849
assert_eq!(super::ceil(1.1), 2.0);
4950
assert_eq!(super::ceil(2.9), 3.0);

src/math/exp2.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ pub fn exp2(mut x: f64) -> f64 {
388388
scalbn(r, ki)
389389
}
390390

391-
#[test]
391+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
392+
#[cfg_attr(not(target_arch = "wasm32"), test)]
392393
fn i0_wrap_test() {
393394
let x = -3.0 / 256.0;
394395
assert_eq!(exp2(x), f64::from_bits(0x3fefbdba3692d514));

src/math/expm1.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ pub fn expm1(mut x: f64) -> f64 {
138138

139139
#[cfg(test)]
140140
mod tests {
141-
#[test]
141+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
142+
#[cfg_attr(not(target_arch = "wasm32"), test)]
142143
fn sanity_check() {
143144
assert_eq!(super::expm1(1.1), 2.0041660239464334);
144145
}

src/math/floorf.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ pub fn floorf(x: f32) -> f32 {
4343

4444
#[cfg(test)]
4545
mod tests {
46-
#[test]
46+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
47+
#[cfg_attr(not(target_arch = "wasm32"), test)]
4748
fn no_overflow() {
4849
assert_eq!(super::floorf(0.5), 0.0);
4950
}

src/math/j1f.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,14 @@ fn qonef(x: f32) -> f32 {
360360
#[cfg(test)]
361361
mod tests {
362362
use super::{j1f, y1f};
363-
#[test]
363+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
364+
#[cfg_attr(not(target_arch = "wasm32"), test)]
364365
fn test_j1f_2488() {
365366
// 0x401F3E49
366367
assert_eq!(j1f(2.4881766_f32), 0.49999475_f32);
367368
}
368-
#[test]
369+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
370+
#[cfg_attr(not(target_arch = "wasm32"), test)]
369371
fn test_y1f_2002() {
370372
assert_eq!(y1f(2.0000002_f32), -0.10703229_f32);
371373
}

src/math/pow.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -500,18 +500,21 @@ mod tests {
500500
});
501501
}
502502

503-
#[test]
503+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
504+
#[cfg_attr(not(target_arch = "wasm32"), test)]
504505
fn zero_as_exponent() {
505506
test_sets_as_base(ALL, 0.0, 1.0);
506507
test_sets_as_base(ALL, -0.0, 1.0);
507508
}
508509

509-
#[test]
510+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
511+
#[cfg_attr(not(target_arch = "wasm32"), test)]
510512
fn one_as_base() {
511513
test_sets_as_exponent(1.0, ALL, 1.0);
512514
}
513515

514-
#[test]
516+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
517+
#[cfg_attr(not(target_arch = "wasm32"), test)]
515518
fn nan_inputs() {
516519
// NAN as the base:
517520
// (NAN ^ anything *but 0* should be NAN)
@@ -522,7 +525,8 @@ mod tests {
522525
test_sets_as_base(&ALL[..(ALL.len() - 2)], NAN, NAN);
523526
}
524527

525-
#[test]
528+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
529+
#[cfg_attr(not(target_arch = "wasm32"), test)]
526530
fn infinity_as_base() {
527531
// Positive Infinity as the base:
528532
// (+Infinity ^ positive anything but 0 and NAN should be +Infinity)
@@ -541,7 +545,8 @@ mod tests {
541545
test_sets(ALL, &|v: f64| pow(NEG_INFINITY, v), &|v: f64| pow(-0.0, -v));
542546
}
543547

544-
#[test]
548+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
549+
#[cfg_attr(not(target_arch = "wasm32"), test)]
545550
fn infinity_as_exponent() {
546551
// Positive/Negative base greater than 1:
547552
// (pos/neg > 1 ^ Infinity should be Infinity - note this excludes NAN as the base)
@@ -567,7 +572,8 @@ mod tests {
567572
test_sets_as_base(&[NEG_ONE, POS_ONE], NEG_INFINITY, 1.0);
568573
}
569574

570-
#[test]
575+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
576+
#[cfg_attr(not(target_arch = "wasm32"), test)]
571577
fn zero_as_base() {
572578
// Positive Zero as the base:
573579
// (+0 ^ anything positive but 0 and NAN should be +0)
@@ -593,7 +599,8 @@ mod tests {
593599
test_sets_as_exponent(-0.0, &[NEG_ODDS], NEG_INFINITY);
594600
}
595601

596-
#[test]
602+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
603+
#[cfg_attr(not(target_arch = "wasm32"), test)]
597604
fn special_cases() {
598605
// One as the exponent:
599606
// (anything ^ 1 should be anything - i.e. the base)
@@ -624,7 +631,8 @@ mod tests {
624631
});
625632
}
626633

627-
#[test]
634+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
635+
#[cfg_attr(not(target_arch = "wasm32"), test)]
628636
fn normal_cases() {
629637
assert_eq!(pow(2.0, 20.0), (1 << 20) as f64);
630638
assert_eq!(pow(-1.0, 9.0), -1.0);

src/math/rem_pio2.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ pub(crate) fn rem_pio2(x: f64) -> (i32, f64, f64) {
190190
mod tests {
191191
use super::rem_pio2;
192192

193-
#[test]
193+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
194+
#[cfg_attr(not(target_arch = "wasm32"), test)]
194195
fn test_near_pi() {
195196
assert_eq!(
196197
rem_pio2(3.141592025756836),
@@ -210,12 +211,14 @@ mod tests {
210211
);
211212
}
212213

213-
#[test]
214+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
215+
#[cfg_attr(not(target_arch = "wasm32"), test)]
214216
fn test_overflow_b9b847() {
215217
let _ = rem_pio2(-3054214.5490637687);
216218
}
217219

218-
#[test]
220+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
221+
#[cfg_attr(not(target_arch = "wasm32"), test)]
219222
fn test_overflow_4747b9() {
220223
let _ = rem_pio2(917340800458.2274);
221224
}

src/math/remquo.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ pub fn remquo(mut x: f64, mut y: f64) -> (f64, i32) {
101101
mod tests {
102102
use super::remquo;
103103

104-
#[test]
104+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
105+
#[cfg_attr(not(target_arch = "wasm32"), test)]
105106
fn test_q_overflow() {
106107
// 0xc000000000000001, 0x04c0000000000004
107108
let _ = remquo(-2.0000000000000004, 8.406091369059082e-286);

src/math/round.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ pub fn round(mut x: f64) -> f64 {
4040
mod tests {
4141
use super::round;
4242

43-
#[test]
43+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
44+
#[cfg_attr(not(target_arch = "wasm32"), test)]
4445
fn negative_zero() {
4546
assert_eq!(round(-0.0_f64).to_bits(), (-0.0_f64).to_bits());
4647
}

src/math/roundf.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub fn roundf(mut x: f32) -> f32 {
3838
mod tests {
3939
use super::roundf;
4040

41-
#[test]
41+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
42+
#[cfg_attr(not(target_arch = "wasm32"), test)]
4243
fn negative_zero() {
4344
assert_eq!(roundf(-0.0_f32).to_bits(), (-0.0_f32).to_bits());
4445
}

src/math/sin.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ pub fn sin(x: f64) -> f64 {
7878
}
7979
}
8080

81-
#[test]
81+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
82+
#[cfg_attr(not(target_arch = "wasm32"), test)]
8283
fn test_near_pi() {
8384
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
8485
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7

src/math/trunc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ pub fn trunc(x: f64) -> f64 {
3434

3535
#[cfg(test)]
3636
mod tests {
37-
#[test]
37+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
38+
#[cfg_attr(not(target_arch = "wasm32"), test)]
3839
fn sanity_check() {
3940
assert_eq!(super::trunc(1.1), 1.0);
4041
}

src/math/truncf.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ pub fn truncf(x: f32) -> f32 {
3434

3535
#[cfg(test)]
3636
mod tests {
37-
#[test]
37+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
38+
#[cfg_attr(not(target_arch = "wasm32"), test)]
3839
fn sanity_check() {
3940
assert_eq!(super::truncf(1.1), 1.0);
4041
}

0 commit comments

Comments
 (0)