Skip to content

Commit 9f8d937

Browse files
committed
---
yaml --- r: 140187 b: refs/heads/try2 c: 20ad931 h: refs/heads/master i: 140185: 4083df6 140183: 1b6f717 v: v3
1 parent 95bc754 commit 9f8d937

File tree

5 files changed

+70
-8
lines changed

5 files changed

+70
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 8f63f9789b12a69723630ae072b6ba63203ed0f6
8+
refs/heads/try2: 20ad931bf337db2efd25e6571e322d31b5b83877
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/num/int-template.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,11 @@ impl Integer for T {
406406
407407
/// Returns `true` if the number can be divided by `other` without leaving a remainder
408408
#[inline(always)]
409-
fn divisible_by(&self, other: &T) -> bool { *self % *other == 0 }
409+
fn is_multiple_of(&self, other: &T) -> bool { *self % *other == 0 }
410410
411411
/// Returns `true` if the number is divisible by `2`
412412
#[inline(always)]
413-
fn is_even(&self) -> bool { self.divisible_by(&2) }
413+
fn is_even(&self) -> bool { self.is_multiple_of(&2) }
414414
415415
/// Returns `true` if the number is not divisible by `2`
416416
#[inline(always)]
@@ -682,6 +682,42 @@ mod tests {
682682
assert_eq!(-(0b11 as T) - (1 as T), (0b11 as T).not());
683683
}
684684
685+
#[test]
686+
fn test_multiple_of() {
687+
assert!((6 as T).is_multiple_of(&(6 as T)));
688+
assert!((6 as T).is_multiple_of(&(3 as T)));
689+
assert!((6 as T).is_multiple_of(&(1 as T)));
690+
assert!((-8 as T).is_multiple_of(&(4 as T)));
691+
assert!((8 as T).is_multiple_of(&(-1 as T)));
692+
assert!((-8 as T).is_multiple_of(&(-2 as T)));
693+
}
694+
695+
#[test]
696+
fn test_even() {
697+
assert_eq!((-4 as T).is_even(), true);
698+
assert_eq!((-3 as T).is_even(), false);
699+
assert_eq!((-2 as T).is_even(), true);
700+
assert_eq!((-1 as T).is_even(), false);
701+
assert_eq!((0 as T).is_even(), true);
702+
assert_eq!((1 as T).is_even(), false);
703+
assert_eq!((2 as T).is_even(), true);
704+
assert_eq!((3 as T).is_even(), false);
705+
assert_eq!((4 as T).is_even(), true);
706+
}
707+
708+
#[test]
709+
fn test_odd() {
710+
assert_eq!((-4 as T).is_odd(), false);
711+
assert_eq!((-3 as T).is_odd(), true);
712+
assert_eq!((-2 as T).is_odd(), false);
713+
assert_eq!((-1 as T).is_odd(), true);
714+
assert_eq!((0 as T).is_odd(), false);
715+
assert_eq!((1 as T).is_odd(), true);
716+
assert_eq!((2 as T).is_odd(), false);
717+
assert_eq!((3 as T).is_odd(), true);
718+
assert_eq!((4 as T).is_odd(), false);
719+
}
720+
685721
#[test]
686722
fn test_bitcount() {
687723
assert_eq!((0b010101 as T).population_count(), 3);

branches/try2/src/libcore/num/num.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ pub trait Integer: Num
8585

8686
fn gcd(&self, other: &Self) -> Self;
8787
fn lcm(&self, other: &Self) -> Self;
88-
fn divisible_by(&self, other: &Self) -> bool;
88+
89+
fn is_multiple_of(&self, other: &Self) -> bool;
8990
fn is_even(&self) -> bool;
9091
fn is_odd(&self) -> bool;
9192
}

branches/try2/src/libcore/num/uint-template.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ impl Integer for T {
238238
239239
/// Returns `true` if the number can be divided by `other` without leaving a remainder
240240
#[inline(always)]
241-
fn divisible_by(&self, other: &T) -> bool { *self % *other == 0 }
241+
fn is_multiple_of(&self, other: &T) -> bool { *self % *other == 0 }
242242
243243
/// Returns `true` if the number is divisible by `2`
244244
#[inline(always)]
245-
fn is_even(&self) -> bool { self.divisible_by(&2) }
245+
fn is_even(&self) -> bool { self.is_multiple_of(&2) }
246246
247247
/// Returns `true` if the number is not divisible by `2`
248248
#[inline(always)]
@@ -415,6 +415,31 @@ mod tests {
415415
assert_eq!((99 as T).lcm(&17), 1683 as T);
416416
}
417417
418+
#[test]
419+
fn test_multiple_of() {
420+
assert!((6 as T).is_multiple_of(&(6 as T)));
421+
assert!((6 as T).is_multiple_of(&(3 as T)));
422+
assert!((6 as T).is_multiple_of(&(1 as T)));
423+
}
424+
425+
#[test]
426+
fn test_even() {
427+
assert_eq!((0 as T).is_even(), true);
428+
assert_eq!((1 as T).is_even(), false);
429+
assert_eq!((2 as T).is_even(), true);
430+
assert_eq!((3 as T).is_even(), false);
431+
assert_eq!((4 as T).is_even(), true);
432+
}
433+
434+
#[test]
435+
fn test_odd() {
436+
assert_eq!((0 as T).is_odd(), false);
437+
assert_eq!((1 as T).is_odd(), true);
438+
assert_eq!((2 as T).is_odd(), false);
439+
assert_eq!((3 as T).is_odd(), true);
440+
assert_eq!((4 as T).is_odd(), false);
441+
}
442+
418443
#[test]
419444
fn test_bitwise() {
420445
assert_eq!(0b1110 as T, (0b1100 as T).bitor(&(0b1010 as T)));

branches/try2/src/libstd/num/bigint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl Integer for BigUint {
428428

429429
/// Returns `true` if the number can be divided by `other` without leaving a remainder
430430
#[inline(always)]
431-
fn divisible_by(&self, other: &BigUint) -> bool { (*self % *other).is_zero() }
431+
fn is_multiple_of(&self, other: &BigUint) -> bool { (*self % *other).is_zero() }
432432

433433
/// Returns `true` if the number is divisible by `2`
434434
#[inline(always)]
@@ -973,7 +973,7 @@ impl Integer for BigInt {
973973

974974
/// Returns `true` if the number can be divided by `other` without leaving a remainder
975975
#[inline(always)]
976-
fn divisible_by(&self, other: &BigInt) -> bool { self.data.divisible_by(&other.data) }
976+
fn is_multiple_of(&self, other: &BigInt) -> bool { self.data.is_multiple_of(&other.data) }
977977

978978
/// Returns `true` if the number is divisible by `2`
979979
#[inline(always)]

0 commit comments

Comments
 (0)