Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add impls for Vec #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/abs_diff_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,24 @@ where
}
}

impl<A, B> AbsDiffEq<Vec<B>> for Vec<A>
where
A: AbsDiffEq<B>,
A::Epsilon: Clone,
{
type Epsilon = A::Epsilon;

#[inline]
fn default_epsilon() -> A::Epsilon {
A::default_epsilon()
}

#[inline]
fn abs_diff_eq(&self, other: &Vec<B>, epsilon: A::Epsilon) -> bool {
self.as_slice().abs_diff_eq(other.as_slice(), epsilon)
}
}

#[cfg(feature = "num-complex")]
impl<T: AbsDiffEq> AbsDiffEq for Complex<T>
where
Expand Down
16 changes: 16 additions & 0 deletions src/relative_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,22 @@ where
}
}

impl<A, B> RelativeEq<Vec<B>> for Vec<A>
where
A: RelativeEq<B>,
A::Epsilon: Clone,
{
#[inline]
fn default_max_relative() -> A::Epsilon {
A::default_max_relative()
}

#[inline]
fn relative_eq(&self, other: &Vec<B>, epsilon: A::Epsilon, max_relative: A::Epsilon) -> bool {
self.as_slice().relative_eq(other.as_slice(), epsilon, max_relative)
}
}

#[cfg(feature = "num-complex")]
impl<T: RelativeEq> RelativeEq for Complex<T>
where
Expand Down
16 changes: 16 additions & 0 deletions src/ulps_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,22 @@ where
}
}

impl<A, B> UlpsEq<Vec<B>> for Vec<A>
where
A: UlpsEq<B>,
A::Epsilon: Clone,
{
#[inline]
fn default_max_ulps() -> u32 {
A::default_max_ulps()
}

#[inline]
fn ulps_eq(&self, other: &Vec<B>, epsilon: A::Epsilon, max_ulps: u32) -> bool {
self.as_slice().ulps_eq(other.as_slice(), epsilon, max_ulps)
}
}

#[cfg(feature = "num-complex")]
impl<T: UlpsEq> UlpsEq for Complex<T>
where
Expand Down
18 changes: 18 additions & 0 deletions tests/abs_diff_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,24 @@ mod test_slice {
}
}

mod test_vec {
mod test_f32 {
#[test]
fn test_basic() {
assert_abs_diff_eq!(vec![1.0f32, 2.0f32], vec![1.0f32, 2.0f32]);
assert_abs_diff_ne!(vec![1.0f32, 2.0f32], vec![2.0f32, 1.0f32]);
}
}

mod test_f64 {
#[test]
fn test_basic() {
assert_abs_diff_eq!(vec![1.0f64, 2.0f64], vec![1.0f64, 2.0f64]);
assert_abs_diff_ne!(vec![1.0f64, 2.0f64], vec![2.0f64, 1.0f64]);
}
}
}

#[cfg(feature = "num-complex")]
mod test_complex {
extern crate num_complex;
Expand Down
18 changes: 18 additions & 0 deletions tests/relative_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,24 @@ mod test_slice {
}
}

mod test_vec {
mod test_f32 {
#[test]
fn test_basic() {
assert_relative_eq!(vec![1.0f32, 2.0f32], vec![1.0f32, 2.0f32]);
assert_relative_ne!(vec![1.0f32, 2.0f32], vec![2.0f32, 1.0f32]);
}
}

mod test_f64 {
#[test]
fn test_basic() {
assert_relative_eq!(vec![1.0f64, 2.0f64], vec![1.0f64, 2.0f64]);
assert_relative_ne!(vec![1.0f64, 2.0f64], vec![2.0f64, 1.0f64]);
}
}
}

#[cfg(feature = "num-complex")]
mod test_complex {
extern crate num_complex;
Expand Down
18 changes: 18 additions & 0 deletions tests/ulps_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,24 @@ mod test_slice {
}
}

mod test_vec {
mod test_f32 {
#[test]
fn test_basic() {
assert_ulps_eq!(vec![1.0f32, 2.0f32], vec![1.0f32, 2.0f32]);
assert_ulps_ne!(vec![1.0f32, 2.0f32], vec![2.0f32, 1.0f32]);
}
}

mod test_f64 {
#[test]
fn test_basic() {
assert_ulps_eq!(vec![1.0f64, 2.0f64], vec![1.0f64, 2.0f64]);
assert_ulps_ne!(vec![1.0f64, 2.0f64], vec![2.0f64, 1.0f64]);
}
}
}

#[cfg(feature = "num-complex")]
mod test_complex {
extern crate num_complex;
Expand Down