def test_bad_method(self): """Testing failure when invalid method is passed.""" with pytest.raises(ValueError): impact_parameter(self.T, self.n_e, self.particles, z_mean=np.nan * u.dimensionless_unscaled, V=np.nan * u.m / u.s, method="meow")
def test_known1(self): """ Test for known value. """ methodVal = impact_parameter(self.T, self.n_e, self.particles, z_mean=np.nan * u.dimensionless_unscaled, V=np.nan * u.m / u.s, method="classical") bmin, bmax = methodVal methodVal = bmin.si.value, bmax.si.value testTrue = np.allclose(self.True1, methodVal, rtol=1e-1, atol=0.0) errStr = (f"Impact parameters should be {self.True1} and " f"not {methodVal}.") assert testTrue, errStr
def test_fail1(self): """ Tests if test_known1() would fail if we slightly adjusted the value comparison by some quantity close to numerical error. """ fail1 = self.True1 * (1 + 1e-15) methodVal = impact_parameter(self.T, self.n_e, self.particles, z_mean=np.nan * u.dimensionless_unscaled, V=np.nan * u.m / u.s, method="classical") bmin, bmax = methodVal methodVal = bmin.si.value, bmax.si.value testTrue = not np.allclose(methodVal, fail1, rtol=1e-16, atol=0.0) errStr = (f"Impact parameter value test gives {methodVal} and " f"should not be equal to {fail1}.") assert testTrue, errStr
def test_symmetry(self): result = impact_parameter(self.T, self.n_e, self.particles) resultRev = impact_parameter(self.T, self.n_e, self.particles[::-1]) assert result == resultRev