Skip to content

Commit

Permalink
Merge pull request #248 from GeoStat-Framework/float-comparison
Browse files Browse the repository at this point in the history
Change float comparison in tests
  • Loading branch information
MuellerSeb authored Aug 9, 2022
2 parents 51204f4 + 0bcb322 commit dda2431
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ def test_transform_normal(self):
srf.transform(
"discrete", values=values, thresholds=thresholds, store="f1"
)
np.testing.assert_array_equal(np.unique(srf.f1), [-1, 0, 1])
np.testing.assert_allclose(np.unique(srf.f1), [-1, 0, 1])

values = [-1, 0, 1]
srf.transform(
"discrete", values=values, thresholds="arithmetic", store="f2"
)
np.testing.assert_array_equal(np.unique(srf.f2), [-1.0, 0.0, 1.0])
np.testing.assert_allclose(np.unique(srf.f2), [-1.0, 0.0, 1.0])

values = [-1, 0, 0.5, 1]
srf.transform(
"discrete", values=values, thresholds="equal", store="f3"
)
np.testing.assert_array_equal(np.unique(srf.f3), values)
np.testing.assert_allclose(np.unique(srf.f3), values)
# checks
with self.assertRaises(ValueError):
srf.transform("discrete", values=values, thresholds=[1])
Expand All @@ -84,7 +84,7 @@ def test_transform_normal(self):

# function
srf.transform("function", function=lambda x: 2 * x, store="f4")
np.testing.assert_array_equal(2 * srf.field, srf.f4)
np.testing.assert_allclose(2 * srf.field, srf.f4)
with self.assertRaises(ValueError):
srf.transform("function", function=None)

Expand Down Expand Up @@ -162,7 +162,7 @@ def test_transform_denormal(self):
store="f1",
process=True,
)
np.testing.assert_array_equal(np.unique(np.log(srf.f1)), [-1, 0, 1])
np.testing.assert_allclose(np.unique(np.log(srf.f1)), [-1, 0, 1])

values = [-1, 0, 1]
srf.transform(
Expand All @@ -172,9 +172,7 @@ def test_transform_denormal(self):
store="f2",
process=True,
)
np.testing.assert_array_equal(
np.unique(np.log(srf.f2)), [-1.0, 0.0, 1.0]
)
np.testing.assert_allclose(np.unique(np.log(srf.f2)), [-1.0, 0.0, 1.0])

values = [-1, 0, 0.5, 1]
srf.transform(
Expand All @@ -184,7 +182,7 @@ def test_transform_denormal(self):
store="f3",
process=True,
)
np.testing.assert_array_equal(np.unique(np.log(srf.f3)), values)
np.testing.assert_allclose(np.unique(np.log(srf.f3)), values)


if __name__ == "__main__":
Expand Down

0 comments on commit dda2431

Please sign in to comment.