Created
August 15, 2020 13:58
-
-
Save lcs-felix/e7f17e3f3a43405c369a1f7288c092b9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# example from: https://hypothesis.readthedocs.io/en/latest/examples.html | |
class Node: | |
def __init__(self, label, value): | |
self.label = label | |
self.value = tuple(value) | |
def __repr__(self): | |
return f"Node({self.label}, {self.value})" | |
def sorts_before(self, other): | |
"""Returns if the node must comes before other, based on the fact that | |
the data of the left is an initial segment of the right. | |
>>> node1 = Node(1, [1, 2]) | |
>>> node2 = Node(2, [1, 2, 3]) | |
>>> node1.sorts_before(node2) | |
True | |
""" | |
if len(self.value) >= len(other.value): | |
return False | |
return other.value[: len(self.value)] == self.value | |
if __name__ == "__main__": | |
import doctest | |
doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment