complex: derive Eq

Fixes #245.
This commit is contained in:
Josh Stone 2016-12-05 23:11:40 -08:00
parent dc8c8fc3f6
commit 5531031252
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. // probably doesn't map to C's _Complex correctly.
/// A complex number in Cartesian form. /// 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))] #[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
pub struct Complex<T> { pub struct Complex<T> {
/// Real portion of the complex number /// Real portion of the complex number
@ -1220,6 +1220,20 @@ mod test {
assert!(::hash(&c) != ::hash(&a)); 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] #[test]
fn test_is_nan() { fn test_is_nan() {
assert!(!_1_1i.is_nan()); assert!(!_1_1i.is_nan());