-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work toward adding property-based tests
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters