Skip to content

Commit 86f0b79

Browse files
committed
Adapt tests
1 parent 8ff0bb1 commit 86f0b79

File tree

1 file changed

+28
-144
lines changed

1 file changed

+28
-144
lines changed

Diff for: tests/test.rs

+28-144
Original file line numberDiff line numberDiff line change
@@ -257,22 +257,22 @@ fn not_nan32_fail_when_constructing_with_nan() {
257257
#[test]
258258
fn not_nan32_calculate_correctly() {
259259
assert_eq!(*(not_nan(5.0f32) + not_nan(4.0f32)), 5.0f32 + 4.0f32);
260-
assert_eq!(*(not_nan(5.0f32) + 4.0f32), 5.0f32 + 4.0f32);
260+
assert_eq!(not_nan(5.0f32) + 4.0f32, 5.0f32 + 4.0f32);
261261
assert_eq!(*(not_nan(5.0f32) - not_nan(4.0f32)), 5.0f32 - 4.0f32);
262-
assert_eq!(*(not_nan(5.0f32) - 4.0f32), 5.0f32 - 4.0f32);
262+
assert_eq!(not_nan(5.0f32) - 4.0f32, 5.0f32 - 4.0f32);
263263
assert_eq!(*(not_nan(5.0f32) * not_nan(4.0f32)), 5.0f32 * 4.0f32);
264-
assert_eq!(*(not_nan(5.0f32) * 4.0f32), 5.0f32 * 4.0f32);
264+
assert_eq!(not_nan(5.0f32) * 4.0f32, 5.0f32 * 4.0f32);
265265
assert_eq!(*(not_nan(8.0f32) / not_nan(4.0f32)), 8.0f32 / 4.0f32);
266-
assert_eq!(*(not_nan(8.0f32) / 4.0f32), 8.0f32 / 4.0f32);
266+
assert_eq!(not_nan(8.0f32) / 4.0f32, 8.0f32 / 4.0f32);
267267
assert_eq!(*(not_nan(8.0f32) % not_nan(4.0f32)), 8.0f32 % 4.0f32);
268-
assert_eq!(*(not_nan(8.0f32) % 4.0f32), 8.0f32 % 4.0f32);
268+
assert_eq!(not_nan(8.0f32) % 4.0f32, 8.0f32 % 4.0f32);
269269
assert_eq!(*(-not_nan(1.0f32)), -1.0f32);
270270

271-
assert!(panic::catch_unwind(|| not_nan(0.0f32) + f32::NAN).is_err());
272-
assert!(panic::catch_unwind(|| not_nan(0.0f32) - f32::NAN).is_err());
273-
assert!(panic::catch_unwind(|| not_nan(0.0f32) * f32::NAN).is_err());
274-
assert!(panic::catch_unwind(|| not_nan(0.0f32) / f32::NAN).is_err());
275-
assert!(panic::catch_unwind(|| not_nan(0.0f32) % f32::NAN).is_err());
271+
assert!(f32::is_nan(not_nan(0.0f32) + f32::NAN));
272+
assert!(f32::is_nan(not_nan(0.0f32) - f32::NAN));
273+
assert!(f32::is_nan(not_nan(0.0f32) * f32::NAN));
274+
assert!(f32::is_nan(not_nan(0.0f32) / f32::NAN));
275+
assert!(f32::is_nan(not_nan(0.0f32) % f32::NAN));
276276

277277
let mut number = not_nan(5.0f32);
278278
number += not_nan(4.0f32);
@@ -285,44 +285,6 @@ fn not_nan32_calculate_correctly() {
285285
assert_eq!(*number, 5.0f32);
286286
number %= not_nan(4.0f32);
287287
assert_eq!(*number, 1.0f32);
288-
289-
number = not_nan(5.0f32);
290-
number += 4.0f32;
291-
assert_eq!(*number, 9.0f32);
292-
number -= 4.0f32;
293-
assert_eq!(*number, 5.0f32);
294-
number *= 4.0f32;
295-
assert_eq!(*number, 20.0f32);
296-
number /= 4.0f32;
297-
assert_eq!(*number, 5.0f32);
298-
number %= 4.0f32;
299-
assert_eq!(*number, 1.0f32);
300-
301-
assert!(panic::catch_unwind(|| {
302-
let mut tmp = not_nan(0.0f32);
303-
tmp += f32::NAN;
304-
})
305-
.is_err());
306-
assert!(panic::catch_unwind(|| {
307-
let mut tmp = not_nan(0.0f32);
308-
tmp -= f32::NAN;
309-
})
310-
.is_err());
311-
assert!(panic::catch_unwind(|| {
312-
let mut tmp = not_nan(0.0f32);
313-
tmp *= f32::NAN;
314-
})
315-
.is_err());
316-
assert!(panic::catch_unwind(|| {
317-
let mut tmp = not_nan(0.0f32);
318-
tmp /= f32::NAN;
319-
})
320-
.is_err());
321-
assert!(panic::catch_unwind(|| {
322-
let mut tmp = not_nan(0.0f32);
323-
tmp %= f32::NAN;
324-
})
325-
.is_err());
326288
}
327289

328290
#[test]
@@ -341,22 +303,22 @@ fn not_nan64_fail_when_constructing_with_nan() {
341303
#[test]
342304
fn not_nan64_calculate_correctly() {
343305
assert_eq!(*(not_nan(5.0f64) + not_nan(4.0f64)), 5.0f64 + 4.0f64);
344-
assert_eq!(*(not_nan(5.0f64) + 4.0f64), 5.0f64 + 4.0f64);
306+
assert_eq!(not_nan(5.0f64) + 4.0f64, 5.0f64 + 4.0f64);
345307
assert_eq!(*(not_nan(5.0f64) - not_nan(4.0f64)), 5.0f64 - 4.0f64);
346-
assert_eq!(*(not_nan(5.0f64) - 4.0f64), 5.0f64 - 4.0f64);
308+
assert_eq!(not_nan(5.0f64) - 4.0f64, 5.0f64 - 4.0f64);
347309
assert_eq!(*(not_nan(5.0f64) * not_nan(4.0f64)), 5.0f64 * 4.0f64);
348-
assert_eq!(*(not_nan(5.0f64) * 4.0f64), 5.0f64 * 4.0f64);
310+
assert_eq!(not_nan(5.0f64) * 4.0f64, 5.0f64 * 4.0f64);
349311
assert_eq!(*(not_nan(8.0f64) / not_nan(4.0f64)), 8.0f64 / 4.0f64);
350-
assert_eq!(*(not_nan(8.0f64) / 4.0f64), 8.0f64 / 4.0f64);
312+
assert_eq!(not_nan(8.0f64) / 4.0f64, 8.0f64 / 4.0f64);
351313
assert_eq!(*(not_nan(8.0f64) % not_nan(4.0f64)), 8.0f64 % 4.0f64);
352-
assert_eq!(*(not_nan(8.0f64) % 4.0f64), 8.0f64 % 4.0f64);
314+
assert_eq!(not_nan(8.0f64) % 4.0f64, 8.0f64 % 4.0f64);
353315
assert_eq!(*(-not_nan(1.0f64)), -1.0f64);
354316

355-
assert!(panic::catch_unwind(|| not_nan(0.0f64) + f64::NAN).is_err());
356-
assert!(panic::catch_unwind(|| not_nan(0.0f64) - f64::NAN).is_err());
357-
assert!(panic::catch_unwind(|| not_nan(0.0f64) * f64::NAN).is_err());
358-
assert!(panic::catch_unwind(|| not_nan(0.0f64) / f64::NAN).is_err());
359-
assert!(panic::catch_unwind(|| not_nan(0.0f64) % f64::NAN).is_err());
317+
assert!(f64::is_nan(not_nan(0.0f64) + f64::NAN));
318+
assert!(f64::is_nan(not_nan(0.0f64) - f64::NAN));
319+
assert!(f64::is_nan(not_nan(0.0f64) * f64::NAN));
320+
assert!(f64::is_nan(not_nan(0.0f64) / f64::NAN));
321+
assert!(f64::is_nan(not_nan(0.0f64) % f64::NAN));
360322

361323
let mut number = not_nan(5.0f64);
362324
number += not_nan(4.0f64);
@@ -369,44 +331,6 @@ fn not_nan64_calculate_correctly() {
369331
assert_eq!(*number, 5.0f64);
370332
number %= not_nan(4.0f64);
371333
assert_eq!(*number, 1.0f64);
372-
373-
number = not_nan(5.0f64);
374-
number += 4.0f64;
375-
assert_eq!(*number, 9.0f64);
376-
number -= 4.0f64;
377-
assert_eq!(*number, 5.0f64);
378-
number *= 4.0f64;
379-
assert_eq!(*number, 20.0f64);
380-
number /= 4.0f64;
381-
assert_eq!(*number, 5.0f64);
382-
number %= 4.0f64;
383-
assert_eq!(*number, 1.0f64);
384-
385-
assert!(panic::catch_unwind(|| {
386-
let mut tmp = not_nan(0.0f64);
387-
tmp += f64::NAN;
388-
})
389-
.is_err());
390-
assert!(panic::catch_unwind(|| {
391-
let mut tmp = not_nan(0.0f64);
392-
tmp -= f64::NAN;
393-
})
394-
.is_err());
395-
assert!(panic::catch_unwind(|| {
396-
let mut tmp = not_nan(0.0f64);
397-
tmp *= f64::NAN;
398-
})
399-
.is_err());
400-
assert!(panic::catch_unwind(|| {
401-
let mut tmp = not_nan(0.0f64);
402-
tmp /= f64::NAN;
403-
})
404-
.is_err());
405-
assert!(panic::catch_unwind(|| {
406-
let mut tmp = not_nan(0.0f64);
407-
tmp %= f64::NAN;
408-
})
409-
.is_err());
410334
}
411335

412336
#[test]
@@ -578,47 +502,23 @@ fn hash_is_good_for_fractional_numbers() {
578502
fn test_add_fails_on_nan() {
579503
let a = not_nan(f32::INFINITY);
580504
let b = not_nan(f32::NEG_INFINITY);
581-
let _c = a + b;
505+
let _c: NotNan<f32> = a + b;
582506
}
583507

584508
#[test]
585509
#[should_panic]
586510
fn test_add_fails_on_nan_ref() {
587511
let a = not_nan(f32::INFINITY);
588512
let b = not_nan(f32::NEG_INFINITY);
589-
let _c = a + &b;
513+
let _c: NotNan<f32> = a + &b;
590514
}
591515

592516
#[test]
593517
#[should_panic]
594518
fn test_add_fails_on_nan_ref_ref() {
595519
let a = not_nan(f32::INFINITY);
596520
let b = not_nan(f32::NEG_INFINITY);
597-
let _c = &a + &b;
598-
}
599-
600-
#[test]
601-
#[should_panic]
602-
fn test_add_fails_on_nan_t_ref() {
603-
let a = not_nan(f32::INFINITY);
604-
let b = f32::NEG_INFINITY;
605-
let _c = a + &b;
606-
}
607-
608-
#[test]
609-
#[should_panic]
610-
fn test_add_fails_on_nan_ref_t_ref() {
611-
let a = not_nan(f32::INFINITY);
612-
let b = f32::NEG_INFINITY;
613-
let _c = &a + &b;
614-
}
615-
616-
#[test]
617-
#[should_panic]
618-
fn test_add_fails_on_nan_ref_t() {
619-
let a = not_nan(f32::INFINITY);
620-
let b = f32::NEG_INFINITY;
621-
let _c = &a + b;
521+
let _c: NotNan<f32> = &a + &b;
622522
}
623523

624524
#[test]
@@ -629,22 +529,6 @@ fn test_add_assign_fails_on_nan_ref() {
629529
a += &b;
630530
}
631531

632-
#[test]
633-
#[should_panic]
634-
fn test_add_assign_fails_on_nan_t_ref() {
635-
let mut a = not_nan(f32::INFINITY);
636-
let b = f32::NEG_INFINITY;
637-
a += &b;
638-
}
639-
640-
#[test]
641-
#[should_panic]
642-
fn test_add_assign_fails_on_nan_t() {
643-
let mut a = not_nan(f32::INFINITY);
644-
let b = f32::NEG_INFINITY;
645-
a += b;
646-
}
647-
648532
#[test]
649533
fn add() {
650534
assert_eq!(not_nan(0.0) + not_nan(0.0), 0.0);
@@ -729,11 +613,11 @@ fn not_nan_panic_safety() {
729613
num
730614
};
731615

732-
assert!(!catch_op(not_nan(f32::INFINITY), |a| *a += f32::NEG_INFINITY).is_nan());
733-
assert!(!catch_op(not_nan(f32::INFINITY), |a| *a -= f32::INFINITY).is_nan());
734-
assert!(!catch_op(not_nan(0.0), |a| *a *= f32::INFINITY).is_nan());
735-
assert!(!catch_op(not_nan(0.0), |a| *a /= 0.0).is_nan());
736-
assert!(!catch_op(not_nan(0.0), |a| *a %= 0.0).is_nan());
616+
assert!(!catch_op(not_nan(f32::INFINITY), |a| *a += not_nan(f32::NEG_INFINITY)).is_nan());
617+
assert!(!catch_op(not_nan(f32::INFINITY), |a| *a -= not_nan(f32::INFINITY)).is_nan());
618+
assert!(!catch_op(not_nan(0.0), |a| *a *= not_nan(f32::INFINITY)).is_nan());
619+
assert!(!catch_op(not_nan(0.0), |a| *a /= not_nan(0.0)).is_nan());
620+
assert!(!catch_op(not_nan(0.0), |a| *a %= not_nan(0.0)).is_nan());
737621
}
738622

739623
#[test]

0 commit comments

Comments
 (0)