@@ -49,6 +49,24 @@ def __init__(self, lower: int, upper: int):
49
49
raise ValueError (f"Lower value ({ lower } ) must be less than upper ({ upper } )" )
50
50
super ().__init__ (portion .closed (lower , upper ))
51
51
52
+ def __sub__ (self , other ):
53
+ # portion default subtraction is to remove from the set, but
54
+ # we want to decrease the values
55
+ if isinstance (other , int ):
56
+ return IntegerRange (self .lower - other , self .upper - other )
57
+ elif isinstance (other , IntegerRange ):
58
+ # subtract the range respective endpoints
59
+ return IntegerRange (self .lower - other .lower , self .upper - other .upper )
60
+
61
+ def __add__ (self , other ):
62
+ # portion default subtraction is to remove from the set, but
63
+ # we want to decrease the values
64
+ if isinstance (other , int ):
65
+ return IntegerRange (self .lower + other , self .upper + other )
66
+ elif isinstance (other , IntegerRange ):
67
+ # the new range is the smallest possible value to the highest
68
+ return IntegerRange (self .lower + other .lower , self .upper - other .upper )
69
+
52
70
53
71
@dataclass
54
72
class Udelta :
0 commit comments