#[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 NeonIsotope {
Ne15,
Ne16,
Ne17,
Ne18,
Ne19,
Ne20,
Ne21,
Ne22,
Ne23,
Ne24,
Ne25,
Ne26,
Ne27,
Ne28,
Ne29,
Ne30,
Ne31,
Ne32,
Ne33,
Ne34,
}
impl super::RelativeAtomicMass for NeonIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Ne15 => 15.043172977f64,
Self::Ne16 => 16.02575f64,
Self::Ne17 => 17.01771396f64,
Self::Ne18 => 18.0057087f64,
Self::Ne19 => 19.00188091f64,
Self::Ne20 => 19.9924401762f64,
Self::Ne21 => 20.993846685f64,
Self::Ne22 => 21.991385114f64,
Self::Ne23 => 22.99446691f64,
Self::Ne24 => 23.99361065f64,
Self::Ne25 => 24.997789f64,
Self::Ne26 => 26.000515f64,
Self::Ne27 => 27.007553f64,
Self::Ne28 => 28.01212f64,
Self::Ne29 => 29.01975f64,
Self::Ne30 => 30.02473f64,
Self::Ne31 => 31.0331f64,
Self::Ne32 => 32.03972f64,
Self::Ne33 => 33.04938f64,
Self::Ne34 => 34.05673f64,
}
}
}
impl super::ElementVariant for NeonIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Ne
}
}
impl super::MassNumber for NeonIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Ne15 => 15u16,
Self::Ne16 => 16u16,
Self::Ne17 => 17u16,
Self::Ne18 => 18u16,
Self::Ne19 => 19u16,
Self::Ne20 => 20u16,
Self::Ne21 => 21u16,
Self::Ne22 => 22u16,
Self::Ne23 => 23u16,
Self::Ne24 => 24u16,
Self::Ne25 => 25u16,
Self::Ne26 => 26u16,
Self::Ne27 => 27u16,
Self::Ne28 => 28u16,
Self::Ne29 => 29u16,
Self::Ne30 => 30u16,
Self::Ne31 => 31u16,
Self::Ne32 => 32u16,
Self::Ne33 => 33u16,
Self::Ne34 => 34u16,
}
}
}
impl super::IsotopicComposition for NeonIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
match self {
Self::Ne20 => Some(0.9048f64),
Self::Ne21 => Some(0.0027f64),
Self::Ne22 => Some(0.0925f64),
_ => None,
}
}
}
impl super::MostAbundantIsotope for NeonIsotope {
fn most_abundant_isotope() -> Self {
Self::Ne20
}
}
impl From<NeonIsotope> for crate::Isotope {
fn from(isotope: NeonIsotope) -> Self {
crate::Isotope::Ne(isotope)
}
}
impl From<NeonIsotope> for crate::Element {
fn from(_isotope: NeonIsotope) -> Self {
crate::Element::Ne
}
}
impl TryFrom<u64> for NeonIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
15u64 => Ok(Self::Ne15),
16u64 => Ok(Self::Ne16),
17u64 => Ok(Self::Ne17),
18u64 => Ok(Self::Ne18),
19u64 => Ok(Self::Ne19),
20u64 => Ok(Self::Ne20),
21u64 => Ok(Self::Ne21),
22u64 => Ok(Self::Ne22),
23u64 => Ok(Self::Ne23),
24u64 => Ok(Self::Ne24),
25u64 => Ok(Self::Ne25),
26u64 => Ok(Self::Ne26),
27u64 => Ok(Self::Ne27),
28u64 => Ok(Self::Ne28),
29u64 => Ok(Self::Ne29),
30u64 => Ok(Self::Ne30),
31u64 => Ok(Self::Ne31),
32u64 => Ok(Self::Ne32),
33u64 => Ok(Self::Ne33),
34u64 => Ok(Self::Ne34),
_ => Err(crate::errors::Error::Isotope(crate::Element::Ne, value)),
}
}
}
impl TryFrom<u8> for NeonIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for NeonIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for NeonIsotope {
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 NeonIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Ne15 => write!(f, "Ne15"),
Self::Ne16 => write!(f, "Ne16"),
Self::Ne17 => write!(f, "Ne17"),
Self::Ne18 => write!(f, "Ne18"),
Self::Ne19 => write!(f, "Ne19"),
Self::Ne20 => write!(f, "Ne20"),
Self::Ne21 => write!(f, "Ne21"),
Self::Ne22 => write!(f, "Ne22"),
Self::Ne23 => write!(f, "Ne23"),
Self::Ne24 => write!(f, "Ne24"),
Self::Ne25 => write!(f, "Ne25"),
Self::Ne26 => write!(f, "Ne26"),
Self::Ne27 => write!(f, "Ne27"),
Self::Ne28 => write!(f, "Ne28"),
Self::Ne29 => write!(f, "Ne29"),
Self::Ne30 => write!(f, "Ne30"),
Self::Ne31 => write!(f, "Ne31"),
Self::Ne32 => write!(f, "Ne32"),
Self::Ne33 => write!(f, "Ne33"),
Self::Ne34 => write!(f, "Ne34"),
}
}
}
#[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 NeonIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in NeonIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Ne, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in NeonIsotope::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 NeonIsotope::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 = NeonIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in NeonIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Ne(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in NeonIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Ne);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in NeonIsotope::iter() {
let mass = isotope.mass_number();
let iso = NeonIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = NeonIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = NeonIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(NeonIsotope::try_from(0_u16).is_err());
assert!(NeonIsotope::try_from(1000_u16).is_err());
assert!(NeonIsotope::try_from(0_u32).is_err());
assert!(NeonIsotope::try_from(1000_u32).is_err());
assert!(NeonIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in NeonIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}