elements_rs/isotopes/
flerovium.rs

1//! Isotopes of the element Flerovium
2#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, strum :: EnumIter)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4/// Isotopes of the element Flerovium
5pub enum FleroviumIsotope {
6    /// Isotope Fl285 of Flerovium
7    Fl285,
8    /// Isotope Fl286 of Flerovium
9    Fl286,
10    /// Isotope Fl287 of Flerovium
11    Fl287,
12    /// Isotope Fl288 of Flerovium
13    Fl288,
14    /// Isotope Fl289 of Flerovium
15    Fl289,
16}
17impl super::RelativeAtomicMass for FleroviumIsotope {
18    #[inline]
19    fn relative_atomic_mass(&self) -> f64 {
20        match self {
21            Self::Fl285 => 285.18364f64,
22            Self::Fl286 => 286.18423f64,
23            Self::Fl287 => 287.18678f64,
24            Self::Fl288 => 288.18757f64,
25            Self::Fl289 => 289.19042f64,
26        }
27    }
28}
29impl super::ElementVariant for FleroviumIsotope {
30    #[inline]
31    fn element(&self) -> crate::Element {
32        crate::Element::Fl
33    }
34}
35impl super::MassNumber for FleroviumIsotope {
36    #[inline]
37    fn mass_number(&self) -> u16 {
38        match self {
39            Self::Fl285 => 285u16,
40            Self::Fl286 => 286u16,
41            Self::Fl287 => 287u16,
42            Self::Fl288 => 288u16,
43            Self::Fl289 => 289u16,
44        }
45    }
46}
47impl super::IsotopicComposition for FleroviumIsotope {
48    #[inline]
49    fn isotopic_composition(&self) -> Option<f64> {
50        None
51    }
52}
53impl super::MostAbundantIsotope for FleroviumIsotope {
54    fn most_abundant_isotope() -> Self {
55        Self::Fl289
56    }
57}
58impl From<FleroviumIsotope> for crate::Isotope {
59    fn from(isotope: FleroviumIsotope) -> Self {
60        crate::Isotope::Fl(isotope)
61    }
62}
63impl From<FleroviumIsotope> for crate::Element {
64    fn from(_isotope: FleroviumIsotope) -> Self {
65        crate::Element::Fl
66    }
67}
68impl TryFrom<u64> for FleroviumIsotope {
69    type Error = crate::errors::Error;
70    fn try_from(value: u64) -> Result<Self, Self::Error> {
71        match value {
72            285u64 => Ok(Self::Fl285),
73            286u64 => Ok(Self::Fl286),
74            287u64 => Ok(Self::Fl287),
75            288u64 => Ok(Self::Fl288),
76            289u64 => Ok(Self::Fl289),
77            _ => Err(crate::errors::Error::Isotope(crate::Element::Fl, value)),
78        }
79    }
80}
81impl TryFrom<u8> for FleroviumIsotope {
82    type Error = crate::errors::Error;
83    fn try_from(value: u8) -> Result<Self, Self::Error> {
84        Self::try_from(u64::from(value))
85    }
86}
87impl TryFrom<u16> for FleroviumIsotope {
88    type Error = crate::errors::Error;
89    fn try_from(value: u16) -> Result<Self, Self::Error> {
90        Self::try_from(u64::from(value))
91    }
92}
93impl TryFrom<u32> for FleroviumIsotope {
94    type Error = crate::errors::Error;
95    fn try_from(value: u32) -> Result<Self, Self::Error> {
96        Self::try_from(u64::from(value))
97    }
98}
99impl core::fmt::Display for FleroviumIsotope {
100    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
101        match self {
102            Self::Fl285 => write!(f, "Fl285"),
103            Self::Fl286 => write!(f, "Fl286"),
104            Self::Fl287 => write!(f, "Fl287"),
105            Self::Fl288 => write!(f, "Fl288"),
106            Self::Fl289 => write!(f, "Fl289"),
107        }
108    }
109}
110#[cfg(test)]
111mod tests {
112    use strum::IntoEnumIterator;
113
114    use super::*;
115    use crate::isotopes::{
116        ElementVariant, IsotopicComposition, MassNumber, MostAbundantIsotope, RelativeAtomicMass,
117    };
118    #[test]
119    fn test_relative_atomic_mass() {
120        for isotope in FleroviumIsotope::iter() {
121            let mass = isotope.relative_atomic_mass();
122            assert!(mass > 0.0, "Mass should be positive for {isotope:?}");
123        }
124    }
125    #[test]
126    fn test_element() {
127        for isotope in FleroviumIsotope::iter() {
128            let element = isotope.element();
129            assert_eq!(element, crate::Element::Fl, "Element should be correct for {isotope:?}");
130        }
131    }
132    #[test]
133    fn test_mass_number() {
134        for isotope in FleroviumIsotope::iter() {
135            let mass_number = isotope.mass_number();
136            assert!(
137                mass_number > 0 && mass_number < 300,
138                "Mass number should be reasonable for {isotope:?}"
139            );
140        }
141    }
142    #[test]
143    fn test_isotopic_composition() {
144        for isotope in FleroviumIsotope::iter() {
145            let comp = isotope.isotopic_composition();
146            if let Some(c) = comp {
147                assert!(
148                    (0.0..=1.0).contains(&c),
149                    "Composition should be between 0 and 1 for {isotope:?}"
150                );
151            }
152        }
153    }
154    #[test]
155    fn test_most_abundant() {
156        let most_abundant = FleroviumIsotope::most_abundant_isotope();
157        let _ = most_abundant.relative_atomic_mass();
158    }
159    #[test]
160    fn test_from_isotope() {
161        for isotope in FleroviumIsotope::iter() {
162            let iso: crate::Isotope = isotope.into();
163            match iso {
164                crate::Isotope::Fl(i) => assert_eq!(i, isotope),
165                _ => panic!("Wrong isotope type"),
166            }
167        }
168    }
169    #[test]
170    fn test_from_element() {
171        for isotope in FleroviumIsotope::iter() {
172            let elem: crate::Element = isotope.into();
173            assert_eq!(elem, crate::Element::Fl);
174        }
175    }
176    #[test]
177    fn test_try_from_mass_number() {
178        for isotope in FleroviumIsotope::iter() {
179            let mass = isotope.mass_number();
180            let iso = FleroviumIsotope::try_from(mass).unwrap();
181            assert_eq!(iso, isotope);
182            let iso_u32 = FleroviumIsotope::try_from(u32::from(mass)).unwrap();
183            assert_eq!(iso_u32, isotope);
184            if let Ok(mass_u8) = u8::try_from(mass) {
185                let iso_u8 = FleroviumIsotope::try_from(mass_u8).unwrap();
186                assert_eq!(iso_u8, isotope);
187            }
188        }
189        assert!(FleroviumIsotope::try_from(0_u16).is_err());
190        assert!(FleroviumIsotope::try_from(1000_u16).is_err());
191        assert!(FleroviumIsotope::try_from(0_u32).is_err());
192        assert!(FleroviumIsotope::try_from(1000_u32).is_err());
193        assert!(FleroviumIsotope::try_from(0_u8).is_err());
194    }
195    #[test]
196    fn test_display() {
197        for isotope in FleroviumIsotope::iter() {
198            let s = alloc::format!("{isotope}");
199            assert!(!s.is_empty(), "Display should not be empty for {isotope:?}");
200        }
201    }
202}