#[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 SeaborgiumIsotope {
Sg258,
Sg259,
Sg260,
Sg261,
Sg262,
Sg263,
Sg264,
Sg265,
Sg266,
Sg267,
Sg268,
Sg269,
Sg271,
}
impl super::RelativeAtomicMass for SeaborgiumIsotope {
#[inline]
fn relative_atomic_mass(&self) -> f64 {
match self {
Self::Sg258 => 258.11298f64,
Self::Sg259 => 259.1144f64,
Self::Sg260 => 260.114384f64,
Self::Sg261 => 261.115949f64,
Self::Sg262 => 262.116337f64,
Self::Sg263 => 263.11829f64,
Self::Sg264 => 264.11893f64,
Self::Sg265 => 265.12109f64,
Self::Sg266 => 266.12198f64,
Self::Sg267 => 267.12436f64,
Self::Sg268 => 268.12539f64,
Self::Sg269 => 269.12863f64,
Self::Sg271 => 271.13393f64,
}
}
}
impl super::ElementVariant for SeaborgiumIsotope {
#[inline]
fn element(&self) -> crate::Element {
crate::Element::Sg
}
}
impl super::MassNumber for SeaborgiumIsotope {
#[inline]
fn mass_number(&self) -> u16 {
match self {
Self::Sg258 => 258u16,
Self::Sg259 => 259u16,
Self::Sg260 => 260u16,
Self::Sg261 => 261u16,
Self::Sg262 => 262u16,
Self::Sg263 => 263u16,
Self::Sg264 => 264u16,
Self::Sg265 => 265u16,
Self::Sg266 => 266u16,
Self::Sg267 => 267u16,
Self::Sg268 => 268u16,
Self::Sg269 => 269u16,
Self::Sg271 => 271u16,
}
}
}
impl super::IsotopicComposition for SeaborgiumIsotope {
#[inline]
fn isotopic_composition(&self) -> Option<f64> {
None
}
}
impl super::MostAbundantIsotope for SeaborgiumIsotope {
fn most_abundant_isotope() -> Self {
Self::Sg271
}
}
impl From<SeaborgiumIsotope> for crate::Isotope {
fn from(isotope: SeaborgiumIsotope) -> Self {
crate::Isotope::Sg(isotope)
}
}
impl From<SeaborgiumIsotope> for crate::Element {
fn from(_isotope: SeaborgiumIsotope) -> Self {
crate::Element::Sg
}
}
impl TryFrom<u64> for SeaborgiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u64) -> Result<Self, Self::Error> {
match value {
258u64 => Ok(Self::Sg258),
259u64 => Ok(Self::Sg259),
260u64 => Ok(Self::Sg260),
261u64 => Ok(Self::Sg261),
262u64 => Ok(Self::Sg262),
263u64 => Ok(Self::Sg263),
264u64 => Ok(Self::Sg264),
265u64 => Ok(Self::Sg265),
266u64 => Ok(Self::Sg266),
267u64 => Ok(Self::Sg267),
268u64 => Ok(Self::Sg268),
269u64 => Ok(Self::Sg269),
271u64 => Ok(Self::Sg271),
_ => Err(crate::errors::Error::Isotope(crate::Element::Sg, value)),
}
}
}
impl TryFrom<u8> for SeaborgiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u16> for SeaborgiumIsotope {
type Error = crate::errors::Error;
fn try_from(value: u16) -> Result<Self, Self::Error> {
Self::try_from(u64::from(value))
}
}
impl TryFrom<u32> for SeaborgiumIsotope {
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 SeaborgiumIsotope {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Sg258 => write!(f, "Sg258"),
Self::Sg259 => write!(f, "Sg259"),
Self::Sg260 => write!(f, "Sg260"),
Self::Sg261 => write!(f, "Sg261"),
Self::Sg262 => write!(f, "Sg262"),
Self::Sg263 => write!(f, "Sg263"),
Self::Sg264 => write!(f, "Sg264"),
Self::Sg265 => write!(f, "Sg265"),
Self::Sg266 => write!(f, "Sg266"),
Self::Sg267 => write!(f, "Sg267"),
Self::Sg268 => write!(f, "Sg268"),
Self::Sg269 => write!(f, "Sg269"),
Self::Sg271 => write!(f, "Sg271"),
}
}
}
#[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 SeaborgiumIsotope::iter() {
let mass = isotope.relative_atomic_mass();
assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
}
}
#[test]
fn test_element() {
for isotope in SeaborgiumIsotope::iter() {
let element = isotope.element();
assert_eq!(element, crate::Element::Sg, "Element should be correct for {isotope:?}");
}
}
#[test]
fn test_mass_number() {
for isotope in SeaborgiumIsotope::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 SeaborgiumIsotope::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 = SeaborgiumIsotope::most_abundant_isotope();
let _ = most_abundant.relative_atomic_mass();
}
#[test]
fn test_from_isotope() {
for isotope in SeaborgiumIsotope::iter() {
let iso: crate::Isotope = isotope.into();
match iso {
crate::Isotope::Sg(i) => assert_eq!(i, isotope),
_ => panic!("Wrong isotope type"),
}
}
}
#[test]
fn test_from_element() {
for isotope in SeaborgiumIsotope::iter() {
let elem: crate::Element = isotope.into();
assert_eq!(elem, crate::Element::Sg);
}
}
#[test]
fn test_try_from_mass_number() {
for isotope in SeaborgiumIsotope::iter() {
let mass = isotope.mass_number();
let iso = SeaborgiumIsotope::try_from(mass).unwrap();
assert_eq!(iso, isotope);
let iso_u32 = SeaborgiumIsotope::try_from(u32::from(mass)).unwrap();
assert_eq!(iso_u32, isotope);
if let Ok(mass_u8) = u8::try_from(mass) {
let iso_u8 = SeaborgiumIsotope::try_from(mass_u8).unwrap();
assert_eq!(iso_u8, isotope);
}
}
assert!(SeaborgiumIsotope::try_from(0_u16).is_err());
assert!(SeaborgiumIsotope::try_from(1000_u16).is_err());
assert!(SeaborgiumIsotope::try_from(0_u32).is_err());
assert!(SeaborgiumIsotope::try_from(1000_u32).is_err());
assert!(SeaborgiumIsotope::try_from(0_u8).is_err());
}
#[test]
fn test_display() {
for isotope in SeaborgiumIsotope::iter() {
let s = alloc::format!("{isotope}");
assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
}
}
}