Skip to content

Commit

Permalink
Match SWINTEGERS and saturation print format
Browse files Browse the repository at this point in the history
The documentation for SWINTEGERS did not match the accuracy of printed
floating numbers, and this lead to a rare possibility for test failures,
exemplified by test_slgof.py::test_slgof_hypo where it was possible to
end up with two saturation points being printed identically.

The usage of SWINTEGERS in test code has been tuned accordingly.

Co-authored by: Alif Be <[email protected]>
  • Loading branch information
berland committed Oct 2, 2024
1 parent 4162b12 commit 469bb84
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pyscal/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* ``MAX_EXPONENT_PC``: Maximal number for exponents in cap pressure parameterizations.
"""

SWINTEGERS: int = 10000
SWINTEGERS: int = 100000

EPSILON: float = 1e-08

Expand Down
2 changes: 1 addition & 1 deletion src/pyscal/utils/relperm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def truncate_zeroness(
value: float, zeronesslimit: float = 1 / SWINTEGERS, name: str = "", log=True
value: float, zeronesslimit: float = 10 / SWINTEGERS, name: str = "", log=True
) -> float:
"""Check a value for closeness to zero, and return as zero if below
a given limit, if not return the value"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gasoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_gasoil_init():

def test_conserve_sgcr(mocker):
"""sgcr in the table can be hard to conserve"""
low_sgcrvalue = 0.00001 # 1/10 of 1/SWINTEGERS
low_sgcrvalue = 1 / SWINTEGERS / 10
# Verify the default behaviour of truncation:
assert truncate_zeroness(low_sgcrvalue) == 0
mocker.patch(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gaswater.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
def check_endpoints(gaswater, krwend, krwmax, krgend):
"""Check that the code produces correct endpoints for
parametrizations, on discrete cases"""
swtol = 1 / SWINTEGERS
swtol = 10 / SWINTEGERS

# Check endpoints for gas curve:
# krg at swl should be krgend:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_slgof.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_numerical_problems(swl, sorg, sgcr):
st.floats(min_value=0.0, max_value=0.3),
st.floats(min_value=0.0, max_value=0.3),
st.floats(min_value=0.0, max_value=0.3),
st.floats(min_value=1.0 / float(1000 * SWINTEGERS), max_value=0.5),
st.floats(min_value=1.0 / float(100 * SWINTEGERS), max_value=0.5),
)
def test_slgof_hypo(swl, sorg, sgcr, h):
"""Shotgun-testing of slgof"""
Expand All @@ -148,7 +148,7 @@ def test_slgof_hypo(swl, sorg, sgcr, h):
@given(
st.floats(min_value=0.0, max_value=0.3),
st.floats(min_value=0.0, max_value=0.3),
st.floats(min_value=1.0 / float(1000 * SWINTEGERS), max_value=0.5),
st.floats(min_value=1.0 / float(100 * SWINTEGERS), max_value=0.5),
)
def test_slgof_sl_mismatch(swl, sorg, h):
"""Test numerical robustness on slgof table creation."""
Expand Down

0 comments on commit 469bb84

Please sign in to comment.