Skip to content

Commit

Permalink
work toward adding property-based tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jab committed Apr 24, 2015
1 parent f6fc702 commit ff0889f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.hypothesis


######################################################################
# https://github.com/github/gitignore/blob/master/Global/OSX.gitignore
######################################################################
Expand Down
34 changes: 34 additions & 0 deletions hypothesis_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Property-based tests.
"""

from hypothesis import assume, given
from hypothesis.specifiers import dictionary

@given(dictionary(int, int))
def test_basic_properties_bidict(fwd):
from bidict import bidict

# ensure all values in fwd are unique
assume(len(fwd.values()) == len(set(fwd.values())))

inv = {v: k for (k, v) in fwd.items()}
b = bidict(fwd)

# len
assert len(fwd) == len(inv) == len(b)

# getitem
for k, v in b.items():
k_ = b[:v]
v_ = b[k]
assert k == k_
assert v == v_

# .inv, is, ==, !=, and ~ operators. == and != are polymorphic.
assert b is b.inv.inv is ~~b
assert b.inv is b.inv.inv.inv is ~b
assert b == fwd
assert ~b == inv
assert not b != fwd
assert not ~b != inv
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'Topic :: Software Development :: Libraries :: Python Modules',
],
test_suite='test',
tests_require=['hypothesis'],
extras_require=dict(
dev=['pre-commit'],
),
Expand Down

0 comments on commit ff0889f

Please sign in to comment.