Skip to content

Commit ac4f087

Browse files
committed
fix test_tools float point precision bug
1 parent eaf5930 commit ac4f087

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tests/test_tools.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
import unittest
14+
import numpy as np
1415
from dimspy.tools import *
1516
from dimspy.portals.hdf5_portal import *
1617

@@ -204,20 +205,23 @@ def test_hdf5_peak_matrix_to_txt(self):
204205
hdf5_peak_matrix_to_txt(to_test_data("MTBLS79_mzml_peak_matrix.hdf5"), to_test_result("pm_mzml_triplicates.txt"),
205206
attr_name="intensity", rsd_tags=(), delimiter="\t", samples_in_rows=True, comprehensive=False)
206207
with open(to_test_result("pm_mzml_triplicates.txt"), "rU") as test_result:
207-
self.assertEquals(test_result.readline().split("\t")[0:5],
208-
['m/z', '74.0166655257', '74.0198337519', '74.0200238089', '74.0202012645'])
208+
ln = test_result.readline().split("\t")[:5]
209+
self.assertEqual(ln[0], "m/z")
210+
self.assertTrue(np.allclose(map(float,ln[1:]), [74.0166655257, 74.0198337519, 74.0200238089, 74.0202012645], atol = 1e-10))
209211

210212
hdf5_peak_matrix_to_txt(to_test_data("MTBLS79_mzml_peak_matrix.hdf5"), to_test_result("pm_mzml_triplicates_comprehensive.txt"),
211213
attr_name="intensity", rsd_tags=("QC",), delimiter="\t", samples_in_rows=True, comprehensive=True)
212214
with open(to_test_result("pm_mzml_triplicates_comprehensive.txt"), "rU") as test_result:
213-
self.assertEquals(test_result.readline().split("\t")[0:6],
214-
["m/z", "missing values", "tags_classLabel", "tags_batch", "tags_untyped", "74.0166655257"])
215+
ln = test_result.readline().split("\t")[:6]
216+
self.assertEquals(ln[:-1], ["m/z", "missing values", "tags_classLabel", "tags_batch", "tags_untyped"])
217+
self.assertTrue(np.isclose(float(ln[-1]), 74.0166655257))
215218

216219
hdf5_peak_matrix_to_txt(to_test_data("MTBLS79_mzml_peak_matrix.hdf5"), to_test_result("pm_mzml_triplicates_snr.txt"),
217220
attr_name="snr", rsd_tags=("QC",), delimiter="\t", samples_in_rows=True, comprehensive=False)
218221
with open(to_test_result("pm_mzml_triplicates_snr.txt"), "rU") as test_result:
219-
self.assertEquals(test_result.readlines()[1].split("\t")[0:10],
220-
["batch04_B02_rep01_301.mzML", "0.0", "0.0", "0.0", "0.0", "0.0", "0.0", "3.60960180872", "0.0", "4.35180213987"])
222+
ln = test_result.readlines()[1].split("\t")[:10]
223+
self.assertEqual(ln[0], "batch04_B02_rep01_301.mzML")
224+
self.assertTrue(np.allclose(map(float,ln[1:]), [0., 0., 0., 0., 0., 0., 3.60960180872, 0., 4.35180213987], atol = 1e-10))
221225

222226
hdf5_peak_matrix_to_txt(to_test_data("MTBLS79_mzml_peak_matrix.hdf5"), to_test_result("pm_mzml_triplicates_comprehensive_T.txt"),
223227
attr_name="intensity", rsd_tags=("QC",), delimiter="\t", samples_in_rows=False, comprehensive=True)

0 commit comments

Comments
 (0)