diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index a60f80b9aef2..5acabecb6ee5 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -373,6 +373,13 @@ impl SmallIntMap { } } +impl PartialOrd for SmallIntMap { + #[inline] + fn partial_cmp(&self, other: &SmallIntMap) -> Option { + iter::order::partial_cmp(self.iter(), other.iter()) + } +} + impl fmt::Show for SmallIntMap { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); @@ -770,6 +777,38 @@ mod test_map { assert!(a == b); } + #[test] + fn test_lt() { + let mut a = SmallIntMap::new(); + let mut b = SmallIntMap::new(); + + assert!(!(a < b) && !(b < a)); + assert!(b.insert(2u, 5i)); + assert!(a < b); + assert!(a.insert(2, 7)); + assert!(!(a < b) && b < a); + assert!(b.insert(1, 0)); + assert!(b < a); + assert!(a.insert(0, 6)); + assert!(a < b); + assert!(a.insert(6, 2)); + assert!(a < b && !(b < a)); + } + + #[test] + fn test_ord() { + let mut a = SmallIntMap::new(); + let mut b = SmallIntMap::new(); + + assert!(a <= b && a >= b); + assert!(a.insert(1u, 1i)); + assert!(a > b && a >= b); + assert!(b < a && b <= a); + assert!(b.insert(2, 2)); + assert!(b > a && b >= a); + assert!(a < b && a <= b); + } + #[test] fn test_hash() { let mut x = SmallIntMap::new();