Skip to content

Commit c468547

Browse files
committed
Consolidate tests of numeric operations
1 parent ce6ee7b commit c468547

File tree

6 files changed

+29
-83
lines changed

6 files changed

+29
-83
lines changed

src/libcore/num/f32.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -555,18 +555,6 @@ impl num::FromStrRadix for f32 {
555555
}
556556
}
557557

558-
#[test]
559-
pub fn test_num() {
560-
let ten: f32 = num::cast(10);
561-
let two: f32 = num::cast(2);
562-
563-
assert!((ten.add(&two) == num::cast(12)));
564-
assert!((ten.sub(&two) == num::cast(8)));
565-
assert!((ten.mul(&two) == num::cast(20)));
566-
assert!((ten.div(&two) == num::cast(5)));
567-
assert!((ten.modulo(&two) == num::cast(0)));
568-
}
569-
570558
//
571559
// Local Variables:
572560
// mode: rust

src/libcore/num/f64.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -577,18 +577,6 @@ impl num::FromStrRadix for f64 {
577577
}
578578
}
579579

580-
#[test]
581-
pub fn test_num() {
582-
let ten: f64 = num::cast(10);
583-
let two: f64 = num::cast(2);
584-
585-
assert!((ten.add(&two) == num::cast(12)));
586-
assert!((ten.sub(&two) == num::cast(8)));
587-
assert!((ten.mul(&two) == num::cast(20)));
588-
assert!((ten.div(&two) == num::cast(5)));
589-
assert!((ten.modulo(&two) == num::cast(0)));
590-
}
591-
592580
//
593581
// Local Variables:
594582
// mode: rust

src/libcore/num/float.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -663,18 +663,6 @@ pub fn test_round() {
663663
assert!(round(-3.5) == -4.0);
664664
}
665665

666-
#[test]
667-
pub fn test_num() {
668-
let ten: float = num::cast(10);
669-
let two: float = num::cast(2);
670-
671-
assert!((ten.add(&two) == num::cast(12)));
672-
assert!((ten.sub(&two) == num::cast(8)));
673-
assert!((ten.mul(&two) == num::cast(20)));
674-
assert!((ten.div(&two) == num::cast(5)));
675-
assert!((ten.modulo(&two) == num::cast(0)));
676-
}
677-
678666

679667
//
680668
// Local Variables:

src/libcore/num/int-template.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,18 +397,6 @@ fn test_int_from_str_overflow() {
397397
assert!((i64::from_str(~"-9223372036854775809").is_none()));
398398
}
399399
400-
#[test]
401-
pub fn test_num() {
402-
let ten: T = num::cast(10);
403-
let two: T = num::cast(2);
404-
405-
assert!((ten.add(&two) == num::cast(12)));
406-
assert!((ten.sub(&two) == num::cast(8)));
407-
assert!((ten.mul(&two) == num::cast(20)));
408-
assert!((ten.div(&two) == num::cast(5)));
409-
assert!((ten.modulo(&two) == num::cast(0)));
410-
}
411-
412400
#[test]
413401
pub fn test_ranges() {
414402
let mut l = ~[];

src/libcore/num/num.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,35 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
202202
total
203203
}
204204

205+
#[cfg(test)]
206+
fn test_num<T:Num + NumCast>(ten: T, two: T) {
207+
assert!(ten.add(&two) == cast(12));
208+
assert!(ten.sub(&two) == cast(8));
209+
assert!(ten.mul(&two) == cast(20));
210+
assert!(ten.div(&two) == cast(5));
211+
assert!(ten.modulo(&two) == cast(0));
212+
213+
assert!(ten.add(&two) == ten + two);
214+
assert!(ten.sub(&two) == ten - two);
215+
assert!(ten.mul(&two) == ten * two);
216+
assert!(ten.div(&two) == ten / two);
217+
assert!(ten.modulo(&two) == ten % two);
218+
}
219+
220+
#[test] fn test_u8_num() { test_num(10u8, 2u8) }
221+
#[test] fn test_u16_num() { test_num(10u16, 2u16) }
222+
#[test] fn test_u32_num() { test_num(10u32, 2u32) }
223+
#[test] fn test_u64_num() { test_num(10u64, 2u64) }
224+
#[test] fn test_uint_num() { test_num(10u, 2u) }
225+
#[test] fn test_i8_num() { test_num(10i8, 2i8) }
226+
#[test] fn test_i16_num() { test_num(10i16, 2i16) }
227+
#[test] fn test_i32_num() { test_num(10i32, 2i32) }
228+
#[test] fn test_i64_num() { test_num(10i64, 2i64) }
229+
#[test] fn test_int_num() { test_num(10i, 2i) }
230+
#[test] fn test_f32_num() { test_num(10f32, 2f32) }
231+
#[test] fn test_f64_num() { test_num(10f64, 2f64) }
232+
#[test] fn test_float_num() { test_num(10f, 2f) }
233+
205234
macro_rules! test_cast_20(
206235
($_20:expr) => ({
207236
let _20 = $_20;
@@ -263,26 +292,3 @@ macro_rules! test_cast_20(
263292
#[test] fn test_f32_cast() { test_cast_20!(20f32) }
264293
#[test] fn test_f64_cast() { test_cast_20!(20f64) }
265294
#[test] fn test_float_cast() { test_cast_20!(20f) }
266-
267-
#[test]
268-
fn test_generic_cast() {
269-
use ops::Add;
270-
271-
fn add_2<T: Add<T,T> + NumCast>(n: T) -> T {
272-
n + cast(2)
273-
}
274-
275-
assert!(add_2(1u) == 3u);
276-
assert!(add_2(1u8) == 3u8);
277-
assert!(add_2(1u16) == 3u16);
278-
assert!(add_2(1u32) == 3u32);
279-
assert!(add_2(1u64) == 3u64);
280-
assert!(add_2(1i) == 3i);
281-
assert!(add_2(1i8) == 3i8);
282-
assert!(add_2(1i16) == 3i16);
283-
assert!(add_2(1i32) == 3i32);
284-
assert!(add_2(1i64) == 3i64);
285-
assert!(add_2(1f) == 3f);
286-
assert!(add_2(1f32) == 3f32);
287-
assert!(add_2(1f64) == 3f64);
288-
}

src/libcore/num/uint-template.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -411,18 +411,6 @@ pub fn test_ranges() {
411411
}
412412
}
413413

414-
#[test]
415-
pub fn test_num() {
416-
let ten: T = num::cast(10);
417-
let two: T = num::cast(2);
418-
419-
assert!((ten.add(&two) == num::cast(12)));
420-
assert!((ten.sub(&two) == num::cast(8)));
421-
assert!((ten.mul(&two) == num::cast(20)));
422-
assert!((ten.div(&two) == num::cast(5)));
423-
assert!((ten.modulo(&two) == num::cast(0)));
424-
}
425-
426414
#[test]
427415
#[should_fail]
428416
#[ignore(cfg(windows))]

0 commit comments

Comments
 (0)