Hypothesis
from hypothesis import given
from hypothesis.strategies import text
def encode(input_string):
# Hypothesis will capture the case when s = ""
# if not input_string:
# return []
count = 1
prev = ""
lst = []
for character in input_string:
if character != prev:
if prev:
entry = (prev, count)
lst.append(entry)
count = 1
prev = character
else:
count += 1
entry = (character, count)
lst.append(entry)
return lst
def decode(lst):
q = ""
for character, count in lst:
q += character * count
return q
@given(text())
def test_decode_inverts_encode(s):
assert decode(encode(s)) == s
test_decode_inverts_encode()
Create a pandas dataframe
from hypothesis.extra.pandas import column, data_frames
df = data_frames([column("A", dtype=int), column("B", dtype=float)]).example()
Create a numpy array
from hypothesis.extra.numpy import arrays
arr = arrays(dtype=int, shape=(2, 2)).example()