Auto merge of #246 - cuviper:complex-eq, r=hauleth

complex: derive Eq

Fixes #245.
This commit is contained in:
Homu 2016-12-06 18:48:42 +09:00
commit 7db32a4ecd
1 changed files with 15 additions and 1 deletions

View File

@ -33,7 +33,7 @@ use traits::{Zero, One, Num, Float};
// probably doesn't map to C's _Complex correctly.
/// A complex number in Cartesian form.
#[derive(PartialEq, Copy, Clone, Hash, Debug, Default)]
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug, Default)]
#[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
pub struct Complex<T> {
/// Real portion of the complex number
@ -1220,6 +1220,20 @@ mod test {
assert!(::hash(&c) != ::hash(&a));
}
#[test]
fn test_hashset() {
use std::collections::HashSet;
let a = Complex::new(0i32, 0i32);
let b = Complex::new(1i32, 0i32);
let c = Complex::new(0i32, 1i32);
let set: HashSet<_> = [a, b, c].iter().cloned().collect();
assert!(set.contains(&a));
assert!(set.contains(&b));
assert!(set.contains(&c));
assert!(!set.contains(&(a + b + c)));
}
#[test]
fn test_is_nan() {
assert!(!_1_1i.is_nan());