Skip to content

Commit

Permalink
Implement PartialOrd for SmallIntMap
Browse files Browse the repository at this point in the history
  • Loading branch information
nham committed Jul 28, 2014
1 parent 16acc10 commit 220f8f6
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/libcollections/smallintmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ impl<V:Clone> SmallIntMap<V> {
}
}

impl<V: PartialOrd> PartialOrd for SmallIntMap<V> {
#[inline]
fn partial_cmp(&self, other: &SmallIntMap<V>) -> Option<Ordering> {
iter::order::partial_cmp(self.iter(), other.iter())
}
}

impl<V: fmt::Show> fmt::Show for SmallIntMap<V> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "{{"));
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 220f8f6

Please sign in to comment.