From 7e44048081cf0399f4264a82b4092a4d9a140f8b Mon Sep 17 00:00:00 2001
From: Udo Eisenbarth <u.eisenbarth@gsi.de>
Date: Thu, 12 Oct 2023 15:52:12 +0200
Subject: [PATCH] Imrprove unit tests for EnergyMeter

---
 src/nodes/beam_splitter.rs | 12 ++++++++++--
 src/nodes/energy_meter.rs  | 21 ++++++++-------------
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/nodes/beam_splitter.rs b/src/nodes/beam_splitter.rs
index 772d63d8..120750e5 100644
--- a/src/nodes/beam_splitter.rs
+++ b/src/nodes/beam_splitter.rs
@@ -105,7 +105,11 @@ impl BeamSplitter {
                     s.scale_vertical(1.0 - self.ratio()).unwrap();
                     out1_2_spectrum = Some(s);
                 }
-                _ => return Err(OpossumError::Analysis("expected DataEnergy value at input port".into())),
+                _ => {
+                    return Err(OpossumError::Analysis(
+                        "expected DataEnergy value at input port".into(),
+                    ))
+                }
             }
         }
         if let Some(Some(in2)) = in2 {
@@ -118,7 +122,11 @@ impl BeamSplitter {
                     s.scale_vertical(1.0 - self.ratio()).unwrap();
                     out2_2_spectrum = Some(s);
                 }
-                _ => return Err(OpossumError::Analysis("expected DataEnergy value at input port".into())),
+                _ => {
+                    return Err(OpossumError::Analysis(
+                        "expected DataEnergy value at input port".into(),
+                    ))
+                }
             }
         }
         let out1_spec = merge_spectra(out1_1_spectrum, out2_2_spectrum);
diff --git a/src/nodes/energy_meter.rs b/src/nodes/energy_meter.rs
index 7ab49fae..cad23adc 100644
--- a/src/nodes/energy_meter.rs
+++ b/src/nodes/energy_meter.rs
@@ -208,32 +208,27 @@ mod test {
     fn analyze() {
         let mut meter = EnergyMeter::default();
         let mut input = LightResult::default();
-        let input_data=Some(LightData::Energy(DataEnergy {
+        let input_data = Some(LightData::Energy(DataEnergy {
             spectrum: create_he_ne_spectrum(1.0),
         }));
-        input.insert(
-            "in1".into(),
-            input_data.clone(),
-        );
+        input.insert("in1".into(), input_data.clone());
         let result = meter.analyze(input, &AnalyzerType::Energy);
         assert!(result.is_ok());
         assert!(result.clone().unwrap().contains_key("out1"));
-        assert!(result.unwrap().get("out1").unwrap().is_some());
+        assert_eq!(result.unwrap().get("out1").unwrap(), &input_data);
     }
     #[test]
     fn analyze_inverted() {
         let mut meter = EnergyMeter::default();
         let mut input = LightResult::default();
         meter.set_property("inverted", true.into()).unwrap();
-        input.insert(
-            "out1".into(),
-            Some(LightData::Energy(DataEnergy {
-                spectrum: create_he_ne_spectrum(1.0),
-            })),
-        );
+        let input_data = Some(LightData::Energy(DataEnergy {
+            spectrum: create_he_ne_spectrum(1.0),
+        }));
+        input.insert("out1".into(), input_data.clone());
         let result = meter.analyze(input, &AnalyzerType::Energy);
         assert!(result.is_ok());
         assert!(result.clone().unwrap().contains_key("in1"));
-        assert!(result.unwrap().get("in1").unwrap().is_some());
+        assert_eq!(result.unwrap().get("in1").unwrap(), &input_data);
     }
 }
-- 
GitLab