Created
June 6, 2017 23:51
-
-
Save markrwilliams/1cbe9114ea6c9120ceb2b1bb91434cc3 to your computer and use it in GitHub Desktop.
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
import unittest | |
from hypothesis import given, strategies as st | |
class ComparisonTests(unittest.TestCase): | |
def assertNonesCauseTypeError(self, first, second): | |
try: | |
first > second | |
except TypeError: | |
comparison_raised = True | |
else: | |
comparison_raised = False | |
try: | |
for i in range(min(len(first), len(second))): | |
if first[i] > second[i] or first[i] < second[i]: | |
break | |
except TypeError: | |
iteration_raised = True | |
else: | |
iteration_raised = False | |
self.assertEqual(comparison_raised, iteration_raised, | |
"comparison_raised={!r} " | |
"iteration_raised={!r} " | |
"{!r} {!r}".format(comparison_raised, | |
iteration_raised, | |
first, second)) | |
@given( | |
first=st.lists(st.just(None) | st.integers()).map(tuple), | |
second=st.lists(st.just(None) | st.integers()).map(tuple), | |
) | |
def test_tuple_comparison(self, first, second): | |
self.assertNonesCauseTypeError(first, second) | |
@given( | |
first=st.lists(st.just(None) | st.integers()), | |
second=st.lists(st.just(None) | st.integers()), | |
) | |
def test_list_comparison(self, first, second): | |
self.assertNonesCauseTypeError(first, second) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment