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