use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(i32)]
pub enum OptionType {
Put = -1,
Call = 1,
}
impl fmt::Display for OptionType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
OptionType::Call => f.write_str("Call"),
OptionType::Put => f.write_str("Put"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn discriminants_match_quantlib() {
assert_eq!(OptionType::Put as i32, -1);
assert_eq!(OptionType::Call as i32, 1);
}
#[test]
fn display_matches_quantlib_output() {
assert_eq!(OptionType::Call.to_string(), "Call");
assert_eq!(OptionType::Put.to_string(), "Put");
}
}