1
|
1 |
|
import pytest |
2
|
|
|
|
3
|
1 |
|
from decimaldate import DecimalDate |
4
|
|
|
|
5
|
1 |
|
""" |
6
|
|
|
__eq__ |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
|
10
|
1 |
|
def test_dunder_equality_true( |
11
|
|
|
today_as_decimaldate_int: int, |
12
|
|
|
) -> None: |
13
|
|
|
# GIVEN |
14
|
1 |
|
today_dd: DecimalDate = DecimalDate(today_as_decimaldate_int) |
15
|
|
|
# WHEN |
16
|
1 |
|
sut: DecimalDate = DecimalDate.today() |
17
|
|
|
# THEN |
18
|
1 |
|
assert today_dd == sut |
19
|
|
|
|
20
|
|
|
|
21
|
1 |
|
def test_dunder_equality_false( |
22
|
|
|
today_as_decimaldate_int: int, |
23
|
|
|
future_as_decimaldate_int: int, |
24
|
|
|
) -> None: |
25
|
|
|
# GIVEN |
26
|
1 |
|
today_dd: DecimalDate = DecimalDate(today_as_decimaldate_int) |
27
|
|
|
# WHEN |
28
|
1 |
|
sut: DecimalDate = DecimalDate(future_as_decimaldate_int) |
29
|
|
|
# THEN |
30
|
1 |
|
assert not today_dd == sut # NOSONAR |
31
|
|
|
|
32
|
|
|
|
33
|
1 |
|
def test_equality_ident( |
34
|
|
|
today_as_decimaldate_int: int, |
35
|
|
|
) -> None: |
36
|
|
|
# GIVEN |
37
|
1 |
|
today_dd: DecimalDate = DecimalDate(today_as_decimaldate_int) |
38
|
|
|
# WHEN |
39
|
1 |
|
sut: DecimalDate = today_dd |
40
|
|
|
# THEN |
41
|
1 |
|
assert today_dd == sut |
42
|
|
|
|
43
|
|
|
|
44
|
1 |
|
def test_equality_same_value( |
45
|
|
|
today_as_decimaldate_int: int, |
46
|
|
|
) -> None: |
47
|
|
|
# GIVEN |
48
|
1 |
|
today1_dd: DecimalDate = DecimalDate(today_as_decimaldate_int) |
49
|
1 |
|
today2_dd: DecimalDate = DecimalDate(today_as_decimaldate_int) |
50
|
|
|
# WHEN |
51
|
|
|
# THEN |
52
|
1 |
|
assert today1_dd == today2_dd |
53
|
|
|
|
54
|
|
|
|
55
|
1 |
|
def test_equality_unsupported_type_raises_typeerror( |
56
|
|
|
today_as_decimaldate_int, |
57
|
|
|
) -> None: |
58
|
|
|
# WHEN |
59
|
1 |
|
today = DecimalDate.today() |
60
|
|
|
# THEN |
61
|
1 |
|
assert today.as_int() == today_as_decimaldate_int |
62
|
1 |
|
with pytest.raises( |
63
|
|
|
expected_exception=TypeError, |
64
|
|
|
): |
65
|
1 |
|
today == today_as_decimaldate_int # NOSONAR |
66
|
|
|
|
67
|
|
|
|
68
|
1 |
|
""" |
69
|
|
|
__ne__ |
70
|
|
|
""" |
71
|
|
|
|
72
|
|
|
|
73
|
1 |
|
def test_dunder_non_equality_true( |
74
|
|
|
today_as_decimaldate_int: int, |
75
|
|
|
future_as_decimaldate_int: int, |
76
|
|
|
) -> None: |
77
|
|
|
# GIVEN |
78
|
1 |
|
today_dd: DecimalDate = DecimalDate(today_as_decimaldate_int) |
79
|
|
|
# WHEN |
80
|
1 |
|
sut: DecimalDate = DecimalDate(future_as_decimaldate_int) |
81
|
|
|
# THEN |
82
|
1 |
|
assert today_dd != sut |
83
|
|
|
|
84
|
|
|
|
85
|
1 |
|
def test_dunder_non_equality_false( |
86
|
|
|
today_as_decimaldate_int: int, |
87
|
|
|
) -> None: |
88
|
|
|
# GIVEN |
89
|
1 |
|
today_dd: DecimalDate = DecimalDate(today_as_decimaldate_int) |
90
|
|
|
# WHEN |
91
|
1 |
|
sut: DecimalDate = DecimalDate.today() |
92
|
|
|
# THEN |
93
|
1 |
|
assert not today_dd != sut # NOSONAR |
94
|
|
|
|
95
|
|
|
|
96
|
1 |
|
def test_dunder_non_equality_unsupported_type_raises_typeerror( |
97
|
|
|
today_as_decimaldate_int, |
98
|
|
|
) -> None: |
99
|
|
|
# WHEN |
100
|
1 |
|
today = DecimalDate.today() |
101
|
|
|
# THEN |
102
|
1 |
|
with pytest.raises( |
103
|
|
|
expected_exception=TypeError, |
104
|
|
|
): |
105
|
1 |
|
today != today_as_decimaldate_int # NOSONAR |
106
|
|
|
|
107
|
|
|
|
108
|
1 |
|
""" |
109
|
|
|
__gt__ |
110
|
|
|
""" |
111
|
|
|
|
112
|
|
|
|
113
|
1 |
|
def test_dunder_greater_than( |
114
|
|
|
today_as_decimaldate_int: int, |
115
|
|
|
past_as_decimaldate_int: int, |
116
|
|
|
) -> None: |
117
|
|
|
# GIVEN |
118
|
|
|
# WHEN |
119
|
|
|
# THEN |
120
|
|
|
# fmt: off |
121
|
1 |
|
assert not DecimalDate(today_as_decimaldate_int) == DecimalDate(past_as_decimaldate_int) # NOSONAR |
122
|
1 |
|
assert not DecimalDate(today_as_decimaldate_int) < DecimalDate(past_as_decimaldate_int) # NOSONAR |
123
|
1 |
|
assert DecimalDate(today_as_decimaldate_int) > DecimalDate(past_as_decimaldate_int) # NOSONAR |
124
|
|
|
# fmt: on |
125
|
|
|
|
126
|
|
|
|
127
|
1 |
|
def test_dunder_greater_than_unsupported_type_raises_typeerror( |
128
|
|
|
today_as_decimaldate_int, |
129
|
|
|
) -> None: |
130
|
|
|
# WHEN |
131
|
1 |
|
today = DecimalDate.today() |
132
|
|
|
# THEN |
133
|
1 |
|
with pytest.raises( |
134
|
|
|
expected_exception=TypeError, |
135
|
|
|
): |
136
|
1 |
|
today > today_as_decimaldate_int # NOSONAR |
137
|
|
|
|
138
|
|
|
|
139
|
1 |
|
""" |
140
|
|
|
__ge__ |
141
|
|
|
""" |
142
|
|
|
|
143
|
|
|
|
144
|
1 |
|
def test_dunder_greater_than_or_equal( |
145
|
|
|
today_as_decimaldate_int: int, |
146
|
|
|
past_as_decimaldate_int: int, |
147
|
|
|
) -> None: |
148
|
|
|
# GIVEN |
149
|
|
|
# WHEN |
150
|
|
|
# THEN |
151
|
|
|
# fmt: off |
152
|
1 |
|
assert not DecimalDate(today_as_decimaldate_int) == DecimalDate(past_as_decimaldate_int) # NOSONAR |
153
|
1 |
|
assert not DecimalDate(today_as_decimaldate_int) < DecimalDate(past_as_decimaldate_int) # NOSONAR |
154
|
1 |
|
assert DecimalDate(today_as_decimaldate_int) > DecimalDate(past_as_decimaldate_int) # NOSONAR |
155
|
1 |
|
assert DecimalDate(today_as_decimaldate_int) >= DecimalDate(past_as_decimaldate_int) # NOSONAR |
156
|
|
|
# fmt: on |
157
|
|
|
|
158
|
|
|
|
159
|
1 |
|
def test_dunder_greater_than_or_equal_unsupported_type_raises_typeerror( |
160
|
|
|
today_as_decimaldate_int, |
161
|
|
|
) -> None: |
162
|
|
|
# WHEN |
163
|
1 |
|
today = DecimalDate.today() |
164
|
|
|
# THEN |
165
|
1 |
|
with pytest.raises( |
166
|
|
|
expected_exception=TypeError, |
167
|
|
|
): |
168
|
1 |
|
today >= today_as_decimaldate_int # NOSONAR |
169
|
|
|
|
170
|
|
|
|
171
|
1 |
|
""" |
172
|
|
|
__lt__ |
173
|
|
|
""" |
174
|
|
|
|
175
|
|
|
|
176
|
1 |
|
def test_dunder_less_than( |
177
|
|
|
today_as_decimaldate_int: int, |
178
|
|
|
past_as_decimaldate_int: int, |
179
|
|
|
) -> None: |
180
|
|
|
# GIVEN |
181
|
|
|
# WHEN |
182
|
|
|
# THEN |
183
|
|
|
# fmt: off |
184
|
1 |
|
assert not DecimalDate(past_as_decimaldate_int) == DecimalDate(today_as_decimaldate_int) # NOSONAR |
185
|
1 |
|
assert DecimalDate(past_as_decimaldate_int) < DecimalDate(today_as_decimaldate_int) # NOSONAR |
186
|
1 |
|
assert not DecimalDate(past_as_decimaldate_int) > DecimalDate(today_as_decimaldate_int) # NOSONAR |
187
|
|
|
# fmt: on |
188
|
|
|
|
189
|
|
|
|
190
|
1 |
|
def test_dunder_less_than_unsupported_type_raises_typeerror( |
191
|
|
|
today_as_decimaldate_int, |
192
|
|
|
) -> None: |
193
|
|
|
# WHEN |
194
|
1 |
|
today = DecimalDate.today() |
195
|
|
|
# THEN |
196
|
1 |
|
with pytest.raises( |
197
|
|
|
expected_exception=TypeError, |
198
|
|
|
): |
199
|
1 |
|
today < today_as_decimaldate_int # NOSONAR |
200
|
|
|
|
201
|
|
|
|
202
|
1 |
|
""" |
203
|
|
|
__le__ |
204
|
|
|
""" |
205
|
|
|
|
206
|
|
|
|
207
|
1 |
|
def test_dunder_less_than_or_equal( |
208
|
|
|
today_as_decimaldate_int: int, |
209
|
|
|
past_as_decimaldate_int: int, |
210
|
|
|
) -> None: |
211
|
|
|
# GIVEN |
212
|
|
|
# WHEN |
213
|
|
|
# THEN |
214
|
|
|
# fmt: off |
215
|
1 |
|
assert not DecimalDate(past_as_decimaldate_int) == DecimalDate(today_as_decimaldate_int) # NOSONAR |
216
|
1 |
|
assert DecimalDate(past_as_decimaldate_int) < DecimalDate(today_as_decimaldate_int) # NOSONAR |
217
|
1 |
|
assert DecimalDate(past_as_decimaldate_int) <= DecimalDate(today_as_decimaldate_int) # NOSONAR |
218
|
|
|
# fmt: on |
219
|
|
|
|
220
|
|
|
|
221
|
1 |
|
def test_dunder_less_than_or_equal_unsupported_type_raises_typeerror( |
222
|
|
|
today_as_decimaldate_int, |
223
|
|
|
) -> None: |
224
|
|
|
# WHEN |
225
|
1 |
|
today = DecimalDate.today() |
226
|
|
|
# THEN |
227
|
1 |
|
with pytest.raises( |
228
|
|
|
expected_exception=TypeError, |
229
|
|
|
): |
230
|
|
|
today <= today_as_decimaldate_int # NOSONAR |
231
|
|
|
|