Skip to content
Snippets Groups Projects
Commit bc40a8aa authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

Add unit test for dummy.analyze

parent c183872e
No related branches found
No related tags found
No related merge requests found
Pipeline #7705 passed
......@@ -11,7 +11,7 @@ use crate::spectrum::Spectrum;
/// [`AnalyzerType`](crate::analyzer::AnalyzerType). For example, an energy analysis ([`LightData::Energy`]) only
/// contains a [`Spectrum`] information, while a geometric analysis ([`LightData::Geometric]) constains a set of optical
/// ray data.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum LightData {
/// data type used for energy analysis.
Energy(DataEnergy),
......@@ -45,12 +45,12 @@ impl Display for LightData {
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DataEnergy {
pub spectrum: Spectrum,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DataGeometric {
_ray: i32,
}
......@@ -134,6 +134,8 @@ impl Dottable for Dummy {}
#[cfg(test)]
mod test {
use crate::{lightdata::{DataEnergy, LightData}, spectrum::create_he_ne_spectrum};
use super::*;
#[test]
fn new() {
......@@ -169,4 +171,50 @@ mod test {
let node = Dummy::default();
assert_eq!(node.node_type(), "dummy");
}
#[test]
fn analyze_ok() {
let mut dummy = Dummy::default();
let mut input=LightResult::default();
let input_light=LightData::Energy(DataEnergy{spectrum:create_he_ne_spectrum(1.0)});
input.insert("front".into(), Some(input_light.clone()));
let output=dummy.analyze(input, &AnalyzerType::Energy);
assert!(output.is_ok());
let output=output.unwrap();
assert!(output.contains_key("rear".into()));
assert_eq!(output.len(),1);
let output=output.get("rear".into()).unwrap();
assert!(output.is_some());
let output=output.clone().unwrap();
assert_eq!(output, input_light);
}
#[test]
fn analyze_wrong() {
let mut dummy = Dummy::default();
let mut input=LightResult::default();
let input_light=LightData::Energy(DataEnergy{spectrum:create_he_ne_spectrum(1.0)});
input.insert("rear".into(), Some(input_light.clone()));
let output=dummy.analyze(input, &AnalyzerType::Energy);
assert!(output.is_ok());
let output=output.unwrap();
let output=output.get("rear".into()).unwrap();
assert!(output.is_none());
}
#[test]
fn analyze_inverse() {
let mut dummy = Dummy::default();
dummy.set_property("inverted", true.into()).unwrap();
let mut input=LightResult::default();
let input_light=LightData::Energy(DataEnergy{spectrum:create_he_ne_spectrum(1.0)});
input.insert("rear".into(), Some(input_light.clone()));
let output=dummy.analyze(input, &AnalyzerType::Energy);
assert!(output.is_ok());
let output=output.unwrap();
assert!(output.contains_key("front".into()));
assert_eq!(output.len(),1);
let output=output.get("front".into()).unwrap();
assert!(output.is_some());
let output=output.clone().unwrap();
assert_eq!(output, input_light);
}
}
......@@ -21,7 +21,7 @@ use std::fs::File;
///
/// This structure handles an array of values over a given wavelength range. Although the interface
/// is still limited, the structure is prepared for handling also non-equidistant wavelength slots.
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, PartialEq)]
pub struct Spectrum {
data: Array1<(f64, f64)>, // (wavelength in meters, data in 1/meters)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment