use crate::common::filter::op::Op;
use crate::common::filter::op::OpBase;
#[derive(Debug, Clone)]
pub struct Operand {
op: OpBase,
}
impl Operand {
pub fn new(symbol: &str) -> Self {
Self {
op: OpBase::new(symbol),
}
}
}
impl Op for Operand {
fn symbol(&self) -> &str {
self.op.symbol()
}
}
#[cfg(test)]
mod tests {
use crate::common::filter::op::Op;
use crate::common::filter::operand::Operand;
#[test]
fn create_operand() {
let operand = Operand::new("+");
assert_eq!(operand.symbol(), "+");
}
#[test]
fn create_operand_with_different_symbols() {
let symbols = vec!["+", "-", "*", "/", "==", "!=", ">", "<"];
for sym in symbols {
let operand = Operand::new(sym);
assert_eq!(operand.symbol(), sym);
}
}
#[test]
fn create_operand_with_empty_string() {
let operand = Operand::new("");
assert_eq!(operand.symbol(), "");
}
#[test]
fn operand_clone_works() {
let operand = Operand::new("+");
let cloned = operand.clone();
assert_eq!(cloned.symbol(), "+");
}
}