#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "mem_size", derive(mem_dbg::MemSize))]
#[cfg_attr(feature = "mem_dbg", derive(mem_dbg::MemDbg))]
#[cfg_attr(feature = "mem_size", mem_size(flat))]
pub enum CaliforniumIsotope {
Cf237,
Cf238,
Cf239,
Cf240,
Cf241,
Cf242,
Cf243,
Cf244,
Cf245,
Cf246,
Cf247,
Cf248,
Cf249,
Cf250,
Cf251,
Cf252,
Cf253,
Cf254,
Cf255,
Cf256,
}
impl super::RelativeAtomicMass for CaliforniumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Cf237 => 237.062198f64,
Self::Cf238 => 238.06149f64,
Self::Cf239 => 239.06253f64,
Self::Cf240 => 240.062256f64,
Self::Cf241 => 241.06369f64,
Self::Cf242 => 242.063754f64,
Self::Cf243 => 243.06548f64,
Self::Cf244 => 244.0660008f64,
Self::Cf245 => 245.0680487f64,
Self::Cf246 => 246.0688055f64,
Self::Cf247 => 247.070965f64,
Self::Cf248 => 248.0721851f64,
Self::Cf249 => 249.0748539f64,
Self::Cf250 => 250.0764062f64,
Self::Cf251 => 251.0795886f64,
Self::Cf252 => 252.0816272f64,
Self::Cf253 => 253.0851345f64,
Self::Cf254 => 254.087324f64,
Self::Cf255 => 255.09105f64,
Self::Cf256 => 256.09344f64,
}
}
}
impl super::ElementVariant for CaliforniumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Cf
}
}
impl super::MassNumber for CaliforniumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Cf237 => 237u16,
Self::Cf238 => 238u16,
Self::Cf239 => 239u16,
Self::Cf240 => 240u16,
Self::Cf241 => 241u16,
Self::Cf242 => 242u16,
Self::Cf243 => 243u16,
Self::Cf244 => 244u16,
Self::Cf245 => 245u16,
Self::Cf246 => 246u16,
Self::Cf247 => 247u16,
Self::Cf248 => 248u16,
Self::Cf249 => 249u16,
Self::Cf250 => 250u16,
Self::Cf251 => 251u16,
Self::Cf252 => 252u16,
Self::Cf253 => 253u16,
Self::Cf254 => 254u16,
Self::Cf255 => 255u16,
Self::Cf256 => 256u16,
}
}
}
impl super::IsotopicComposition for CaliforniumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
None
}
}
impl super::MostAbundantIsotope for CaliforniumIsotope {
fn most_abundant_isotope() -> Self {
Self::Cf256
}
}
impl From<CaliforniumIsotope> for crate::Isotope {
fn from(isotope: CaliforniumIsotope) -> Self {
crate::Isotope::Cf(isotope)
}
}
impl From<CaliforniumIsotope> for crate::Element {
fn from(_isotope: CaliforniumIsotope) -> Self {
crate::Element::Cf
}
}
impl TryFrom<u64> for CaliforniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
237u64 => Ok(Self::Cf237),
238u64 => Ok(Self::Cf238),
239u64 => Ok(Self::Cf239),
240u64 => Ok(Self::Cf240),
241u64 => Ok(Self::Cf241),
242u64 => Ok(Self::Cf242),
243u64 => Ok(Self::Cf243),
244u64 => Ok(Self::Cf244),
245u64 => Ok(Self::Cf245),
246u64 => Ok(Self::Cf246),
247u64 => Ok(Self::Cf247),
248u64 => Ok(Self::Cf248),
249u64 => Ok(Self::Cf249),
250u64 => Ok(Self::Cf250),
251u64 => Ok(Self::Cf251),
252u64 => Ok(Self::Cf252),
253u64 => Ok(Self::Cf253),
254u64 => Ok(Self::Cf254),
255u64 => Ok(Self::Cf255),
256u64 => Ok(Self::Cf256),
_ => Err(crate::errors::Error::Isotope(crate::Element::Cf, value)),
}
}
}
impl TryFrom<u8> for CaliforniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for CaliforniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for CaliforniumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u32) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl core::fmt::Display for CaliforniumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Cf237 => write!(f, "Cf237"),
Self::Cf238 => write!(f, "Cf238"),
Self::Cf239 => write!(f, "Cf239"),
Self::Cf240 => write!(f, "Cf240"),
Self::Cf241 => write!(f, "Cf241"),
Self::Cf242 => write!(f, "Cf242"),
Self::Cf243 => write!(f, "Cf243"),
Self::Cf244 => write!(f, "Cf244"),
Self::Cf245 => write!(f, "Cf245"),
Self::Cf246 => write!(f, "Cf246"),
Self::Cf247 => write!(f, "Cf247"),
Self::Cf248 => write!(f, "Cf248"),
Self::Cf249 => write!(f, "Cf249"),
Self::Cf250 => write!(f, "Cf250"),
Self::Cf251 => write!(f, "Cf251"),
Self::Cf252 => write!(f, "Cf252"),
Self::Cf253 => write!(f, "Cf253"),
Self::Cf254 => write!(f, "Cf254"),
Self::Cf255 => write!(f, "Cf255"),
Self::Cf256 => write!(f, "Cf256"),
}
}
}
#[cfg(test)]
mod tests {
use strum::IntoEnumIterator;
use super::*;
use crate::isotopes::{
ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
};
#[test]
fn test_relative_atomic_mass() {
for isotope in CaliforniumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in CaliforniumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Cf, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in CaliforniumIsotope::iter() {
let mass_number = isotope.mass_number();
assert!(
mass_number > 0 && mass_number < 300,
"Mass number should be reasonable for {isotope:?}"
);
}
}
#[test]
fn test_isotopic_composition() {
for isotope in CaliforniumIsotope::iter() {
let comp = isotope.isotopic_composition();
if let Some(c) = comp {
assert!(
(0.0..=1.0).contains(&c),
"Composition should be between 0 and 1 for {isotope:?}"
);
}
}
}
#[test]
fn test_most_abundant() {
let most_abundant = CaliforniumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in CaliforniumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Cf(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in CaliforniumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Cf);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in CaliforniumIsotope::iter() {
let mass = isotope.mass_number();
let iso = CaliforniumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = CaliforniumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = CaliforniumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(CaliforniumIsotope::try_from(0_u16).is_err());
assert!(CaliforniumIsotope::try_from(1000_u16).is_err());
assert!(CaliforniumIsotope::try_from(0_u32).is_err());
assert!(CaliforniumIsotope::try_from(1000_u32).is_err());
assert!(CaliforniumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in CaliforniumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}