Skip to content

Commit 6e099a3

Browse files
committed
additional virial test
1 parent 9a97de8 commit 6e099a3

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/virial.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,8 @@ impl VirialCoeff {
9595
/// See "Colloidal Domain" by Evans and Wennerström, 2nd Ed, p. 408
9696
pub fn association_const(&self) -> Option<f64> {
9797
const LITER_PER_CUBIC_ANGSTROM: f64 = 1e-27;
98-
let association_const =
99-
-2.0 * (self.b2 - self.hardsphere()) * LITER_PER_CUBIC_ANGSTROM * AVOGADRO_CONSTANT;
100-
if association_const.is_sign_positive() {
101-
Some(association_const)
102-
} else {
103-
None
104-
}
98+
Some(-2.0 * (self.b2 - self.hardsphere()) * LITER_PER_CUBIC_ANGSTROM * AVOGADRO_CONSTANT)
99+
.filter(|x| x.is_sign_positive())
105100
}
106101
/// Dissociation constant, 𝐾𝑑
107102
/// See "Colloidal Domain" by Evans and Wennerström, 2nd Ed, p. 408
@@ -143,7 +138,7 @@ mod tests {
143138
(49.0, -0.0356),
144139
];
145140
let virial = VirialCoeff::from_pmf(pmf.iter().cloned(), None).unwrap();
146-
assert_relative_eq!(virial.b2(), 87041.72463623626);
141+
assert_relative_eq!(virial.b2(), 87041.72463623626, epsilon = 1e-3);
147142
assert_relative_eq!(virial.hardsphere(), 106087.39512152252);
148143
assert_relative_eq!(virial.sigma(), 37.0);
149144
assert_relative_eq!(virial.reduced(), 0.820471881098885);
@@ -155,5 +150,8 @@ mod tests {
155150
assert_relative_eq!(virial.sigma(), 40.0);
156151
assert_relative_eq!(virial.reduced(), 0.6553003699405502);
157152
assert_relative_eq!(virial.dissociation_const().unwrap(), 0.017969653256450453);
153+
154+
let virial = VirialCoeff::from_raw_parts(16760.0, 20.0);
155+
assert!(virial.association_const().is_none());
158156
}
159157
}

0 commit comments

Comments
 (0)