-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrich.py
80 lines (51 loc) · 2 KB
/
rich.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""rich comparison conjectures."""
import abc
import typing
import conjecture.base
CT = typing.TypeVar("CT", bound="Comparable")
class Comparable(typing.Protocol):
"""Rich comparison protocol."""
@abc.abstractmethod
def __lt__(self: CT, other: CT) -> bool:
"""Check less than."""
@abc.abstractmethod
def __gt__(self: CT, other: CT) -> bool:
"""Check greater than."""
@abc.abstractmethod
def __le__(self: CT, other: CT) -> bool:
"""Check less than or equal to."""
@abc.abstractmethod
def __ge__(self: CT, other: CT) -> bool:
"""Check greater than or equal to."""
def greater_than(value: Comparable) -> conjecture.base.Conjecture:
"""
Greater than.
Propose that the value is greater than the provided value
>>> assert value == conjecture.greater_than(5)
:return: a conjecture object
"""
return conjecture.base.Conjecture(lambda x: typing.cast(Comparable, x) > value)
def greater_than_or_equal_to(value: Comparable) -> conjecture.base.Conjecture:
"""
Greater than or equal to.
Propose that the value is greater than or equal to the provided value
>>> assert value == conjecture.greater_than_or_equal(5)
:return: a conjecture object
"""
return conjecture.base.Conjecture(lambda x: typing.cast(Comparable, x) >= value)
def less_than(value: Comparable) -> conjecture.base.Conjecture:
"""
Less than.
Propose that the value is less than the provided value
>>> assert value == conjecture.less_than(5)
:return: a conjecture object
"""
return conjecture.base.Conjecture(lambda x: typing.cast(Comparable, x) < value)
def less_than_or_equal_to(value: Comparable) -> conjecture.base.Conjecture:
"""
Less than or equal to.
Propose that the value is less than or equal to the provided value
>>> assert value == conjecture.less_than_or_equal(5)
:return: a conjecture object
"""
return conjecture.base.Conjecture(lambda x: typing.cast(Comparable, x) <= value)