@@ -181,3 +181,51 @@ def test_intersection(self):
181181 assert before_20th .intersection (after_c11th ) == UndateInterval (
182182 Undate (1001 ), Undate (1901 )
183183 )
184+
185+ def test_contains (self ):
186+ century11th = UndateInterval (Undate (1001 ), Undate (1100 ))
187+ century20th = UndateInterval (Undate (1901 ), Undate (2000 ))
188+ decade1990s = UndateInterval (Undate (1990 ), Undate (1999 ))
189+ # an interval doesn't contain itself
190+ for interval in [century11th , century20th , decade1990s ]:
191+ assert interval not in interval
192+
193+ # checking if an interval is within another interval
194+ assert decade1990s in century20th
195+ assert decade1990s not in century11th
196+ assert century11th not in decade1990s
197+ assert century20th not in decade1990s
198+ # a specific date can be contained by an interval
199+ y2k = Undate (2000 )
200+ assert y2k in century20th
201+ assert y2k not in century11th
202+ # partially known date should work too
203+ april_someyear = Undate ("198X" , 4 )
204+ assert april_someyear in century20th
205+ assert april_someyear not in century11th
206+ # conversion from datetime.date also works
207+ assert datetime .date (1922 , 5 , 1 ) in century20th
208+ # unsupported types result in a type error
209+ with pytest .raises (TypeError ):
210+ "nineteen-eighty-four" in century20th
211+
212+ # contains check with half-open intervals
213+ after_c11th = UndateInterval (Undate (1001 ), None )
214+ before_20th = UndateInterval (None , Undate (1901 ))
215+ # neither of them contains the other
216+ assert after_c11th not in before_20th
217+ assert before_20th not in after_c11th
218+ # nor are they contained by a smaller range
219+ assert after_c11th not in decade1990s
220+ assert before_20th not in decade1990s
221+
222+ # all of our previous test dates are in the 1900s,
223+ # so they are after the 11th century and not before the 20th
224+ for period in [decade1990s , y2k , april_someyear ]:
225+ assert period in after_c11th
226+ assert period not in before_20th
227+
228+ # fully open interval - is this even meaningful?
229+ whenever = UndateInterval (None , None )
230+ assert decade1990s in whenever
231+ assert whenever not in whenever
0 commit comments