[python-periodictable] 02/02: Allow numerical fuzz in tests
Stuart Prescott
stuart at debian.org
Tue Dec 26 14:02:13 UTC 2017
This is an automated email from the git hooks/post-receive script.
stuart pushed a commit to branch master
in repository python-periodictable.
commit 3e35c0dde1d4c477e7c227359e3933b2e5dfc4c5
Author: Stuart Prescott <stuart at debian.org>
Date: Wed Dec 27 01:01:54 2017 +1100
Allow numerical fuzz in tests
---
debian/patches/series | 1 +
debian/patches/test-precision.patch | 97 +++++++++++++++++++++++++++++++++++++
2 files changed, 98 insertions(+)
diff --git a/debian/patches/series b/debian/patches/series
index 098902c..63ccbe3 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,3 @@
+test-precision.patch
pytest.patch
sphinx-local-mathjax.patch
diff --git a/debian/patches/test-precision.patch b/debian/patches/test-precision.patch
new file mode 100644
index 0000000..9c81b27
--- /dev/null
+++ b/debian/patches/test-precision.patch
@@ -0,0 +1,97 @@
+Description: Fix tests to cope with round-off error
+ (superseded by alternate solution upstream)
+Author: Stuart Prescott <stuart at debian.org>
+Forwarded: not-needed
+Applied-Upstream: https://github.com/pkienzle/periodictable/commit/538018a26513267ec1a7aa71b48042071aa53fdd
+--- a/test/test_xsf.py
++++ b/test/test_xsf.py
+@@ -1,5 +1,6 @@
+ import numpy
+ from numpy import pi, isnan
++from numpy.testing import assert_almost_equal
+ from periodictable import formula
+ from periodictable import Cu,Mo,Ni,Fe,Si,H,D,O
+ from periodictable.xsf import xray_energy, xray_sld_from_atoms, xray_sld
+@@ -13,8 +14,8 @@
+
+ # Check scalar scattering factor lookup
+ f1,f2 = Ni.xray.scattering_factors(energy=xray_energy(Cu.K_alpha))
+- assert abs(f1-25.0229)<0.0001
+- assert abs(f2-0.5249)<0.0001
++ assert_almost_equal(f1, 25.0229, 4)
++ assert_almost_equal(f2, 0.5249, 4)
+
+ # Check array scattering factor lookup
+ f1,f2 = Ni.xray.scattering_factors(wavelength=Cu.K_alpha)
+@@ -24,10 +25,10 @@
+
+ # Check that we can lookup sld by wavelength and energy
+ Fe_rho,Fe_mu = Fe.xray.sld(wavelength=Cu.K_alpha)
+- assert abs(Fe_rho-59.45) < 0.01
++ assert_almost_equal(Fe_rho, 59.45, 2)
+ Si_rho,Si_mu = Si.xray.sld(energy=8.050)
+- assert abs(Si_rho-20.0701) < 0.0001
+- assert abs(Si_mu-0.4572) < 0.0001
++ assert_almost_equal(Si_rho, 20.0701, 4)
++ assert_almost_equal(Si_mu, 0.4572, 4)
+
+ # Check that wavelength is the default
+ Fe_rho_default,Fe_mu_default = Fe.xray.sld(wavelength=Cu.K_alpha)
+@@ -63,16 +64,16 @@
+ # Cross check against mo
+ rho,mu = xray_sld({Si:1},density=Si.density,wavelength=1.54)
+ rhoSi,muSi = Si.xray.sld(wavelength=1.54)
+- assert abs(rho - rhoSi) < 1e-14
+- assert abs(mu - muSi) < 1e-14
++ assert_almost_equal(rho, rhoSi, 14)
++ assert_almost_equal(mu, muSi, 14)
+
+ # Check that xray_sld works as expected
+ atoms = formula('SiO2').atoms
+ rho,mu = xray_sld(atoms,density=2.2,energy=xray_energy(Cu.K_alpha))
+- assert abs(rho-18.87)<0.1
++ assert_almost_equal(rho, 18.87, 2)
+ atoms = formula('B4C').atoms
+ rho,mu = xray_sld(atoms,density=2.52,energy=xray_energy(Cu.K_alpha))
+- assert abs(rho-20.17)<0.1
++ assert_almost_equal(rho, 20.17, 2)
+
+ F = formula('', density=0)
+ rho,mu = xray_sld('', density=0, wavelength=Cu.K_alpha)
+@@ -82,13 +83,14 @@
+ D2O_density = (2*D.mass + O.mass)/(2*H.mass + O.mass)
+ rho,mu = xray_sld('D2O',natural_density=1,wavelength=1.54)
+ rho2,mu2 = xray_sld('D2O',density=D2O_density,wavelength=1.54)
+- assert abs(rho-rho2)<1e-14 and abs(mu-mu2)<1e-14
++ assert_almost_equal(rho, rho2, 14)
++ assert_almost_equal(mu, mu2, 14)
+
+
+ # Check f0 calculation for scalar, vector, array and empty
+ Q1,Q2 = 4*pi/Cu.K_alpha, 4*pi/Mo.K_alpha
+ f0 = Ni.xray.f0(Q=Q1)
+- assert abs(f0-10.11303) < 0.00001
++ assert_almost_equal(f0, 10.11303, 5)
+ assert isnan(Ni.xray.f0(Q=7*4*pi))
+
+ f0 = Ni.xray.f0(Q=Q1)
+@@ -101,14 +103,14 @@
+ assert len(f0) == 0
+
+ f0 = Ni.xray.f0(Q=[[1,2],[3,4]])
+- assert f0[0,0] == Ni.xray.f0(1)
+- assert f0[0,1] == Ni.xray.f0(2)
+- assert f0[1,0] == Ni.xray.f0(3)
+- assert f0[1,1] == Ni.xray.f0(4)
++ assert_almost_equal(f0[0,0], Ni.xray.f0(1))
++ assert_almost_equal(f0[0,1], Ni.xray.f0(2))
++ assert_almost_equal(f0[1,0], Ni.xray.f0(3))
++ assert_almost_equal(f0[1,1], Ni.xray.f0(4))
+
+ # Check f0 calculation for ion
+ Ni_2p_f0 = Ni.ion[2].xray.f0(Q=Q1)
+- assert abs(Ni_2p_f0-10.09535) < 0.00001
++ assert_almost_equal(Ni_2p_f0, 10.09535, 5)
+ Ni58_2p_f0 = Ni[58].ion[2].xray.f0(Q=Q1)
+ assert Ni_2p_f0 == Ni58_2p_f0
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-periodictable.git
More information about the debian-science-commits
mailing list