Skip to content

Instantly share code, notes, and snippets.

@tomphp
Created September 27, 2017 20:47
Show Gist options
  • Save tomphp/909e8b6b637a1f027669bd8ec1396571 to your computer and use it in GitHub Desktop.
Save tomphp/909e8b6b637a1f027669bd8ec1396571 to your computer and use it in GitHub Desktop.
from hypothesis import given
from hypothesis.strategies import text
def reverse(string):
return string
@given(text())
def test_reverse_reverse_is_the_original(s):
assert s == reverse(reverse(s))
@given(text())
def test_reversed_has_same_length(s):
assert len(s) == len(reverse(s))
@given(text())
def test_first_char_ends_up_in_last_place(s):
if not s:
pass
else:
assert s[0] == reverse(s)[-1]
from hypothesis import given
from hypothesis.strategies import text, lists
class Stack():
last_elem = None
def Push(self, elem):
self.last_elem = elem
def Pop(self):
return self.last_elem
@given(lists(elements=text(), min_size=1))
def test_pop_after_a_push_returns_the_pushed_value(items):
stack = Stack()
for elem in items:
stack.Push(elem)
assert stack.Pop() == items[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment