Added approx, maybe that will fix tests on ci.
This commit is contained in:
62
src/lib.rs
62
src/lib.rs
@@ -1,5 +1,9 @@
|
||||
extern crate statrs;
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
extern crate approx;
|
||||
|
||||
mod factor_graph;
|
||||
mod gaussian;
|
||||
mod math;
|
||||
@@ -278,6 +282,7 @@ where
|
||||
|
||||
let _ata = BETA.powi(2) * &rotated_a_matrix * &a_matrix;
|
||||
let _atsa = &rotated_a_matrix * &variance_matrix * &a_matrix;
|
||||
|
||||
let start = mean_matrix.transpose() * &a_matrix;
|
||||
let middle = &_ata + &_atsa;
|
||||
let end = &rotated_a_matrix * &mean_matrix;
|
||||
@@ -290,14 +295,48 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::f64;
|
||||
|
||||
use approx::{AbsDiffEq, RelativeEq};
|
||||
|
||||
use super::*;
|
||||
|
||||
impl AbsDiffEq for Rating {
|
||||
type Epsilon = f64;
|
||||
|
||||
#[inline]
|
||||
fn default_epsilon() -> Self::Epsilon {
|
||||
f64::default_epsilon()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool {
|
||||
self.mu.abs_diff_eq(&other.mu, epsilon) && self.sigma.abs_diff_eq(&other.sigma, epsilon)
|
||||
}
|
||||
}
|
||||
|
||||
impl RelativeEq for Rating {
|
||||
fn default_max_relative() -> Self::Epsilon {
|
||||
f64::default_max_relative()
|
||||
}
|
||||
|
||||
fn relative_eq(
|
||||
&self,
|
||||
other: &Self,
|
||||
epsilon: Self::Epsilon,
|
||||
max_relative: Self::Epsilon,
|
||||
) -> bool {
|
||||
self.mu.relative_eq(&other.mu, epsilon, max_relative)
|
||||
&& self.sigma.relative_eq(&other.sigma, epsilon, max_relative)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_quality_1vs1() {
|
||||
let alice = Rating::new(MU, SIGMA);
|
||||
let bob = Rating::new(MU, SIGMA);
|
||||
|
||||
assert_eq!(quality(&[&[alice], &[bob]]), 0.4472135954999579);
|
||||
assert_relative_eq!(quality(&[&[alice], &[bob]]), 0.4472135954999579);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -307,16 +346,17 @@ mod tests {
|
||||
let chris = Rating::new(MU, SIGMA);
|
||||
let darren = Rating::new(MU, SIGMA);
|
||||
|
||||
let new_ratings = rate(&[&[alice], &[bob], &[chris], &[darren]]);
|
||||
let expected_ratings = vec![
|
||||
Rating::new(33.20778932559525, 6.347937214998893),
|
||||
Rating::new(27.401497882797486, 5.787057812482782),
|
||||
Rating::new(22.598576351652632, 5.7871159419307645),
|
||||
Rating::new(16.79337409436942, 6.348053083319977),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
new_ratings,
|
||||
vec![
|
||||
Rating::new(33.20778932559525, 6.347937214998893),
|
||||
Rating::new(27.401497882797486, 5.787057812482782),
|
||||
Rating::new(22.598576351652632, 5.7871159419307645),
|
||||
Rating::new(16.79337409436942, 6.348053083319977),
|
||||
]
|
||||
);
|
||||
let ratings = rate(&[&[alice], &[bob], &[chris], &[darren]]);
|
||||
|
||||
for (rating, expected) in ratings.iter().zip(expected_ratings.iter()) {
|
||||
assert_relative_eq!(rating, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user