Newer
Older
use crate::properties::{Properties, Proptype, Property};
type Result<T> = std::result::Result<T, OpossumError>;
/// A fake / dummy component without any optical functionality.
///
/// Any [`LightResult`] is directly forwarded without any modification. It is mainly used for
/// development and debugging purposes.
///
/// ## Optical Ports
/// - Inputs
/// - `front`
/// - Outputs
/// - `rear`
pub struct Dummy {
is_inverted: bool,
impl Default for Dummy {
fn default() -> Self {
let mut props= Properties::default();
props.set("name", Property{prop: Proptype::String("udo".into())});
Self {
is_inverted: Default::default(),
name: String::from("dummy"),
impl Dummy {
/// Creates a new [`Dummy`] with a given name.
pub fn new(name: &str) -> Self {
let mut props= Properties::default();
props.set("name", Property{prop: Proptype::String(name.into())});
fn set_name(&mut self, name: &str) {
self.name = name.to_owned()
}
fn name(&self) -> &str {
&self.name
}
let mut ports = OpticPorts::new();
ports.add_input("front").unwrap();
ports.add_output("rear").unwrap();
ports
}
fn analyze(
&mut self,
incoming_data: LightResult,
_analyzer_type: &AnalyzerType,
) -> Result<LightResult> {
if !self.is_inverted {
if let Some(data) = incoming_data.get("front") {
Ok(HashMap::from([("rear".into(), data.clone())]))
} else {
Ok(HashMap::from([("rear".into(), None)]))
}
} else if let Some(data) = incoming_data.get("rear") {
Ok(HashMap::from([("front".into(), data.clone())]))
fn set_inverted(&mut self, inverted: bool) {
fn inverted(&self) -> bool {
self.is_inverted
}
fn properties(&self) -> Properties {
self.props.clone()
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn new() {
let node = Dummy::new("Test");
assert_eq!(node.name, "Test");
assert_eq!(node.inverted(), false);
}
#[test]
fn default() {
let node = Dummy::default();
assert_eq!(node.name, "dummy");
assert_eq!(node.inverted(), false);
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
}
#[test]
fn set_name() {
let mut node = Dummy::default();
node.set_name("Test1");
assert_eq!(node.name, "Test1")
}
#[test]
fn name() {
let mut node = Dummy::default();
node.set_name("Test1");
assert_eq!(node.name(), "Test1")
}
#[test]
fn set_inverted() {
let mut node = Dummy::default();
node.set_inverted(true);
assert_eq!(node.is_inverted, true)
}
#[test]
fn inverted() {
let mut node = Dummy::default();
node.set_inverted(true);
assert_eq!(node.inverted(), true)
}
#[test]
fn is_detector() {
let node = Dummy::default();
assert_eq!(node.is_detector(), false);
}
#[test]
fn node_type() {
let node = Dummy::default();
assert_eq!(node.node_type(), "dummy");
}
}