use super::reference::Reference;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ErrorBarType {
Plus,
Minus,
PlusMinus,
}
impl ErrorBarType {
pub fn as_str(self) -> &'static str {
match self {
ErrorBarType::Plus => "plus",
ErrorBarType::Minus => "minus",
ErrorBarType::PlusMinus => "both",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ErrorBar {
pub bar_type: ErrorBarType,
pub reference: Reference,
}
impl ErrorBar {
pub fn new(bar_type: ErrorBarType, reference: Reference) -> Self {
ErrorBar {
bar_type,
reference,
}
}
pub fn values(&self) -> Option<&[super::reference::CellValue]> {
self.reference.values()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tokens_match_python_flags() {
assert_eq!(ErrorBarType::Plus.as_str(), "plus");
assert_eq!(ErrorBarType::Minus.as_str(), "minus");
assert_eq!(ErrorBarType::PlusMinus.as_str(), "both");
}
#[test]
fn carries_a_reference() {
let reference = Reference::new("S", (0, 0), Some((2, 0)), None, None).unwrap();
let bar = ErrorBar::new(ErrorBarType::PlusMinus, reference);
assert_eq!(bar.bar_type, ErrorBarType::PlusMinus);
assert!(bar.values().is_none());
}
}