use crate::core::value::Value;
#[derive(Debug)]
pub enum Item<Op, Val = Value>
where
Op: core::fmt::Debug + core::cmp::Eq,
Val: core::fmt::Debug + core::cmp::PartialEq,
{
Operator(Op),
Value(Val),
}
impl<Op, Val> PartialEq for Item<Op, Val>
where
Op: core::fmt::Debug + core::cmp::Eq,
Val: core::fmt::Debug + core::cmp::PartialEq,
{
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Operator(op), Self::Operator(other_op)) => op == other_op,
(Self::Value(value), Self::Value(other_value)) => value == other_value,
_ => false,
}
}
}
#[cfg(test)]
mod tests {
use crate::core::item::Item::{self, *};
use crate::core::value::Value::*;
#[test]
fn test_eq() {
let op_item1: Item<u8> = Operator(u8::default());
let op_item2: Item<u8> = Operator(u8::default());
assert_eq!(op_item1, op_item2);
let val_item1: Item<u8> = Value(Integer(i128::default()));
let val_item2: Item<u8> = Value(Integer(i128::default()));
assert_eq!(val_item1, val_item2);
}
#[test]
fn test_ne() {
let op_item1: Item<u8> = Operator(u8::default());
let op_item2: Item<u8> = Operator(u8::default() + 1);
assert_ne!(op_item1, op_item2);
let val_item1: Item<u8> = Value(Integer(i128::default()));
let val_item2: Item<u8> = Value(Integer(i128::default() + 1));
assert_ne!(val_item1, val_item2);
assert_ne!(op_item1, val_item1);
assert_ne!(op_item1, val_item2);
assert_ne!(op_item2, val_item1);
assert_ne!(op_item2, val_item2);
}
}