#[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))]
pub enum BerkeliumIsotope {
Bk233,
Bk234,
Bk235,
Bk236,
Bk238,
Bk239,
Bk240,
Bk241,
Bk242,
Bk243,
Bk244,
Bk245,
Bk246,
Bk247,
Bk248,
Bk249,
Bk250,
Bk251,
Bk252,
Bk253,
}
impl super::RelativeAtomicMass for BerkeliumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Bk233 => 233.056652f64,
Self::Bk234 => 234.05727f64,
Self::Bk235 => 235.05658f64,
Self::Bk236 => 236.05748f64,
Self::Bk238 => 238.0582f64,
Self::Bk239 => 239.05824f64,
Self::Bk240 => 240.05976f64,
Self::Bk241 => 241.06016f64,
Self::Bk242 => 242.06198f64,
Self::Bk243 => 243.0630078f64,
Self::Bk244 => 244.065181f64,
Self::Bk245 => 245.0663618f64,
Self::Bk246 => 246.068673f64,
Self::Bk247 => 247.0703073f64,
Self::Bk248 => 248.073088f64,
Self::Bk249 => 249.0749877f64,
Self::Bk250 => 250.0783167f64,
Self::Bk251 => 251.080762f64,
Self::Bk252 => 252.08431f64,
Self::Bk253 => 253.08688f64,
}
}
}
impl super::ElementVariant for BerkeliumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Bk
}
}
impl super::MassNumber for BerkeliumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Bk233 => 233u16,
Self::Bk234 => 234u16,
Self::Bk235 => 235u16,
Self::Bk236 => 236u16,
Self::Bk238 => 238u16,
Self::Bk239 => 239u16,
Self::Bk240 => 240u16,
Self::Bk241 => 241u16,
Self::Bk242 => 242u16,
Self::Bk243 => 243u16,
Self::Bk244 => 244u16,
Self::Bk245 => 245u16,
Self::Bk246 => 246u16,
Self::Bk247 => 247u16,
Self::Bk248 => 248u16,
Self::Bk249 => 249u16,
Self::Bk250 => 250u16,
Self::Bk251 => 251u16,
Self::Bk252 => 252u16,
Self::Bk253 => 253u16,
}
}
}
impl super::IsotopicComposition for BerkeliumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
None
}
}
impl super::MostAbundantIsotope for BerkeliumIsotope {
fn most_abundant_isotope() -> Self {
Self::Bk253
}
}
impl From<BerkeliumIsotope> for crate::Isotope {
fn from(isotope: BerkeliumIsotope) -> Self {
crate::Isotope::Bk(isotope)
}
}
impl From<BerkeliumIsotope> for crate::Element {
fn from(_isotope: BerkeliumIsotope) -> Self {
crate::Element::Bk
}
}
impl TryFrom<u64> for BerkeliumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
233u64 => Ok(Self::Bk233),
234u64 => Ok(Self::Bk234),
235u64 => Ok(Self::Bk235),
236u64 => Ok(Self::Bk236),
238u64 => Ok(Self::Bk238),
239u64 => Ok(Self::Bk239),
240u64 => Ok(Self::Bk240),
241u64 => Ok(Self::Bk241),
242u64 => Ok(Self::Bk242),
243u64 => Ok(Self::Bk243),
244u64 => Ok(Self::Bk244),
245u64 => Ok(Self::Bk245),
246u64 => Ok(Self::Bk246),
247u64 => Ok(Self::Bk247),
248u64 => Ok(Self::Bk248),
249u64 => Ok(Self::Bk249),
250u64 => Ok(Self::Bk250),
251u64 => Ok(Self::Bk251),
252u64 => Ok(Self::Bk252),
253u64 => Ok(Self::Bk253),
_ => Err(crate::errors::Error::Isotope(crate::Element::Bk, value)),
}
}
}
impl TryFrom<u8> for BerkeliumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for BerkeliumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for BerkeliumIsotope {
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 BerkeliumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Bk233 => write!(f, "Bk233"),
Self::Bk234 => write!(f, "Bk234"),
Self::Bk235 => write!(f, "Bk235"),
Self::Bk236 => write!(f, "Bk236"),
Self::Bk238 => write!(f, "Bk238"),
Self::Bk239 => write!(f, "Bk239"),
Self::Bk240 => write!(f, "Bk240"),
Self::Bk241 => write!(f, "Bk241"),
Self::Bk242 => write!(f, "Bk242"),
Self::Bk243 => write!(f, "Bk243"),
Self::Bk244 => write!(f, "Bk244"),
Self::Bk245 => write!(f, "Bk245"),
Self::Bk246 => write!(f, "Bk246"),
Self::Bk247 => write!(f, "Bk247"),
Self::Bk248 => write!(f, "Bk248"),
Self::Bk249 => write!(f, "Bk249"),
Self::Bk250 => write!(f, "Bk250"),
Self::Bk251 => write!(f, "Bk251"),
Self::Bk252 => write!(f, "Bk252"),
Self::Bk253 => write!(f, "Bk253"),
}
}
}
#[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 BerkeliumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in BerkeliumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Bk, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in BerkeliumIsotope::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 BerkeliumIsotope::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 = BerkeliumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in BerkeliumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Bk(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in BerkeliumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Bk);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in BerkeliumIsotope::iter() {
let mass = isotope.mass_number();
let iso = BerkeliumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = BerkeliumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = BerkeliumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(BerkeliumIsotope::try_from(0_u16).is_err());
assert!(BerkeliumIsotope::try_from(1000_u16).is_err());
assert!(BerkeliumIsotope::try_from(0_u32).is_err());
assert!(BerkeliumIsotope::try_from(1000_u32).is_err());
assert!(BerkeliumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in BerkeliumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}