#[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 MeitneriumIsotope {
Mt266,
Mt268,
Mt270,
Mt274,
Mt275,
Mt276,
Mt277,
Mt278,
Mt282,
}
impl super::RelativeAtomicMass for MeitneriumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Mt266 => 266.13737f64,
Self::Mt268 => 268.13865f64,
Self::Mt270 => 270.14033f64,
Self::Mt274 => 274.14724f64,
Self::Mt275 => 275.14882f64,
Self::Mt276 => 276.15159f64,
Self::Mt277 => 277.15327f64,
Self::Mt278 => 278.15631f64,
Self::Mt282 => 282.166888f64,
}
}
}
impl super::ElementVariant for MeitneriumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Mt
}
}
impl super::MassNumber for MeitneriumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Mt266 => 266u16,
Self::Mt268 => 268u16,
Self::Mt270 => 270u16,
Self::Mt274 => 274u16,
Self::Mt275 => 275u16,
Self::Mt276 => 276u16,
Self::Mt277 => 277u16,
Self::Mt278 => 278u16,
Self::Mt282 => 282u16,
}
}
}
impl super::IsotopicComposition for MeitneriumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
None
}
}
impl super::MostAbundantIsotope for MeitneriumIsotope {
fn most_abundant_isotope() -> Self {
Self::Mt282
}
}
impl From<MeitneriumIsotope> for crate::Isotope {
fn from(isotope: MeitneriumIsotope) -> Self {
crate::Isotope::Mt(isotope)
}
}
impl From<MeitneriumIsotope> for crate::Element {
fn from(_isotope: MeitneriumIsotope) -> Self {
crate::Element::Mt
}
}
impl TryFrom<u64> for MeitneriumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
266u64 => Ok(Self::Mt266),
268u64 => Ok(Self::Mt268),
270u64 => Ok(Self::Mt270),
274u64 => Ok(Self::Mt274),
275u64 => Ok(Self::Mt275),
276u64 => Ok(Self::Mt276),
277u64 => Ok(Self::Mt277),
278u64 => Ok(Self::Mt278),
282u64 => Ok(Self::Mt282),
_ => Err(crate::errors::Error::Isotope(crate::Element::Mt, value)),
}
}
}
impl TryFrom<u8> for MeitneriumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for MeitneriumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for MeitneriumIsotope {
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 MeitneriumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Mt266 => write!(f, "Mt266"),
Self::Mt268 => write!(f, "Mt268"),
Self::Mt270 => write!(f, "Mt270"),
Self::Mt274 => write!(f, "Mt274"),
Self::Mt275 => write!(f, "Mt275"),
Self::Mt276 => write!(f, "Mt276"),
Self::Mt277 => write!(f, "Mt277"),
Self::Mt278 => write!(f, "Mt278"),
Self::Mt282 => write!(f, "Mt282"),
}
}
}
#[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 MeitneriumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in MeitneriumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Mt, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in MeitneriumIsotope::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 MeitneriumIsotope::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 = MeitneriumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in MeitneriumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Mt(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in MeitneriumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Mt);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in MeitneriumIsotope::iter() {
let mass = isotope.mass_number();
let iso = MeitneriumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = MeitneriumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = MeitneriumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(MeitneriumIsotope::try_from(0_u16).is_err());
assert!(MeitneriumIsotope::try_from(1000_u16).is_err());
assert!(MeitneriumIsotope::try_from(0_u32).is_err());
assert!(MeitneriumIsotope::try_from(1000_u32).is_err());
assert!(MeitneriumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in MeitneriumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}