def testContainsElement(self): # includes both ends range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertTrue(range.contains(QDate(2010, 3, 1))) self.assertTrue(range.contains(QDate(2010, 5, 2))) self.assertTrue(range.contains(QDate(2010, 6, 2))) self.assertFalse(range.contains(QDate(2009, 6, 2))) self.assertFalse(range.contains(QDate(2017, 6, 2))) self.assertFalse(range.contains(QDate())) # infinite left end range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertTrue(range.contains(QDate(2010, 3, 1))) self.assertTrue(range.contains(QDate(2010, 5, 2))) self.assertTrue(range.contains(QDate(2010, 6, 2))) self.assertTrue(range.contains(QDate(2009, 6, 2))) self.assertFalse(range.contains(QDate(2017, 6, 2))) self.assertFalse(range.contains(QDate())) # infinite right end range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertTrue(range.contains(QDate(2010, 3, 1))) self.assertTrue(range.contains(QDate(2010, 5, 2))) self.assertTrue(range.contains(QDate(2010, 6, 2))) self.assertFalse(range.contains(QDate(2009, 6, 2))) self.assertTrue(range.contains(QDate(2017, 6, 2))) self.assertFalse(range.contains(QDate()))
def testOverlaps(self): # includes both ends range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 6, 2)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2010, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2017, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate()))) self.assertTrue(range.overlaps(QgsDateRange(QDate(), QDate(2010, 4, 1)))) self.assertFalse(range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2009, 8, 5)))) self.assertFalse(range.overlaps(QgsDateRange(QDate(2019, 4, 1), QDate(2019, 8, 5)))) range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 6, 2)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2010, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2017, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate()))) self.assertTrue(range.overlaps(QgsDateRange(QDate(), QDate(2010, 4, 1)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2009, 8, 5)))) self.assertFalse(range.overlaps(QgsDateRange(QDate(2019, 4, 1), QDate(2019, 8, 5)))) range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 6, 2)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2010, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2017, 4, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate()))) self.assertTrue(range.overlaps(QgsDateRange(QDate(), QDate(2010, 4, 1)))) self.assertFalse(range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2009, 8, 5)))) self.assertTrue(range.overlaps(QgsDateRange(QDate(2019, 4, 1), QDate(2019, 8, 5))))
def testGetters(self): range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertEqual(range.begin(), QDate(2010, 3, 1)) self.assertEqual(range.end(), QDate(2010, 6, 2)) self.assertTrue(range.includeBeginning()) self.assertTrue(range.includeEnd()) range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertFalse(range.begin().isValid()) self.assertEqual(range.end(), QDate(2010, 6, 2)) range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertEqual(range.begin(), QDate(2010, 3, 1)) self.assertFalse(range.end().isValid())
def testIsEmpty(self): range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(), QDate()) self.assertTrue(range.isEmpty()) range = QgsDateRange(QDate(2017, 3, 1), QDate(2010, 6, 2)) self.assertTrue(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 3, 1)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 3, 1), False, False) self.assertTrue(range.isEmpty())
def testGetters(self): range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertEqual(range.begin(), QDate(2010, 3, 1)) self.assertEqual(range.end(), QDate(2010, 6, 2)) self.assertTrue(range.includeBeginning()) self.assertTrue(range.includeEnd()) range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertFalse(range.begin().isValid()) self.assertEqual(range.end(), QDate(2010, 6, 2)) range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertEqual(range.begin(), QDate(2010, 3, 1)) self.assertFalse(range.end().isValid())
def testIsEmpty(self): range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertFalse(range.isEmpty()) # check QgsDateRange docs - this is treated as an infinite range, so is NOT empty range = QgsDateRange(QDate(), QDate()) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(2017, 3, 1), QDate(2010, 6, 2)) self.assertTrue(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 3, 1)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 3, 1), False, False) self.assertTrue(range.isEmpty())
def testContainsElement(self): # includes both ends range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertTrue(range.contains(QDate(2010, 3, 1))) self.assertTrue(range.contains(QDate(2010, 5, 2))) self.assertTrue(range.contains(QDate(2010, 6, 2))) self.assertFalse(range.contains(QDate(2009, 6, 2))) self.assertFalse(range.contains(QDate(2017, 6, 2))) self.assertFalse(range.contains(QDate())) # infinite left end range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertTrue(range.contains(QDate(2010, 3, 1))) self.assertTrue(range.contains(QDate(2010, 5, 2))) self.assertTrue(range.contains(QDate(2010, 6, 2))) self.assertTrue(range.contains(QDate(2009, 6, 2))) self.assertFalse(range.contains(QDate(2017, 6, 2))) self.assertFalse(range.contains(QDate())) # infinite right end range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertTrue(range.contains(QDate(2010, 3, 1))) self.assertTrue(range.contains(QDate(2010, 5, 2))) self.assertTrue(range.contains(QDate(2010, 6, 2))) self.assertFalse(range.contains(QDate(2009, 6, 2))) self.assertTrue(range.contains(QDate(2017, 6, 2))) self.assertFalse(range.contains(QDate()))
def testOverlaps(self): # includes both ends range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 6, 2)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2010, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2017, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate()))) self.assertTrue( range.overlaps(QgsDateRange(QDate(), QDate(2010, 4, 1)))) self.assertFalse( range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2009, 8, 5)))) self.assertFalse( range.overlaps(QgsDateRange(QDate(2019, 4, 1), QDate(2019, 8, 5)))) range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 6, 2)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2010, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2017, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate()))) self.assertTrue( range.overlaps(QgsDateRange(QDate(), QDate(2010, 4, 1)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2009, 8, 5)))) self.assertFalse( range.overlaps(QgsDateRange(QDate(2019, 4, 1), QDate(2019, 8, 5)))) range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2010, 6, 2)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2010, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate(2017, 4, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2010, 4, 1), QDate()))) self.assertTrue( range.overlaps(QgsDateRange(QDate(), QDate(2010, 4, 1)))) self.assertFalse( range.overlaps(QgsDateRange(QDate(2009, 4, 1), QDate(2009, 8, 5)))) self.assertTrue( range.overlaps(QgsDateRange(QDate(2019, 4, 1), QDate(2019, 8, 5))))
def testIsEmpty(self): range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(), QDate()) self.assertTrue(range.isEmpty()) range = QgsDateRange(QDate(2017, 3, 1), QDate(2010, 6, 2)) self.assertTrue(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 3, 1)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 3, 1), False, False) self.assertTrue(range.isEmpty())
def testIsEmpty(self): range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertFalse(range.isEmpty()) # check QgsDateRange docs - this is treated as an infinite range, so is NOT empty range = QgsDateRange(QDate(), QDate()) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(2017, 3, 1), QDate(2010, 6, 2)) self.assertTrue(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 3, 1)) self.assertFalse(range.isEmpty()) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 3, 1), False, False) self.assertTrue(range.isEmpty())
def testIsInfinite(self): self.assertFalse(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)).isInfinite()) self.assertFalse(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 3, 1)).isInfinite()) self.assertFalse(QgsDateRange(QDate(2010, 3, 1), QDate(2010, 3, 1), False, False).isInfinite()) self.assertTrue(QgsDateRange(QDate(), QDate()).isInfinite())
def testExtend(self): range_empty = QgsDateRange(QDate(2010, 6, 2), QDate(2010, 3, 1)) # Empty self.assertFalse(range_empty.extend(range_empty)) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, False) self.assertFalse(range.extend(range_empty)) range = QgsDateRange(QDate(2010, 6, 2), QDate(2010, 3, 1)) self.assertTrue( range.extend( QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, False))) self.assertEqual( range, QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, False)) # Extend low range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, False) self.assertTrue( range.extend( QgsDateRange(QDate(2010, 2, 1), QDate(2010, 6, 2), False, False))) self.assertEqual( range, QgsDateRange(QDate(2010, 2, 1), QDate(2010, 6, 2), False, False)) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, False) self.assertTrue( range.extend( QgsDateRange(QDate(2010, 2, 1), QDate(2010, 5, 2), True, False))) self.assertEqual( range, QgsDateRange(QDate(2010, 2, 1), QDate(2010, 6, 2), True, False)) # Extend high range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, False) self.assertTrue( range.extend( QgsDateRange(QDate(2010, 3, 1), QDate(2010, 7, 2), False, False))) self.assertEqual( range, QgsDateRange(QDate(2010, 3, 1), QDate(2010, 7, 2), False, False)) range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, False) self.assertTrue( range.extend( QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, True))) self.assertEqual( range, QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, True)) # Extend both range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, False) self.assertTrue( range.extend( QgsDateRange(QDate(2010, 2, 1), QDate(2010, 7, 2), False, False))) self.assertEqual( range, QgsDateRange(QDate(2010, 2, 1), QDate(2010, 7, 2), False, False)) # Extend none range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2), False, False) self.assertFalse( range.extend( QgsDateRange(QDate(2010, 4, 6), QDate(2010, 5, 2), False, False))) # Test infinity range = QgsDateRange(QDate(), QDate()) self.assertFalse( range.extend( QgsDateRange(QDate(2010, 4, 6), QDate(2010, 5, 2), False, False))) range = QgsDateRange(QDate(), QDate(2010, 5, 2)) self.assertFalse( range.extend( QgsDateRange(QDate(2010, 4, 6), QDate(2010, 5, 2), False, False))) self.assertEqual(range, QgsDateRange(QDate(), QDate(2010, 5, 2), True, True)) range = QgsDateRange(QDate(2010, 4, 6), QDate()) self.assertTrue( range.extend( QgsDateRange(QDate(2010, 3, 6), QDate(2010, 5, 2), False, False))) self.assertEqual(range, QgsDateRange(QDate(2010, 3, 6), QDate(), False, True)) range = QgsDateRange(QDate(), QDate(2010, 5, 2)) self.assertTrue( range.extend( QgsDateRange(QDate(2010, 3, 6), QDate(2010, 6, 2), False, False))) self.assertEqual(range, QgsDateRange(QDate(), QDate(2010, 6, 2), True, False)) range = QgsDateRange(QDate(2010, 4, 6), QDate()) self.assertTrue( range.extend(QgsDateRange(QDate(), QDate(2010, 5, 2), True, False))) self.assertEqual(range, QgsDateRange(QDate(), QDate(), True, True)) range = QgsDateRange(QDate(), QDate(2010, 4, 6)) self.assertTrue( range.extend(QgsDateRange(QDate(), QDate(), True, True))) self.assertEqual(range, QgsDateRange(QDate(), QDate(), True, True))
def testGetters(self): range = QgsDateRange(QDate(2010, 3, 1), QDate(2010, 6, 2)) self.assertEqual(range.lower(), QDate(2010, 3, 1)) self.assertEqual(range.upper(), QDate(2010, 6, 2)) self.assertTrue(range.includeLower()) self.assertTrue(range.includeUpper()) range = QgsDateRange(QDate(), QDate(2010, 6, 2)) self.assertFalse(range.lower().isValid()) self.assertEqual(range.upper(), QDate(2010, 6, 2)) range = QgsDateRange(QDate(2010, 3, 1), QDate()) self.assertEqual(range.lower(), QDate(2010, 3, 1)) self.assertFalse(range.upper().isValid())