Skip to content

Commit

Permalink
ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
abhidg committed Aug 31, 2024
1 parent 88007e9 commit 2db4ff9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions property_based.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from hypothesis import given
from hypothesis.strategies import floats, integers
def divide(x, y): return x / y


def divide(x, y):
return x / y


@given(integers(), integers())
def test_divide(x, y): assert divide(x, y) < x
def test_divide(x, y):
assert divide(x, y) < x
4 changes: 3 additions & 1 deletion sunblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def fahrenheit_to_celsius(temp: pd.Series | float) -> pd.Series | float:
if math.isinf(temp):
raise ValueError("Temperature cannot be infinity")
if temp < -459.67:
raise ValueError("Temperature below minimum fahrenheit temperature at absolute zero")
raise ValueError(
"Temperature below minimum fahrenheit temperature at absolute zero"
)
return 5 * (temp - 32) / 9


Expand Down
4 changes: 3 additions & 1 deletion tests/test_hypothesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
# are given, we never return a value less than absolute zero (0 K) which
# is equivalent to -273.15 degrees celsius.


@given(floats())
def test_fahrenheit_to_celsius(temp):
try:
assert fahrenheit_to_celsius(temp) > -273.15 # absolute zero
except ValueError:
reject()


# hypothesis can also be used to intentionally find counter-examples
# here we are trying to find an example where the numerical values of a
# temperature in celsius and fahrenheit are the same. This should fail
Expand All @@ -36,4 +38,4 @@ def test_fahrenheit_differs_from_celsius(temp):
try:
assert fahrenheit_to_celsius(temp) != temp
except ValueError:
reject()
reject()

0 comments on commit 2db4ff9

Please sign in to comment.