use crate::key::CKey;
use std::fmt::Formatter;
impl std::fmt::Debug for CKey {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(
f,
"{:016x}{:016x}{:016x}{:016x}",
self.data[0], self.data[1], self.data[2], self.data[3]
)
}
}
impl std::fmt::Display for CKey {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:0.9}", f64::from(*self))
}
}
#[cfg(test)]
mod tests {
use super::CKey;
#[test]
fn test_fmt_debug() {
assert_eq!(
"0000000000000000000000000000000000000000000000000000000000000000",
format!("{:?}", CKey::zero())
);
assert_eq!(
"0000000000000000000000000000000000000000000000000000000000000001",
format!("{:?}", CKey::unit())
);
assert_eq!(
"8000000000000000000000000000000000000000000000000000000000000000",
format!("{:?}", CKey::halfway())
);
assert_eq!(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
format!("{:?}", CKey::last())
);
}
#[test]
fn test_fmt_display() {
assert_eq!("0.000000000", format!("{}", CKey::zero()));
assert_eq!("0.000000000", format!("{}", CKey::unit()));
assert_eq!("0.500000000", format!("{}", CKey::halfway()));
assert_eq!("1.000000000", format!("{}", CKey::last()));
}
}