@@ -54,7 +54,7 @@ use serde::{Serialize, Deserialize};
5454/// Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3
5555/// (September 2000), 363-372.
5656/// DOI:[10.1145/358407.358414](https://doi.acm.org/10.1145/358407.358414)
57- #[ derive( Clone , Copy , Debug ) ]
57+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
5858#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
5959pub struct Gamma < F >
6060where
@@ -91,7 +91,7 @@ impl fmt::Display for Error {
9191#[ cfg_attr( doc_cfg, doc( cfg( feature = "std" ) ) ) ]
9292impl std:: error:: Error for Error { }
9393
94- #[ derive( Clone , Copy , Debug ) ]
94+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
9595#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
9696enum GammaRepr < F >
9797where
@@ -119,7 +119,7 @@ where
119119///
120120/// See `Gamma` for sampling from a Gamma distribution with general
121121/// shape parameters.
122- #[ derive( Clone , Copy , Debug ) ]
122+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
123123#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
124124struct GammaSmallShape < F >
125125where
@@ -135,7 +135,7 @@ where
135135///
136136/// See `Gamma` for sampling from a Gamma distribution with general
137137/// shape parameters.
138- #[ derive( Clone , Copy , Debug ) ]
138+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
139139#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
140140struct GammaLargeShape < F >
141141where
@@ -280,7 +280,7 @@ where
280280/// let v = chi.sample(&mut rand::thread_rng());
281281/// println!("{} is from a χ²(11) distribution", v)
282282/// ```
283- #[ derive( Clone , Copy , Debug ) ]
283+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
284284#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
285285pub struct ChiSquared < F >
286286where
@@ -314,7 +314,7 @@ impl fmt::Display for ChiSquaredError {
314314#[ cfg_attr( doc_cfg, doc( cfg( feature = "std" ) ) ) ]
315315impl std:: error:: Error for ChiSquaredError { }
316316
317- #[ derive( Clone , Copy , Debug ) ]
317+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
318318#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
319319enum ChiSquaredRepr < F >
320320where
@@ -385,7 +385,7 @@ where
385385/// let v = f.sample(&mut rand::thread_rng());
386386/// println!("{} is from an F(2, 32) distribution", v)
387387/// ```
388- #[ derive( Clone , Copy , Debug ) ]
388+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
389389#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
390390pub struct FisherF < F >
391391where
@@ -472,7 +472,7 @@ where
472472/// let v = t.sample(&mut rand::thread_rng());
473473/// println!("{} is from a t(11) distribution", v)
474474/// ```
475- #[ derive( Clone , Copy , Debug ) ]
475+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
476476#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
477477pub struct StudentT < F >
478478where
@@ -522,15 +522,15 @@ where
522522/// Generating beta variates with nonintegral shape parameters.
523523/// Communications of the ACM 21, 317-322.
524524/// https://doi.org/10.1145/359460.359482
525- #[ derive( Clone , Copy , Debug ) ]
525+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
526526#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
527527enum BetaAlgorithm < N > {
528528 BB ( BB < N > ) ,
529529 BC ( BC < N > ) ,
530530}
531531
532532/// Algorithm BB for `min(alpha, beta) > 1`.
533- #[ derive( Clone , Copy , Debug ) ]
533+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
534534#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
535535struct BB < N > {
536536 alpha : N ,
@@ -539,7 +539,7 @@ struct BB<N> {
539539}
540540
541541/// Algorithm BC for `min(alpha, beta) <= 1`.
542- #[ derive( Clone , Copy , Debug ) ]
542+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
543543#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
544544struct BC < N > {
545545 alpha : N ,
@@ -560,7 +560,7 @@ struct BC<N> {
560560/// let v = beta.sample(&mut rand::thread_rng());
561561/// println!("{} is from a Beta(2, 5) distribution", v);
562562/// ```
563- #[ derive( Clone , Copy , Debug ) ]
563+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
564564#[ cfg_attr( feature = "serde1" , derive( Serialize , Deserialize ) ) ]
565565pub struct Beta < F >
566566where
@@ -811,4 +811,29 @@ mod test {
811811 assert ! ( !beta. sample( & mut rng) . is_nan( ) , "failed at i={}" , i) ;
812812 }
813813 }
814+
815+ #[ test]
816+ fn gamma_distributions_can_be_compared ( ) {
817+ assert_eq ! ( Gamma :: new( 1.0 , 2.0 ) , Gamma :: new( 1.0 , 2.0 ) ) ;
818+ }
819+
820+ #[ test]
821+ fn beta_distributions_can_be_compared ( ) {
822+ assert_eq ! ( Beta :: new( 1.0 , 2.0 ) , Beta :: new( 1.0 , 2.0 ) ) ;
823+ }
824+
825+ #[ test]
826+ fn chi_squared_distributions_can_be_compared ( ) {
827+ assert_eq ! ( ChiSquared :: new( 1.0 ) , ChiSquared :: new( 1.0 ) ) ;
828+ }
829+
830+ #[ test]
831+ fn fisher_f_distributions_can_be_compared ( ) {
832+ assert_eq ! ( FisherF :: new( 1.0 , 2.0 ) , FisherF :: new( 1.0 , 2.0 ) ) ;
833+ }
834+
835+ #[ test]
836+ fn student_t_distributions_can_be_compared ( ) {
837+ assert_eq ! ( StudentT :: new( 1.0 ) , StudentT :: new( 1.0 ) ) ;
838+ }
814839}
0 commit comments