Skip to content

Commit

Permalink
test: assert Send and Sync for error types
Browse files Browse the repository at this point in the history
Co-authored-by: FreezyLemon <[email protected]>
  • Loading branch information
YeungOnion and FreezyLemon committed Sep 9, 2024
1 parent f8793d1 commit 6cd01db
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/distribution/dirichlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,12 @@ where
#[rustfmt::skip]
#[cfg(test)]
mod tests {
use super::*;

use std::fmt::{Debug, Display};

use nalgebra::{dmatrix, dvector, vector, DimMin, OVector};

use crate::{
distribution::{Continuous, Dirichlet},
statistics::{MeanN, VarianceN},
};

fn try_create<D>(alpha: OVector<f64, D>) -> Dirichlet<D>
where
D: DimMin<D, Output = D>,
Expand Down Expand Up @@ -580,4 +577,10 @@ mod tests {
let n = try_create(vector![0.1, 0.3, 0.5, 0.8]);
n.ln_pdf(&vector![0.5, 0.25, 0.8, 0.9]);
}

#[test]
fn test_error_is_sync_send() {
fn assert_sync_send<T: Sync + Send>() {}
assert_sync_send::<DirichletError>();
}
}
7 changes: 7 additions & 0 deletions src/distribution/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ pub mod test {
)
}
}

/// Asserts that associated error type is Send and Sync
#[test]
fn test_error_is_sync_send() {
fn assert_sync_send<T: Sync + Send>() {}
assert_sync_send::<$dist_err>();
}
};
}

Expand Down
6 changes: 6 additions & 0 deletions src/distribution/multinomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,12 @@ mod tests {
);
}

#[test]
fn test_error_is_sync_send() {
fn assert_sync_send<T: Sync + Send>() {}
assert_sync_send::<MultinomialError>();
}

// #[test]
// #[should_panic]
// fn test_pmf_x_wrong_length() {
Expand Down
8 changes: 8 additions & 0 deletions src/distribution/multivariate_normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ mod tests {
statistics::{Max, MeanN, Min, Mode, VarianceN},
};

use super::MultivariateNormalError;

fn try_create<D>(mean: OVector<f64, D>, covariance: OMatrix<f64, D, D>) -> MultivariateNormal<D>
where
D: DimMin<D, Output = D>,
Expand Down Expand Up @@ -703,4 +705,10 @@ mod tests {
let mvn = MultivariateNormal::new(vec![0., 0.], vec![1., 0., 0., 1.,]).unwrap();
mvn.pdf(&vec![1.].into()); // x.size != mu.size
}

#[test]
fn test_error_is_sync_send() {
fn assert_sync_send<T: Sync + Send>() {}
assert_sync_send::<MultivariateNormalError>();
}
}
8 changes: 7 additions & 1 deletion src/distribution/multivariate_students_t.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ mod tests {
statistics::{Max, MeanN, Min, Mode, VarianceN},
};

use super::MultivariateStudentError;

fn try_create(location: Vec<f64>, scale: Vec<f64>, freedom: f64) -> MultivariateStudent<Dyn>
{
let mvs = MultivariateStudent::new(location, scale, freedom);
Expand Down Expand Up @@ -614,5 +616,9 @@ mod tests {
assert_eq!(mvs.scale_chol_decomp(), &OMatrix::<f64, Dyn, Dyn>::identity(2, 2));
}


#[test]
fn test_error_is_sync_send() {
fn assert_sync_send<T: Sync + Send>() {}
assert_sync_send::<MultivariateStudentError>();
}
}

0 comments on commit 6cd01db

Please sign in to comment.