@@ -15,6 +15,7 @@ use std::collections::BTreeSet;
1515use std:: fmt:: Debug ;
1616use std:: marker:: PhantomData ;
1717
18+ /// Multi-color feature which evaluates non-color dependent feature for each passband.
1819#[ derive( Clone , Debug , Serialize , Deserialize , JsonSchema ) ]
1920#[ serde( bound(
2021 deserialize = "P: PassbandTrait + Deserialize<'de>, T: Float, F: FeatureEvaluator<T>"
3536 T : Float ,
3637 F : FeatureEvaluator < T > ,
3738{
39+ /// Creates a new instance of `MonochromeFeature`.
40+ ///
41+ /// # Arguments
42+ /// - `feature` - non-multi-color feature to evaluate for each passband.
43+ /// - `passband_set` - set of passbands to evaluate the feature for.
3844 pub fn new ( feature : F , passband_set : BTreeSet < P > ) -> Self {
3945 let names = passband_set
4046 . iter ( )
@@ -130,3 +136,32 @@ where
130136 }
131137 }
132138}
139+
140+ #[ cfg( test) ]
141+ mod tests {
142+ use super :: * ;
143+
144+ use crate :: features:: Mean ;
145+ use crate :: multicolor:: passband:: MonochromePassband ;
146+ use crate :: Feature ;
147+
148+ #[ test]
149+ fn test_monochrome_feature ( ) {
150+ let feature: MonochromeFeature < MonochromePassband < _ > , f64 , Feature < _ > > =
151+ MonochromeFeature :: new (
152+ Mean :: default ( ) . into ( ) ,
153+ [
154+ MonochromePassband :: new ( 4700e-8 , "g" ) ,
155+ MonochromePassband :: new ( 6200e-8 , "r" ) ,
156+ ]
157+ . into_iter ( )
158+ . collect ( ) ,
159+ ) ;
160+ assert_eq ! ( feature. get_names( ) , vec![ "mean_g" , "mean_r" ] ) ;
161+ assert_eq ! (
162+ feature. get_descriptions( ) ,
163+ vec![ "mean magnitude, passband g" , "mean magnitude, passband r" ]
164+ ) ;
165+ assert_eq ! ( feature. get_info( ) . size, 2 ) ;
166+ }
167+ }
0 commit comments